Skip to content

Commit

Permalink
Merge pull request #118 from nandub/sendPrivate
Browse files Browse the repository at this point in the history
Add sendPrivate method
  • Loading branch information
jgable committed Apr 7, 2014
2 parents cac3074 + d68c642 commit 2ab07cc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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'

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2ab07cc

Please sign in to comment.