-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbot.rb
44 lines (37 loc) · 1.34 KB
/
bot.rb
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
42
43
44
# use karl's chat-adapter library
require 'chat-adapter'
# also use the local HerokuSlackbot class defined in heroku.rb
require './heroku'
# if we're on our local machine, we want to test our bot via shell, but when on
# heroku, deploy the actual slackbot.
#
# Feel free to change the name of the bot here - this controls what name the bot
# uses when responding.
if ARGV.first == 'heroku'
bot = HerokuSlackAdapter.new(nick: 'echobot')
else
bot = ChatAdapter::Shell.new(nick: 'echobot')
end
# Feel free to ignore this - makes logging easier
log = ChatAdapter.log
# Do this thing in this block each time the bot hears a message:
bot.on_message do |message, info|
# ignore all messages not directed to this bot
unless message.start_with? 'echobot: '
next # don't process the next lines in this block
end
# Conditionally send a direct message to the person saying whisper
if message == 'echobot: whisper'
# log some info - useful when something doesn't work as expected
log.debug("Someone whispered! #{info}")
# and send the actual message
bot.direct_message(info[:user], "whisper-whisper")
end
# split the message in 2 to get what was actually said.
botname, command = message.split(': ', 2)
# answer the query!
# this bot simply echoes the message back
"@#{info[:user]}: #{command}"
end
# actually start the bot
bot.start!