Skip to content

Commit dc0b0e6

Browse files
committed
Added support for "Enter Message" support
1 parent 9ac1fd9 commit dc0b0e6

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/irc.coffee

+17-10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ class IrcBot extends Adapter
4747
@bot.part channel, () ->
4848
console.log('left %s', channel)
4949

50+
createUser: (channel, from) ->
51+
user = @userForName from
52+
unless user?
53+
id = (new Date().getTime() / 1000).toString().replace('.','')
54+
user = @userForId id
55+
user.name = from
56+
57+
if channel.match(/^[&#]/)
58+
user.room = channel
59+
else
60+
user.room = null
61+
user
62+
5063
run: ->
5164
self = @
5265

@@ -92,18 +105,11 @@ class IrcBot extends Adapter
92105

93106
bot.addListener 'message', (from, to, message) ->
94107
console.log "From #{from} to #{to}: #{message}"
95-
96-
user = self.userForName from
97-
unless user?
98-
id = (new Date().getTime() / 1000).toString().replace('.','')
99-
user = self.userForId id
100-
user.name = from
101108

102-
if to.match(/^[&#]/)
103-
user.room = to
109+
user = self.createUser to, from
110+
if user.room
104111
console.log "#{to} <#{from}> #{message}"
105112
else
106-
user.room = null
107113
console.log "msg <#{from}> #{message}"
108114

109115
self.receive new Robot.TextMessage(user, message)
@@ -116,6 +122,8 @@ class IrcBot extends Adapter
116122

117123
bot.addListener 'join', (channel, who) ->
118124
console.log('%s has joined %s', who, channel)
125+
user = self.createUser channel, who
126+
self.receive new Robot.EnterMessage(user)
119127

120128
bot.addListener 'part', (channel, who, reason) ->
121129
console.log('%s has left %s: %s', who, channel, reason)
@@ -137,4 +145,3 @@ class IrcResponse extends Robot.Response
137145

138146
exports.use = (robot) ->
139147
new IrcBot robot
140-

0 commit comments

Comments
 (0)