From a75a006d41d8e21dd1c9dd65f6909529a1ebc4f3 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Mon, 7 May 2012 23:05:45 -0500 Subject: [PATCH 1/7] Adding a command listener. --- src/irc.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/irc.coffee b/src/irc.coffee index 939e9fd..ad5757c 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -47,6 +47,10 @@ class IrcBot extends Adapter @bot.part channel, () -> console.log('left %s', channel) + command: (command, strings...) -> + for str in strings + @bot.send command, str + run: -> self = @ From d8ab884fcb6496a07d740f399f220e72eccad3e5 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Tue, 8 May 2012 00:47:45 -0500 Subject: [PATCH 2/7] Pass command arguments all toghether. --- src/irc.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/irc.coffee b/src/irc.coffee index ad5757c..b52b8ce 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -48,8 +48,7 @@ class IrcBot extends Adapter console.log('left %s', channel) command: (command, strings...) -> - for str in strings - @bot.send command, str + @bot.send command, strings... run: -> self = @ From 4b39ced9a94351929ce5663d135a6c51b70585ee Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Tue, 8 May 2012 04:43:45 -0500 Subject: [PATCH 3/7] Emit a joined event. --- src/irc.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/irc.coffee b/src/irc.coffee index b52b8ce..6f58163 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -42,6 +42,7 @@ class IrcBot extends Adapter self = @ @bot.join channel, () -> console.log('joined %s', channel) + self.emit 'joined' part: (channel) -> @bot.part channel, () -> From a54b89d8589be616e8498404713c77549836bc0d Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Mon, 25 Jun 2012 13:48:05 -0500 Subject: [PATCH 4/7] Updating to work with latest hubot. --- src/irc.coffee | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/irc.coffee b/src/irc.coffee index 6f58163..8958e74 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -1,17 +1,10 @@ -Robot = require('hubot').robot() -Adapter = require('hubot').adapter() +Robot = require('hubot').Robot +Adapter = require('hubot').Adapter +TextMessage = require('hubot').TextMessage Irc = require 'irc' class IrcBot extends Adapter - constructor: (@robot) -> - super @robot - - @robot.notice = (user, strings...) -> - @adapter.notice user, strings... - - @robot.Response = IrcResponse - send: (user, strings...) -> for str in strings if not str? @@ -48,6 +41,12 @@ class IrcBot extends Adapter @bot.part channel, () -> console.log('left %s', channel) + kick: (channel, client, message) -> + @bot.emit 'raw', + command: 'KICK' + nick: process.env.HUBOT_IRC_NICK + args: [ channel, client, message ] + command: (command, strings...) -> @bot.send command, strings... @@ -110,7 +109,7 @@ class IrcBot extends Adapter user.room = null console.log "msg <#{from}> #{message}" - self.receive new Robot.TextMessage(user, message) + self.receive new TextMessage(user, message) bot.addListener 'error', (message) -> console.error('ERROR: %s: %s', message.command, message.args.join(' ')) @@ -135,7 +134,7 @@ class IrcBot extends Adapter self.emit "connected" -class IrcResponse extends Robot.Response +class IrcResponse extends Response notice: (strings...) -> @robot.adapter.notice @message.user, strings... From 8d33bdd5722ffb1edb99c865170c2ccda9e9ba92 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Mon, 25 Jun 2012 13:50:19 -0500 Subject: [PATCH 5/7] Missed one. --- src/irc.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/irc.coffee b/src/irc.coffee index 8958e74..5f4d58c 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -1,6 +1,7 @@ Robot = require('hubot').Robot Adapter = require('hubot').Adapter TextMessage = require('hubot').TextMessage +Response = require('hubot').Response Irc = require 'irc' From 9159d2887f00c2d2567f05d92d860ebcc029cc44 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Tue, 26 Jun 2012 08:46:15 -0500 Subject: [PATCH 6/7] Use enter/leave messages on enter/leave events. --- src/irc.coffee | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/irc.coffee b/src/irc.coffee index 5f4d58c..8d9a151 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -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' @@ -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' @@ -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('.','') @@ -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) From 0343013d8600401e20756edfe97700e720399b12 Mon Sep 17 00:00:00 2001 From: Elliott Foster Date: Tue, 26 Jun 2012 09:51:15 -0500 Subject: [PATCH 7/7] More correct implementation for join/leave messages for the bot. --- src/irc.coffee | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/irc.coffee b/src/irc.coffee index 8d9a151..b70fa41 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -39,15 +39,14 @@ class IrcBot extends Adapter @bot.join channel, () -> console.log('joined %s', channel) - user = self.userForName @bot.name - self.receive new EnterMessage(user) + self.receive new EnterMessage(null) part: (channel) -> + self = @ @bot.part channel, () -> console.log('left %s', channel) - user = self.userForName @bot.name - self.receive new LeaveMessage(user) + self.receive new LeaveMessage(null) kick: (channel, client, message) -> @bot.emit 'raw',