-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonebot.rb
53 lines (46 loc) · 1.94 KB
/
donebot.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
45
46
47
48
49
50
51
52
53
require 'slack-ruby-bot'
COUNTERS = {}
module DoneBot
class App < SlackRubyBot::App
end
class Counter < SlackRubyBot::Commands::Base
match /^Setup a counter for (?<counter_name>\w*)$/ do |client, data, match|
COUNTERS[match[:counter_name]] = 0
send_message client, data.channel, "I setup a new counter for #{match[:counter_name]}."
end
end
class Done < SlackRubyBot::Commands::Base
match /^Done with (?<counter_name>\w*)$/ do |client, data, match|
finished_sayings = ["Great job!", "Nice work.", "Keep at it.", "Do, or do not. There is no try!"]
if COUNTERS[match[:counter_name]]
COUNTERS[match[:counter_name]] += 1
response = finished_sayings[(rand*4).ceil-1]
else
response = "Sorry, there's no counter with that name. If you'd like to set one up, just say, \"Setup a counter for #{match[:counter_name]}\""
end
send_message client, data.channel, response
end
end
class AmountDone < SlackRubyBot::Commands::Base
match /^How many are done with (?<counter_name>\w*)$/ do |client, data, match|
if COUNTERS[match[:counter_name]]
response = "#{COUNTERS[match[:counter_name]]} are done."
else
response = "Sorry, there's no counter with that name. If you'd like to set one up, just say, \"Setup a counter for #{match[:counter_name]}\""
end
send_message client, data.channel, response
end
end
class Reset < SlackRubyBot::Commands::Base
match /^Reset the (?<counter_name>\w*)$/ do |client, data, match|
if COUNTERS[match[:counter_name]]
COUNTERS[match[:counter_name]] = 0
response = "#{COUNTERS[match[:counter_name]]} has been reset to 0."
else
response = "Sorry, there's no counter with that name. If you'd like to set one up, just say, \"Setup a counter for #{match[:counter_name]}\""
end
send_message client, data.channel, response
end
end
end
DoneBot::App.instance.run