Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sendPrivate method #118

Merged
merged 1 commit into from
Apr 7, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/irc.coffee
Original file line number Diff line number Diff line change
@@ -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