Skip to content

Commit

Permalink
Adding changes for entering and leaving room from @pboos
Browse files Browse the repository at this point in the history
  • Loading branch information
jgable committed Jul 18, 2012
1 parent 3a3cf72 commit 5e877a5
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/irc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ class IrcBot extends Adapter

self.receive new LeaveMessage(null)

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

kick: (channel, client, message) ->
@bot.emit 'raw',
command: 'KICK'
Expand Down Expand Up @@ -103,17 +116,10 @@ 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 TextMessage(user, message)
Expand All @@ -127,14 +133,14 @@ class IrcBot extends Adapter
bot.addListener 'join', (channel, who) ->
console.log('%s has joined %s', who, channel)

user = self.userForName who
self.receive new EnterMessage(user)
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)

user = self.userForName who
self.receive new LeaveMessage(user)
user = self.createUser channel, who
self.receive new Robot.LeaveMessage(user)

bot.addListener 'kick', (channel, who, _by, reason) ->
console.log('%s was kicked from %s by %s: %s', who, channel, _by, reason)
Expand All @@ -153,4 +159,3 @@ class IrcResponse extends Response

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

0 comments on commit 5e877a5

Please sign in to comment.