diff --git a/src/irc.coffee b/src/irc.coffee index e683e93..47b94c1 100644 --- a/src/irc.coffee +++ b/src/irc.coffee @@ -1,6 +1,11 @@ # Hubot dependencies {Robot, Adapter, TextMessage, EnterMessage, LeaveMessage, Response} = require 'hubot' +# Custom Response class that adds a sendPrivate method +class IrcResponse extends Response + sendPrivate: (strings...) -> + @robot.adapter.sendPrivate @envelope, strings... + # Irc library Irc = require 'irc' @@ -20,6 +25,17 @@ class IrcBot extends Adapter for str in strings @bot.say target, str + sendPrivate: (envelope, strings...) -> + # Remove the room from the envelope and send as private message to user + + if envelope.room + delete envelope.room + + if envelope.user?.room + delete envelope.user.room + + @send envelope, strings... + topic: (envelope, strings...) -> data = strings.join " / " channel = envelope.room @@ -167,6 +183,9 @@ class IrcBot extends Adapter client_options['channels'] = options.rooms unless options.nickpass + # Override the response to provide a sendPrivate method + @robot.Response = IrcResponse + @robot.name = options.nick bot = new Irc.Client options.server, options.nick, client_options