Skip to content

Commit

Permalink
Use enter/leave messages on enter/leave events.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotttf committed Jun 26, 2012
1 parent 8d33bdd commit 9159d28
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/irc.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Robot = require('hubot').Robot
Adapter = require('hubot').Adapter
TextMessage = require('hubot').TextMessage
EnterMessage = require('hubot').EnterMessage
LeaveMessage = require('hubot').LeaveMessage
Response = require('hubot').Response

Irc = require 'irc'
Expand Down Expand Up @@ -36,12 +38,17 @@ class IrcBot extends Adapter
self = @
@bot.join channel, () ->
console.log('joined %s', channel)
self.emit 'joined'

user = self.userForName @bot.name
self.receive new EnterMessage(user)

part: (channel) ->
@bot.part channel, () ->
console.log('left %s', channel)

user = self.userForName @bot.name
self.receive new LeaveMessage(user)

kick: (channel, client, message) ->
@bot.emit 'raw',
command: 'KICK'
Expand Down Expand Up @@ -96,7 +103,7 @@ 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('.','')
Expand All @@ -121,9 +128,15 @@ 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)

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)

bot.addListener 'kick', (channel, who, _by, reason) ->
console.log('%s was kicked from %s by %s: %s', who, channel, _by, reason)

Expand Down

0 comments on commit 9159d28

Please sign in to comment.