Skip to content

Commit

Permalink
Added support for "Enter Message" support
Browse files Browse the repository at this point in the history
  • Loading branch information
pboos committed Jun 8, 2012
1 parent 9ac1fd9 commit dc0b0e6
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/irc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ class IrcBot extends Adapter
@bot.part channel, () ->
console.log('left %s', channel)

createUser: (channel, from) ->
user = @userForName from
unless user?
id = (new Date().getTime() / 1000).toString().replace('.','')
user = @userForId id
user.name = from

if channel.match(/^[&#]/)
user.room = channel
else
user.room = null
user

run: ->
self = @

Expand Down Expand Up @@ -92,18 +105,11 @@ class IrcBot extends Adapter

bot.addListener 'message', (from, to, message) ->
console.log "From #{from} to #{to}: #{message}"

user = self.userForName from
unless user?
id = (new Date().getTime() / 1000).toString().replace('.','')
user = self.userForId id
user.name = from

if to.match(/^[&#]/)
user.room = to
user = self.createUser to, from
if user.room
console.log "#{to} <#{from}> #{message}"
else
user.room = null
console.log "msg <#{from}> #{message}"

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

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

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

exports.use = (robot) ->
new IrcBot robot

0 comments on commit dc0b0e6

Please sign in to comment.