slack-smart-bot 1.9.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +109 -11
- data/lib/slack/smart-bot/comm/ask.rb +55 -49
- data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
- data/lib/slack/smart-bot/comm/event_hello.rb +7 -3
- data/lib/slack/smart-bot/comm/get_channel_members.rb +9 -4
- data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
- data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +19 -2
- data/lib/slack/smart-bot/comm/respond.rb +217 -72
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +22 -18
- data/lib/slack/smart-bot/comm.rb +2 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +59 -32
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +10 -9
- data/lib/slack/smart-bot/commands/general/bot_status.rb +2 -4
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +7 -7
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -5
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +32 -11
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +2 -4
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +4 -5
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +2 -4
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +2 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +8 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +27 -14
- data/lib/slack/smart-bot/commands.rb +16 -0
- data/lib/slack/smart-bot/listen.rb +1 -3
- data/lib/slack/smart-bot/process.rb +212 -74
- data/lib/slack/smart-bot/process_first.rb +118 -37
- data/lib/slack/smart-bot/treat_message.rb +313 -248
- data/lib/slack/smart-bot/utils/build_help.rb +3 -3
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_help.rb +58 -68
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +2 -0
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils.rb +3 -0
- data/lib/slack-smart-bot.rb +45 -4
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +43 -17
- data/whats_new.txt +32 -20
- metadata +24 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
def listen_simulate
|
3
|
-
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
|
3
|
+
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
|
4
4
|
@pings = []
|
5
5
|
@last_activity_check = Time.now
|
6
6
|
get_bots_created()
|
@@ -18,8 +18,6 @@ class SlackSmartBot
|
|
18
18
|
command = message[3].to_s.strip
|
19
19
|
# take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
|
20
20
|
@logger.info "treat message: #{message}" if config.testing
|
21
|
-
|
22
|
-
|
23
21
|
if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
|
24
22
|
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
25
23
|
if cmd.to_s!=''
|
@@ -13,11 +13,11 @@ class SlackSmartBot
|
|
13
13
|
processed = true
|
14
14
|
|
15
15
|
on_demand = false
|
16
|
-
if command.match(
|
17
|
-
command.match(
|
18
|
-
command.match(
|
19
|
-
command.match(
|
20
|
-
command.match(
|
16
|
+
if command.match(/\A@?(#{config[:nick]}):*\s+(.+)/im) or
|
17
|
+
command.match(/\A()!!(.+)/im) or
|
18
|
+
command.match(/\A()\^(.+)/im) or
|
19
|
+
command.match(/\A()!(.+)/im) or
|
20
|
+
command.match(/\A()<@#{config[:nick_id]}>\s+(.+)/im)
|
21
21
|
command2 = $2
|
22
22
|
Thread.current[:command] = command2
|
23
23
|
if command2.match?(/^()!!(.+)/im) or
|
@@ -30,95 +30,230 @@ class SlackSmartBot
|
|
30
30
|
if (on_demand or typem == :on_dm or
|
31
31
|
(@listening.key?(from) and (@listening[from].key?(dest) or @listening[from].key?(Thread.current[:thread_ts])) )) and
|
32
32
|
config.on_maintenance and !command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/)
|
33
|
-
|
33
|
+
unless Thread.current.key?(:routine) and Thread.current[:routine]
|
34
|
+
respond eval("\"" + config.on_maintenance_message + "\"")
|
35
|
+
end
|
34
36
|
processed = true
|
35
37
|
end
|
36
|
-
|
37
38
|
if !config.on_maintenance or (config.on_maintenance and command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/))
|
38
39
|
#todo: check :on_pg in this case
|
39
40
|
if typem == :on_master or typem == :on_bot or typem == :on_pg or typem == :on_dm
|
40
41
|
|
41
42
|
case command
|
42
43
|
|
43
|
-
when
|
44
|
-
hi_bot(user, dest, dchannel, from, display_name)
|
45
|
-
when /^\s*what's\s+new\s*$/i
|
44
|
+
when /\A\s*what's\s+new\s*$/i
|
46
45
|
whats_new(user, dest, dchannel, from, display_name)
|
47
|
-
when
|
48
|
-
|
49
|
-
|
50
|
-
$1.to_s.match?(/rules/i) ? specific = true : specific = false
|
51
|
-
help_command = $2
|
52
|
-
|
46
|
+
when /\A\s*(#{@salutations.join("|")})\s+(rules|help)\s*(.+)?$/i, /\A(#{@salutations.join("|")}),? what can I do/i
|
47
|
+
$2.to_s.match?(/rules/i) ? specific = true : specific = false
|
48
|
+
help_command = $3
|
53
49
|
bot_help(user, from, dest, dchannel, specific, help_command, rules_file)
|
54
|
-
when
|
50
|
+
when /\A\s*(suggest|random)\s+(command|rule)\s*\z/i, /\A\s*(command|rule)\s+suggestion\s*\z/i
|
51
|
+
$2.to_s.match?(/rule/i) || $1.to_s.match?(/rule/i) ? specific = true : specific = false
|
52
|
+
suggest_command(from, dest, dchannel, specific, rules_file)
|
53
|
+
when /\A\s*use\s+(rules\s+)?(from\s+)?<#C\w+\|(.+)>\s*$/i,
|
54
|
+
/\A\s*use\s+(rules\s+)?(from\s+)?<#(\w+)\|>\s*$/i,
|
55
|
+
/\Ause\s+(rules\s+)?(from\s+)?([^\s]+\s*$)/i
|
55
56
|
channel = $3
|
56
57
|
use_rules(dest, channel, user, dchannel)
|
57
|
-
when
|
58
|
+
when /\A\s*stop\s+using\s+rules\s+(on\s+)<#\w+\|(.+)>/i,
|
59
|
+
/\A\s*stop\s+using\s+rules\s+(on\s+)<#(\w+)\|>/i,
|
60
|
+
/\A\s*stop\s+using\s+rules\s+(on\s+)(.+)\s*$/i
|
61
|
+
channel = $2
|
62
|
+
stop_using_rules_on(dest, user, from, channel, typem)
|
63
|
+
when /\A\s*stop\s+using\s+(rules\s+from\s+)?<#\w+\|(.+)>/i,
|
64
|
+
/\A\s*stop\s+using\s+(rules\s+from\s+)?<#(\w+)\|>/i,
|
65
|
+
/\A\s*stop\s+using\s+(rules\s+from\s+)?(.+)\s*$/i
|
58
66
|
channel = $2
|
59
67
|
stop_using_rules(dest, channel, user, dchannel)
|
60
|
-
when
|
61
|
-
|
68
|
+
when /\A\s*extend\s+rules\s+(to\s+)<#C\w+\|(.+)>/i, /\A\s*extend\s+rules\s+(to\s+)<#(\w+)\|>/i,
|
69
|
+
/\A\s*extend\s+rules\s+(to\s+)(.+)/i,
|
70
|
+
/\A\s*use\s+rules\s+(on\s+)<#C\w+\|(.+)>/i, /\A\s*use\s+rules\s+(on\s+)<#(\w+)\|>/i,
|
71
|
+
/\A\s*use\s+rules\s+(on\s+)(.+)/i
|
62
72
|
channel = $2
|
63
73
|
extend_rules(dest, user, from, channel, typem)
|
64
|
-
when
|
65
|
-
channel = $2
|
66
|
-
stop_using_rules_on(dest, user, from, channel, typem)
|
67
|
-
when /^\s*exit\s+bot\s*$/i, /^quit\s+bot\s*$/i, /^close\s+bot\s*$/i
|
74
|
+
when /\A\s*exit\s+bot\s*$/i, /\A\s*quit\s+bot\s*$/i, /\A\s*close\s+bot\s*$/i
|
68
75
|
exit_bot(command, from, dest, display_name)
|
69
|
-
when
|
76
|
+
when /\A\s*start\s+(this\s+)?bot$/i
|
70
77
|
start_bot(dest, from)
|
71
|
-
when
|
78
|
+
when /\A\s*pause\s+(this\s+)?bot$/i
|
72
79
|
pause_bot(dest, from)
|
73
|
-
when
|
80
|
+
when /\A\s*bot\s+status/i
|
74
81
|
bot_status(dest, user)
|
75
|
-
when /\Anotify\s+<#(C\w+)\|.+>\s+(.+)\s*\z/im,
|
82
|
+
when /\Anotify\s+<#(C\w+)\|.+>\s+(.+)\s*\z/im,
|
83
|
+
/\Anotify\s+<#(\w+)\|>\s+(.+)\s*\z/im,
|
84
|
+
/\Anotify\s+(all)?\s*(.+)\s*\z/im
|
76
85
|
where = $1
|
77
86
|
message = $2
|
78
87
|
notify_message(dest, from, where, message)
|
79
|
-
when
|
80
|
-
|
88
|
+
when /\Apublish\s+announcements\s*\z/i
|
89
|
+
publish_announcements(user)
|
90
|
+
when /\A\s*create\s+(cloud\s+|silent\s+)?bot\s+on\s+<#C\w+\|(.+)>\s*/i,
|
91
|
+
/\A\s*create\s+(cloud\s+|silent\s+)?bot\s+on\s+<#(\w+)\|>\s*/i,
|
92
|
+
/\Acreate\s+(cloud\s+|silent\s+)?bot\s+on\s+#(.+)\s*/i,
|
93
|
+
/\Acreate\s+(cloud\s+|silent\s+)?bot\s+on\s+(.+)\s*/i
|
94
|
+
type = $1.to_s.downcase
|
81
95
|
channel = $2
|
82
|
-
create_bot(dest, user,
|
83
|
-
when
|
96
|
+
create_bot(dest, user, type, channel)
|
97
|
+
when /\A\s*kill\s+bot\s+on\s+<#C\w+\|(.+)>\s*$/i,
|
98
|
+
/\A\s*kill\s+bot\s+on\s+<#(\w+)\|>\s*$/i,
|
99
|
+
/\Akill\s+bot\s+on\s+#(.+)\s*$/i, /\Akill\s+bot\s+on\s+(.+)\s*$/i
|
84
100
|
channel = $1
|
85
101
|
kill_bot_on_channel(dest, from, channel)
|
86
|
-
when
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
102
|
+
when /\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s#(\w+)\s*)(\s.+)?\s*\z/im,
|
103
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*\z/im,
|
104
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s<#(\w+)\|>\s*)?(\s.+)?\s*\z/im,
|
105
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekend|weekday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*\z/im,
|
106
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekend|weekday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*\z/im,
|
107
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekend|weekday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s<#(\w+)\|>\s*)?(\s.+)?\s*\z/im,
|
108
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*\z/im,
|
109
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*\z/im,
|
110
|
+
/\A\s*(add|create)\s+(silent\s+)?(bgroutine|routine)\s+([\w\.]+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(\w+)\|>\s*)?(\s.+)?\s*\z/im
|
92
111
|
silent = $2.to_s!=''
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
112
|
+
routine_type = $3.downcase
|
113
|
+
name = $4.downcase
|
114
|
+
type = $5.to_s.downcase
|
115
|
+
number_time = $6
|
116
|
+
period = $7
|
117
|
+
channel = $9
|
118
|
+
command_to_run = $10
|
119
|
+
content = command_to_run.to_s.scan(/\A\s*```(.+)```\s*\z/im).join
|
120
|
+
unless content == ''
|
121
|
+
files = [
|
122
|
+
{
|
123
|
+
name: name,
|
124
|
+
filetype: '',
|
125
|
+
content: content
|
126
|
+
}
|
127
|
+
]
|
128
|
+
command_to_run = ''
|
129
|
+
end
|
130
|
+
add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel, routine_type)
|
131
|
+
when /\A\s*(kill|delete|remove)\s+routine\s+([\w\.]+)\s*$/i
|
101
132
|
name = $2.downcase
|
102
133
|
remove_routine(dest, from, name)
|
103
|
-
when
|
134
|
+
when /\A\s*see\s+routines?\s+results?\s+([\w\.]+)\s*$/i,
|
135
|
+
/\A\s*see\s+results?\s+routines?\s+([\w\.]+)\s*$/i,
|
136
|
+
/\A\s*results?\s+routines?\s+([\w\.]+)\s*$/i
|
137
|
+
name = $1.downcase
|
138
|
+
see_result_routine(dest, from, name)
|
139
|
+
when /\A\s*(run|execute)\s+routine\s+([\w\.]+)\s*$/i
|
104
140
|
name = $2.downcase
|
105
141
|
run_routine(dest, from, name)
|
106
|
-
when
|
142
|
+
when /\A\s*pause\s+routine\s+([\w\.]+)\s*$/i
|
107
143
|
name = $1.downcase
|
108
144
|
pause_routine(dest, from, name)
|
109
|
-
when
|
145
|
+
when /\A\s*start\s+routine\s+([\w\.]+)\s*$/i
|
110
146
|
name = $1.downcase
|
111
147
|
start_routine(dest, from, name)
|
112
|
-
when
|
148
|
+
when /\A\s*see\s+(all\s+)?routines\s*$/i
|
113
149
|
all = $1.to_s != ""
|
114
150
|
see_routines(dest, from, user, all)
|
115
|
-
when
|
151
|
+
when /\A\s*get\s+bot\s+logs?\s*$/i
|
116
152
|
get_bot_logs(dest, from, typem)
|
117
|
-
when
|
153
|
+
when /\A\s*send\s+message\s+(on|to|in)\s*([^\s]+)\s+([^\s]+)\s*:\s*(.+)\s*$/i,
|
154
|
+
/\A\s*send\s+message\s+(on|to|in)\s*([^\s]+)\s*():\s*(.+)\s*$/i
|
155
|
+
to = $2
|
156
|
+
thread_ts = $3.to_s
|
157
|
+
message = $4
|
158
|
+
to_channel = to.scan(/<#([^>]+)\|.*>/).join
|
159
|
+
to_channel = to.scan(/#([^\s]+)/).join if to_channel == ''
|
160
|
+
if to_channel == ''
|
161
|
+
to_user = to.scan(/<@(\w+)>/).join
|
162
|
+
if to_user == ''
|
163
|
+
# message_id
|
164
|
+
else
|
165
|
+
to = to_user
|
166
|
+
end
|
167
|
+
else
|
168
|
+
to = to_channel
|
169
|
+
end
|
170
|
+
send_message(dest, from, typem, to, thread_ts, message)
|
171
|
+
when /\A\s*react\s+(on|to|in)\s*([^\s]+)\s+([^\s]+)\s+(.+)\s*$/i
|
172
|
+
to = $2
|
173
|
+
thread_ts = $3.to_s
|
174
|
+
emojis = $4
|
175
|
+
to_channel = to.scan(/<#([^>]+)\|.*>/).join
|
176
|
+
if to_channel == ''
|
177
|
+
to_channel = to.scan(/#([^\s]+)/).join
|
178
|
+
to_channel = @channels_id[to_channel].to_s
|
179
|
+
end
|
180
|
+
if to_channel == ''
|
181
|
+
respond "The channel specified doesn't exist or is in a incorrect format"
|
182
|
+
else
|
183
|
+
to = to_channel
|
184
|
+
react_to(dest, from, typem, to, thread_ts, emojis)
|
185
|
+
end
|
186
|
+
|
187
|
+
when /\A\s*(leader\s+board|leaderboard|ranking|podium)()()\s*$/i,
|
188
|
+
/\A\s*(leader\s+board|leaderboard|ranking|podium)\s+from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)\s+to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)\s*$/i,
|
189
|
+
/\A\s*(leader\s+board|leaderboard|ranking|podium)\s+from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)()\s*$/i,
|
190
|
+
/\A\s*(leader\s+board|leaderboard|ranking|podium)\s+(today|yesterday|last\s+week|this\s+week|last\s+month|this\s+month|last\s+year|this year)()\s*$/i
|
191
|
+
require 'date'
|
192
|
+
opt1 = $2.to_s
|
193
|
+
to = $3.to_s
|
194
|
+
if opt1.match?(/\d/)
|
195
|
+
from = opt1
|
196
|
+
period = ''
|
197
|
+
from = from.gsub('.','-').gsub('/','-')
|
198
|
+
if to.empty?
|
199
|
+
to = Date.today.strftime("%Y-%m-%d")
|
200
|
+
else
|
201
|
+
to = to.gsub('.','-').gsub('/','-')
|
202
|
+
end
|
203
|
+
elsif opt1.to_s==''
|
204
|
+
period = 'last week'
|
205
|
+
date = Date.today
|
206
|
+
wday = date.wday
|
207
|
+
wday = 7 if wday==0
|
208
|
+
wday-=1
|
209
|
+
from = "#{(date-wday-7).strftime("%Y-%m-%d")}"
|
210
|
+
to = "#{(date-wday-1).strftime("%Y-%m-%d")}"
|
211
|
+
else
|
212
|
+
from = ''
|
213
|
+
period = opt1.downcase
|
214
|
+
case period
|
215
|
+
when 'today'
|
216
|
+
from = to = "#{Date.today.strftime("%Y-%m-%d")}"
|
217
|
+
when 'yesterday'
|
218
|
+
from = to ="#{(Date.today-1).strftime("%Y-%m-%d")}"
|
219
|
+
when /this\s+month/
|
220
|
+
from = "#{Date.today.strftime("%Y-%m-01")}"
|
221
|
+
to = "#{Date.today.strftime("%Y-%m-%d")}"
|
222
|
+
when /last\s+month/
|
223
|
+
date = Date.today<<1
|
224
|
+
from = "#{date.strftime("%Y-%m-01")}"
|
225
|
+
to = "#{(Date.new(date.year, date.month, -1)).strftime("%Y-%m-%d")}"
|
226
|
+
when /this\s+year/
|
227
|
+
from = "#{Date.today.strftime("%Y-01-01")}"
|
228
|
+
to = "#{Date.today.strftime("%Y-%m-%d")}"
|
229
|
+
when /last\s+year/
|
230
|
+
date = Date.today.prev_year
|
231
|
+
from = "#{date.strftime("%Y-01-01")}"
|
232
|
+
to = "#{(Date.new(date.year, 12, 31)).strftime("%Y-%m-%d")}"
|
233
|
+
when /this\s+week/
|
234
|
+
date = Date.today
|
235
|
+
wday = date.wday
|
236
|
+
wday = 7 if wday==0
|
237
|
+
wday-=1
|
238
|
+
from = "#{(date-wday).strftime("%Y-%m-%d")}"
|
239
|
+
to = "#{date.strftime("%Y-%m-%d")}"
|
240
|
+
when /last\s+week/
|
241
|
+
date = Date.today
|
242
|
+
wday = date.wday
|
243
|
+
wday = 7 if wday==0
|
244
|
+
wday-=1
|
245
|
+
from = "#{(date-wday-7).strftime("%Y-%m-%d")}"
|
246
|
+
to = "#{(date-wday-1).strftime("%Y-%m-%d")}"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
leaderboard(from, to, period)
|
251
|
+
|
252
|
+
when /\A\s*bot\s+stats\s*(.*)\s*$/i
|
118
253
|
opts = $1.to_s
|
119
254
|
all_opts = opts.downcase.split(' ')
|
120
255
|
all_data = all_opts.include?('alldata')
|
121
|
-
st_channel = opts.scan(/<#(\w+)
|
256
|
+
st_channel = opts.scan(/<#(\w+)\|.*>/).join
|
122
257
|
st_from = opts.scan(/from\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
123
258
|
st_from = st_from.gsub('.','-').gsub('/','-')
|
124
259
|
st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
@@ -154,6 +289,11 @@ class SlackSmartBot
|
|
154
289
|
status = $2.downcase
|
155
290
|
message = $3.to_s
|
156
291
|
set_maintenance(from, status, message)
|
292
|
+
when /\A(set|turn)\s+(general|generic)\s+message\s+(off)\s*()\z/im, /\A(set|turn)\s+(general|generic)\s+message\s+(on\s+)?\s*(.+)\s*\z/im
|
293
|
+
status = $3.to_s.downcase
|
294
|
+
status = 'on' if status == ''
|
295
|
+
message = $4.to_s
|
296
|
+
set_general_message(from, status, message)
|
157
297
|
else
|
158
298
|
processed = false
|
159
299
|
end
|
@@ -175,28 +315,24 @@ class SlackSmartBot
|
|
175
315
|
|
176
316
|
case command
|
177
317
|
|
178
|
-
|
179
|
-
|
180
|
-
help_command = $1
|
181
|
-
bot_rules(dest, help_command, typem, rules_file, user)
|
182
|
-
when /^\s*(add\s+)?(global\s+|generic\s+)?shortcut\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i,
|
183
|
-
/^(add\s+)(global\s+|generic\s+)?sc\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
|
318
|
+
when /\A\s*(add\s+)?(global\s+|generic\s+)?shortcut\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i,
|
319
|
+
/\A(add\s+)(global\s+|generic\s+)?sc\s+(for\sall)?\s*([^:]+)\s*:\s*(.+)/i
|
184
320
|
for_all = $3
|
185
321
|
shortcut_name = $4.to_s.downcase
|
186
322
|
command_to_run = $5
|
187
323
|
global = $2.to_s != ''
|
188
324
|
add_shortcut(dest, user, typem, for_all, shortcut_name, command, command_to_run, global)
|
189
|
-
when
|
190
|
-
|
325
|
+
when /\A\s*(delete|remove)\s+(global\s+|generic\s+)?shortcut\s+(.+)/i,
|
326
|
+
/\A(delete|remove)\s+(global\s+|generic\s+)?sc\s+(.+)/i
|
191
327
|
shortcut = $3.to_s.downcase
|
192
328
|
global = $2.to_s != ''
|
193
329
|
|
194
330
|
delete_shortcut(dest, user, shortcut, typem, command, global)
|
195
|
-
when
|
331
|
+
when /\A\s*see\s+shortcuts/i, /^see\s+sc/i
|
196
332
|
see_shortcuts(dest, user, typem)
|
197
333
|
|
198
334
|
#kept to be backwards compatible
|
199
|
-
when
|
335
|
+
when /\A\s*id\schannel\s<#C\w+\|(.+)>\s*/i, /^id channel (.+)/
|
200
336
|
unless typem == :on_extended
|
201
337
|
channel_name = $1
|
202
338
|
get_channels_name_and_id()
|
@@ -206,18 +342,20 @@ class SlackSmartBot
|
|
206
342
|
respond "channel: #{channel_name} not found", dest
|
207
343
|
end
|
208
344
|
end
|
209
|
-
when
|
345
|
+
when /\A\s*ruby\s+(.+)/im, /\A\s*code\s+(.+)/im
|
210
346
|
code = $1
|
211
347
|
code.gsub!("\\n", "\n")
|
212
348
|
code.gsub!("\\r", "\r")
|
349
|
+
code.gsub!(/^\s*```/,'')
|
350
|
+
code.gsub!(/```\s*$/,'')
|
213
351
|
@logger.info code
|
214
352
|
ruby_code(dest, user, code, rules_file)
|
215
|
-
when
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
353
|
+
when /\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s*()()()\z/i,
|
354
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()()\s*\z/i,
|
355
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"()\s*\z/i,
|
356
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)\s*:\s+"([^"]+)"\s+(.+)\s*\z/i,
|
357
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)\s+([\w\-]+)()\s+(.+)\s*\z/i,
|
358
|
+
/\A\s*(private\s+|clean\s+|clean\s+private\s+|private\s+clean\s+)?(repl|irb|live)()\s+()(.+)\s*\z/i
|
221
359
|
opts_type = $1.to_s.downcase.split(' ')
|
222
360
|
opts_type.include?('private') ? type = :private : type = :public
|
223
361
|
type = "#{type}_clean".to_sym if opts_type.include?('clean')
|
@@ -235,10 +373,10 @@ class SlackSmartBot
|
|
235
373
|
env_vars[idx] = "ENV['#{ev}"
|
236
374
|
end
|
237
375
|
repl(dest, user, session_name, env_vars.flatten, rules_file, command, description, type)
|
238
|
-
when
|
376
|
+
when /\A\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
|
239
377
|
session_name = $2
|
240
378
|
get_repl(dest, user, session_name)
|
241
|
-
when
|
379
|
+
when /\A\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*$/i,
|
242
380
|
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/i
|
243
381
|
session_name = $2
|
244
382
|
opts = " #{$3}"
|
@@ -252,10 +390,10 @@ class SlackSmartBot
|
|
252
390
|
env_vars[idx] = "ENV['#{ev}"
|
253
391
|
end
|
254
392
|
run_repl(dest, user, session_name, env_vars.flatten, rules_file)
|
255
|
-
when
|
393
|
+
when /\A\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
|
256
394
|
repl_name = $3
|
257
395
|
delete_repl(dest, user, repl_name)
|
258
|
-
when
|
396
|
+
when /\A\s*see\s+(repls|repl|irb|irbs)\s*$/i
|
259
397
|
see_repls(dest, user, typem)
|
260
398
|
else
|
261
399
|
processed2 = false
|
@@ -1,27 +1,49 @@
|
|
1
1
|
class SlackSmartBot
|
2
|
-
def process_first(user, text, dest, dchannel, typem, files, ts, thread_ts, routine)
|
2
|
+
def process_first(user, text, dest, dchannel, typem, files, ts, thread_ts, routine, routine_name, routine_type)
|
3
3
|
nick = user.name
|
4
4
|
rules_file = ""
|
5
5
|
text.gsub!(/^!!/,'^') # to treat it just as ^
|
6
|
+
shared = []
|
7
|
+
if @shares.key?(@channels_name[dest]) and (ts.to_s!='' or config.simulate) and (user.id!=config.nick_id or (user.id == config.nick_id and !text.match?(/\A\*?Shares from channel/)))
|
8
|
+
@shares[@channels_name[dest]].each do |row|
|
9
|
+
if row[:user_deleted]==''
|
10
|
+
if ((row[:type] == 'text' and text.include?(row[:condition][1..-2])) or (row[:type]=='regexp' and text.match?(/#{row[:condition][1..-2]}/im))) and !shared.include?(row[:to_channel])
|
11
|
+
if config.simulate
|
12
|
+
link = text
|
13
|
+
else
|
14
|
+
link = client.web_client.chat_getPermalink(channel: dest, message_ts: ts).permalink
|
15
|
+
end
|
16
|
+
respond "*<#{link}|Shared> by <@#{row[:user_created]}> from <##{dest}>* using share id #{row[:share_id]}", row[:to_channel]
|
17
|
+
shared << row[:to_channel]
|
18
|
+
sleep 0.2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
6
24
|
if typem == :on_call
|
7
25
|
rules_file = config.rules_file
|
8
26
|
elsif dest[0] == "C" or dest[0] == "G" # on a channel or private channel
|
9
27
|
rules_file = config.rules_file
|
10
28
|
|
11
|
-
if @rules_imported.key?(user.
|
12
|
-
unless @bots_created.key?(@rules_imported[user.
|
29
|
+
if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(dchannel)
|
30
|
+
unless @bots_created.key?(@rules_imported[user.name][dchannel])
|
13
31
|
get_bots_created()
|
14
32
|
end
|
15
|
-
if @bots_created.key?(@rules_imported[user.
|
16
|
-
rules_file = @bots_created[@rules_imported[user.
|
33
|
+
if @bots_created.key?(@rules_imported[user.name][dchannel])
|
34
|
+
rules_file = @bots_created[@rules_imported[user.name][dchannel]][:rules_file]
|
17
35
|
end
|
18
36
|
end
|
19
|
-
elsif dest[0] == "D" and @rules_imported.key?(user.
|
20
|
-
unless @bots_created.key?(@rules_imported[user.
|
37
|
+
elsif dest[0] == "D" and @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name) #direct message
|
38
|
+
unless @bots_created.key?(@rules_imported[user.name][user.name])
|
21
39
|
get_bots_created()
|
22
40
|
end
|
23
|
-
if @bots_created.key?(@rules_imported[user.
|
24
|
-
rules_file = @bots_created[@rules_imported[user.
|
41
|
+
if @bots_created.key?(@rules_imported[user.name][user.name])
|
42
|
+
rules_file = @bots_created[@rules_imported[user.name][user.name]][:rules_file]
|
43
|
+
end
|
44
|
+
elsif dest[0] == 'D' and (!@rules_imported.key?(user.name) or ( @rules_imported.key?(user.name) and !@rules_imported[user.name].key?(user.name)))
|
45
|
+
if File.exist?("#{config.path}/rules/general_rules.rb")
|
46
|
+
rules_file = "/rules/general_rules.rb"
|
25
47
|
end
|
26
48
|
end
|
27
49
|
|
@@ -160,6 +182,9 @@ class SlackSmartBot
|
|
160
182
|
begin
|
161
183
|
t = Thread.new do
|
162
184
|
begin
|
185
|
+
processed = false
|
186
|
+
processed_rules = false
|
187
|
+
|
163
188
|
Thread.current[:dest] = dest
|
164
189
|
Thread.current[:user] = user
|
165
190
|
Thread.current[:command] = command
|
@@ -169,30 +194,36 @@ class SlackSmartBot
|
|
169
194
|
Thread.current[:ts] = ts
|
170
195
|
Thread.current[:thread_ts] = thread_ts
|
171
196
|
Thread.current[:routine] = routine
|
197
|
+
Thread.current[:routine_name] = routine_name
|
198
|
+
Thread.current[:routine_type] = routine_type
|
199
|
+
Thread.current[:dchannel] = dchannel
|
172
200
|
if thread_ts.to_s == ''
|
173
201
|
Thread.current[:on_thread] = false
|
174
202
|
Thread.current[:thread_ts] = Thread.current[:ts] # to create the thread if necessary
|
175
203
|
else
|
176
204
|
Thread.current[:on_thread] = true
|
177
205
|
end
|
178
|
-
if (dest[0] == "C") || (dest[0] == "G") and @rules_imported.key?(user.
|
179
|
-
@rules_imported[user.
|
180
|
-
Thread.current[:using_channel] = @rules_imported[user.
|
181
|
-
elsif dest[0] == "D" && @rules_imported.key?(user.
|
182
|
-
@bots_created.key?(@rules_imported[user.
|
183
|
-
Thread.current[:using_channel] = @rules_imported[user.
|
206
|
+
if (dest[0] == "C") || (dest[0] == "G") and @rules_imported.key?(user.name) &&
|
207
|
+
@rules_imported[user.name].key?(dchannel) && @bots_created.key?(@rules_imported[user.name][dchannel])
|
208
|
+
Thread.current[:using_channel] = @rules_imported[user.name][dchannel]
|
209
|
+
elsif dest[0] == "D" && @rules_imported.key?(user.name) && @rules_imported[user.name].key?(user.name) and
|
210
|
+
@bots_created.key?(@rules_imported[user.name][user.name])
|
211
|
+
Thread.current[:using_channel] = @rules_imported[user.name][user.name]
|
184
212
|
else
|
185
213
|
Thread.current[:using_channel] = ''
|
186
214
|
end
|
187
|
-
|
188
|
-
|
215
|
+
if typem == :on_pub or typem == :on_pg
|
216
|
+
processed = false
|
217
|
+
else
|
218
|
+
processed = process(user, command, dest, dchannel, rules_file, typem, files, Thread.current[:thread_ts])
|
219
|
+
end
|
189
220
|
@logger.info "command: #{nick}> #{command}" if processed
|
190
221
|
on_demand = false
|
191
|
-
if command.match(
|
192
|
-
command.match(
|
193
|
-
command.match(
|
194
|
-
command.match(
|
195
|
-
command.match(
|
222
|
+
if command.match(/\A@?(#{config[:nick]}):*\s+(.+)/im) or
|
223
|
+
command.match(/\A()!!(.+)/im) or
|
224
|
+
command.match(/\A()\^(.+)/im) or
|
225
|
+
command.match(/\A()!(.+)/im) or
|
226
|
+
command.match(/\A()<@#{config[:nick_id]}>\s+(.+)/im)
|
196
227
|
command2 = $2
|
197
228
|
Thread.current[:command] = command2
|
198
229
|
if command2.match?(/^()!!(.+)/im) or
|
@@ -202,7 +233,25 @@ class SlackSmartBot
|
|
202
233
|
command = command2
|
203
234
|
on_demand = true
|
204
235
|
end
|
205
|
-
unless config.on_maintenance
|
236
|
+
unless config.on_maintenance or @status != :on
|
237
|
+
if typem == :on_pub or typem == :on_pg or typem == :on_extended
|
238
|
+
if command.match(/\A\s*(#{@salutations.join("|")})\s+(rules|help)\s*(.+)?$/i) or command.match(/\A(#{@salutations.join("|")}),? what can I do/i)
|
239
|
+
$2.to_s.match?(/rules/i) ? specific = true : specific = false
|
240
|
+
help_command = $3
|
241
|
+
if typem == :on_extended and specific
|
242
|
+
bot_rules(dest, help_command, typem, rules_file, user)
|
243
|
+
else
|
244
|
+
bot_help(user, user.name, dest, dchannel, specific, help_command, rules_file)
|
245
|
+
end
|
246
|
+
processed = true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
processed = (processed || general_bot_commands(user, command, dest, files) )
|
250
|
+
processed = (processed || general_commands(user, command, dest, files) ) if defined?(general_commands)
|
251
|
+
@logger.info "command: #{nick}> #{command}" if processed
|
252
|
+
end
|
253
|
+
|
254
|
+
if !config.on_maintenance and !processed and typem != :on_pub and typem != :on_pg
|
206
255
|
if @status == :on and
|
207
256
|
(!answer.empty? or
|
208
257
|
(@repl_sessions.key?(nick) and dest==@repl_sessions[nick][:dest] and
|
@@ -216,9 +265,9 @@ class SlackSmartBot
|
|
216
265
|
#todo: verify this
|
217
266
|
|
218
267
|
if dest[0] == "C" or dest[0] == "G" or (dest[0] == "D" and typem == :on_call)
|
219
|
-
if typem != :on_call and @rules_imported.key?(user.
|
220
|
-
if @bots_created.key?(@rules_imported[user.
|
221
|
-
if @bots_created[@rules_imported[user.
|
268
|
+
if typem != :on_call and @rules_imported.key?(user.name) and @rules_imported[user.name].key?(dchannel)
|
269
|
+
if @bots_created.key?(@rules_imported[user.name][dchannel])
|
270
|
+
if @bots_created[@rules_imported[user.name][dchannel]][:status] != :on
|
222
271
|
respond "The bot on that channel is not :on", dest
|
223
272
|
rules_file = ""
|
224
273
|
end
|
@@ -235,19 +284,19 @@ class SlackSmartBot
|
|
235
284
|
command[0] = "" if command[0] == "!"
|
236
285
|
command.gsub!(/^@\w+:*\s*/, "")
|
237
286
|
if method(:rules).parameters.size == 4
|
238
|
-
rules(user, command, processed, dest)
|
287
|
+
processed_rules = rules(user, command, processed, dest)
|
239
288
|
elsif method(:rules).parameters.size == 5
|
240
|
-
rules(user, command, processed, dest, files)
|
289
|
+
processed_rules = rules(user, command, processed, dest, files)
|
241
290
|
else
|
242
|
-
rules(user, command, processed, dest, files, rules_file)
|
291
|
+
processed_rules = rules(user, command, processed, dest, files, rules_file)
|
243
292
|
end
|
244
293
|
else
|
245
294
|
@logger.warn "It seems like rules method is not defined"
|
246
295
|
end
|
247
296
|
end
|
248
|
-
elsif @rules_imported.key?(user.
|
249
|
-
if @bots_created.key?(@rules_imported[user.
|
250
|
-
if @bots_created[@rules_imported[user.
|
297
|
+
elsif @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name)
|
298
|
+
if @bots_created.key?(@rules_imported[user.name][user.name])
|
299
|
+
if @bots_created[@rules_imported[user.name][user.name]][:status] == :on
|
251
300
|
begin
|
252
301
|
eval(File.new(config.path+rules_file).read) if File.exist?(config.path+rules_file) and !['.','..'].include?(config.path + rules_file)
|
253
302
|
rescue Exception => stack
|
@@ -255,7 +304,7 @@ class SlackSmartBot
|
|
255
304
|
@logger.fatal stack
|
256
305
|
end
|
257
306
|
else
|
258
|
-
respond "The bot on <##{@rules_imported[user.
|
307
|
+
respond "The bot on <##{@rules_imported[user.name][user.name]}|#{@bots_created[@rules_imported[user.name][user.name]][:channel_name]}> is not :on", dest
|
259
308
|
rules_file = ""
|
260
309
|
end
|
261
310
|
end
|
@@ -265,16 +314,43 @@ class SlackSmartBot
|
|
265
314
|
command[0] = "" if command[0] == "!"
|
266
315
|
command.gsub!(/^@\w+:*\s*/, "")
|
267
316
|
if method(:rules).parameters.size == 4
|
268
|
-
rules(user, command, processed, dest)
|
317
|
+
processed_rules = rules(user, command, processed, dest)
|
269
318
|
elsif method(:rules).parameters.size == 5
|
270
|
-
rules(user, command, processed, dest, files)
|
319
|
+
processed_rules = rules(user, command, processed, dest, files)
|
271
320
|
else
|
272
|
-
rules(user, command, processed, dest, files, rules_file)
|
321
|
+
processed_rules = rules(user, command, processed, dest, files, rules_file)
|
273
322
|
end
|
274
323
|
else
|
275
324
|
@logger.warn "It seems like rules method is not defined"
|
276
325
|
end
|
277
326
|
end
|
327
|
+
elsif dest[0] == 'D' and
|
328
|
+
(!@rules_imported.key?(user.name) or ( @rules_imported.key?(user.name) and !@rules_imported[user.name].key?(user.name))) and
|
329
|
+
rules_file.include?('general_rules.rb')
|
330
|
+
begin
|
331
|
+
eval(File.new(config.path+rules_file).read) if File.exist?(config.path+rules_file) and !['.','..'].include?(config.path + rules_file)
|
332
|
+
rescue Exception => stack
|
333
|
+
@logger.fatal "ERROR ON imported RULES FILE: #{rules_file}"
|
334
|
+
@logger.fatal stack
|
335
|
+
end
|
336
|
+
|
337
|
+
if defined?(general_rules)
|
338
|
+
command[0] = "" if command[0] == "!"
|
339
|
+
command.gsub!(/^@\w+:*\s*/, "")
|
340
|
+
#todo: check to change processed > processed_rules
|
341
|
+
if method(:general_rules).parameters.size == 4
|
342
|
+
processed = general_rules(user, command, processed, dest)
|
343
|
+
elsif method(:general_rules).parameters.size == 5
|
344
|
+
processed = general_rules(user, command, processed, dest, files)
|
345
|
+
else
|
346
|
+
processed = general_rules(user, command, processed, dest, files, rules_file)
|
347
|
+
end
|
348
|
+
else
|
349
|
+
@logger.warn "It seems like general_rules method is not defined"
|
350
|
+
end
|
351
|
+
unless processed
|
352
|
+
dont_understand('')
|
353
|
+
end
|
278
354
|
else
|
279
355
|
@logger.info "it is a direct message with no rules file selected so no rules file executed."
|
280
356
|
if command.match?(/^\s*bot\s+rules\s*(.*)$/i)
|
@@ -285,6 +361,8 @@ class SlackSmartBot
|
|
285
361
|
end
|
286
362
|
end
|
287
363
|
|
364
|
+
processed = (processed_rules || processed)
|
365
|
+
|
288
366
|
if processed and @listening.key?(nick)
|
289
367
|
if Thread.current[:on_thread] and @listening[nick].key?(Thread.current[:thread_ts])
|
290
368
|
@listening[nick][Thread.current[:thread_ts]] = Time.now
|
@@ -292,9 +370,12 @@ class SlackSmartBot
|
|
292
370
|
@listening[nick][dest] = Time.now
|
293
371
|
end
|
294
372
|
end
|
295
|
-
|
296
373
|
end
|
297
374
|
end
|
375
|
+
|
376
|
+
if processed and config.general_message != '' and !routine
|
377
|
+
respond eval("\"" + config.general_message + "\"")
|
378
|
+
end
|
298
379
|
rescue Exception => stack
|
299
380
|
@logger.fatal stack
|
300
381
|
end
|