Skip to content

Commit 2ab07cc

Browse files
committed
Merge pull request nandub#118 from nandub/sendPrivate
Add sendPrivate method
2 parents cac3074 + d68c642 commit 2ab07cc

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/irc.coffee

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Hubot dependencies
22
{Robot, Adapter, TextMessage, EnterMessage, LeaveMessage, Response} = require 'hubot'
33

4+
# Custom Response class that adds a sendPrivate method
5+
class IrcResponse extends Response
6+
sendPrivate: (strings...) ->
7+
@robot.adapter.sendPrivate @envelope, strings...
8+
49
# Irc library
510
Irc = require 'irc'
611

@@ -20,6 +25,17 @@ class IrcBot extends Adapter
2025
for str in strings
2126
@bot.say target, str
2227

28+
sendPrivate: (envelope, strings...) ->
29+
# Remove the room from the envelope and send as private message to user
30+
31+
if envelope.room
32+
delete envelope.room
33+
34+
if envelope.user?.room
35+
delete envelope.user.room
36+
37+
@send envelope, strings...
38+
2339
topic: (envelope, strings...) ->
2440
data = strings.join " / "
2541
channel = envelope.room
@@ -167,6 +183,9 @@ class IrcBot extends Adapter
167183

168184
client_options['channels'] = options.rooms unless options.nickpass
169185

186+
# Override the response to provide a sendPrivate method
187+
@robot.Response = IrcResponse
188+
170189
@robot.name = options.nick
171190
bot = new Irc.Client options.server, options.nick, client_options
172191

0 commit comments

Comments
 (0)