Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
45 lines (37 sloc) 1.337 kB
# Description:
# Send messages to users the next time they speak
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
# hubot ambush <user name>: <message>
#
# Author:
# jmoses
appendAmbush = (data, toUser, fromUser, message) ->
data[toUser.name] or= []
data[toUser.name].push [fromUser.name, message]
module.exports = (robot) ->
robot.logger.warning "ambush.coffee has moved from hubot-scripts to its own package. See https://github.com/hubot-scripts/hubot-ambush installation instructions"
robot.brain.on 'loaded', =>
robot.brain.data.ambushes ||= {}
robot.respond /ambush (.*?): (.*)/i, (msg) ->
users = robot.brain.usersForFuzzyName(msg.match[1].trim())
if users.length is 1
user = users[0]
appendAmbush(robot.brain.data.ambushes, user, msg.message.user, msg.match[2])
msg.send "Ambush prepared"
else if users.length > 1
msg.send "Too many users like that"
else
msg.send "#{msg.match[1]}? Never heard of 'em"
robot.hear /./i, (msg) ->
return unless robot.brain.data.ambushes?
if (ambushes = robot.brain.data.ambushes[msg.message.user.name])
for ambush in ambushes
msg.send msg.message.user.name + ": while you were out, " + ambush[0] + " said: " + ambush[1]
delete robot.brain.data.ambushes[msg.message.user.name]
Jump to Line
Something went wrong with that request. Please try again.