-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathambush.coffee
41 lines (36 loc) · 1.17 KB
/
ambush.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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.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]} sent at #{new Date()}")
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]