slack-smart-bot 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +134 -23
- data/lib/slack/smart-bot/comm/delete.rb +13 -0
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/get_channel_members.rb +7 -3
- data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +1 -1
- data/lib/slack/smart-bot/comm/respond.rb +24 -13
- data/lib/slack/smart-bot/comm/send_msg_user.rb +12 -11
- data/lib/slack/smart-bot/comm/set_status.rb +21 -0
- data/lib/slack/smart-bot/comm.rb +3 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +1 -1
- data/lib/slack/smart-bot/commands/general/add_memo_team.rb +117 -0
- data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
- data/lib/slack/smart-bot/commands/general/add_vacation.rb +51 -0
- data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +20 -11
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +1 -1
- data/lib/slack/smart-bot/commands/general/delete_memo_team.rb +69 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +1 -1
- data/lib/slack/smart-bot/commands/general/delete_team.rb +54 -0
- data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
- data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
- data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
- data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
- data/lib/slack/smart-bot/commands/general/remove_vacation.rb +27 -0
- data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
- data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +7 -5
- data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +3 -4
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +34 -21
- data/lib/slack/smart-bot/commands/general/see_teams.rb +402 -0
- data/lib/slack/smart-bot/commands/general/see_vacations.rb +58 -0
- data/lib/slack/smart-bot/commands/general/see_vacations_team.rb +136 -0
- data/lib/slack/smart-bot/commands/general/set_memo_status.rb +58 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +1 -1
- data/lib/slack/smart-bot/commands/general/update_team.rb +130 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +442 -13
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +3 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +10 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +3 -1
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +15 -2
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +5 -4
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +416 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/leaderboard.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/suggest_command.rb +6 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +1 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +73 -15
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +117 -28
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +2 -1
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +3 -2
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +5 -4
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -2
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +6 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
- data/lib/slack/smart-bot/commands.rb +30 -7
- data/lib/slack/smart-bot/listen.rb +30 -30
- data/lib/slack/smart-bot/process.rb +53 -23
- data/lib/slack/smart-bot/process_first.rb +2 -2
- data/lib/slack/smart-bot/treat_message.rb +23 -17
- data/lib/slack/smart-bot/utils/build_help.rb +1 -1
- data/lib/slack/smart-bot/utils/check_vacations.rb +43 -0
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +1 -1
- data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
- data/lib/slack/smart-bot/utils/get_admins_channels.rb +33 -0
- data/lib/slack/smart-bot/utils/get_bots_created.rb +27 -10
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
- data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
- data/lib/slack/smart-bot/utils/get_help.rb +36 -19
- data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
- data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
- data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
- data/lib/slack/smart-bot/utils/get_vacations.rb +22 -0
- data/lib/slack/smart-bot/utils/has_access.rb +25 -9
- data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +52 -42
- data/lib/slack/smart-bot/utils/save_status.rb +22 -7
- data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
- data/lib/slack/smart-bot/utils/update_admins_channels.rb +25 -0
- data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
- data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
- data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
- data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
- data/lib/slack/smart-bot/utils/update_vacations.rb +16 -0
- data/lib/slack/smart-bot/utils.rb +11 -0
- data/lib/slack-smart-bot.rb +50 -12
- data/lib/slack-smart-bot_general_commands.rb +16 -1
- data/whats_new.txt +12 -30
- metadata +78 -21
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -314
@@ -1,20 +1,22 @@
|
|
1
|
-
require_relative "commands/general/whats_new"
|
2
1
|
require_relative "commands/general/hi_bot"
|
3
2
|
require_relative "commands/general/bye_bot"
|
4
3
|
require_relative "commands/general/bot_help"
|
5
|
-
require_relative "commands/general/suggest_command"
|
4
|
+
require_relative "commands/on_bot/general/suggest_command"
|
6
5
|
require_relative "commands/on_bot/ruby_code"
|
7
6
|
require_relative "commands/on_bot/repl"
|
8
7
|
require_relative "commands/on_bot/get_repl"
|
9
8
|
require_relative "commands/on_bot/run_repl"
|
9
|
+
require_relative "commands/on_bot/kill_repl"
|
10
10
|
require_relative "commands/on_bot/delete_repl"
|
11
11
|
require_relative "commands/on_bot/see_repls"
|
12
|
-
require_relative "commands/general/
|
13
|
-
require_relative "commands/general/
|
12
|
+
require_relative "commands/on_bot/general/whats_new"
|
13
|
+
require_relative "commands/on_bot/general/use_rules"
|
14
|
+
require_relative "commands/on_bot/general/stop_using_rules"
|
14
15
|
require_relative "commands/on_master/admin_master/exit_bot"
|
15
16
|
require_relative "commands/on_master/admin_master/notify_message"
|
16
17
|
require_relative "commands/on_master/admin/kill_bot_on_channel"
|
17
18
|
require_relative "commands/on_master/create_bot"
|
19
|
+
require_relative "commands/on_master/where_smartbot"
|
18
20
|
require_relative "commands/on_bot/admin/add_routine"
|
19
21
|
require_relative "commands/on_bot/admin/start_bot"
|
20
22
|
require_relative "commands/on_bot/admin/pause_bot"
|
@@ -26,16 +28,17 @@ require_relative "commands/on_bot/admin/start_routine"
|
|
26
28
|
require_relative "commands/on_bot/admin/see_routines"
|
27
29
|
require_relative "commands/on_bot/admin/extend_rules"
|
28
30
|
require_relative "commands/on_bot/admin/stop_using_rules_on"
|
29
|
-
require_relative "commands/general/bot_status"
|
31
|
+
require_relative "commands/on_bot/general/bot_status"
|
30
32
|
require_relative "commands/on_bot/add_shortcut"
|
31
33
|
require_relative "commands/on_bot/delete_shortcut"
|
32
34
|
require_relative "commands/on_bot/see_shortcuts"
|
33
35
|
require_relative "commands/on_extended/bot_rules"
|
34
36
|
require_relative "commands/on_bot/admin_master/get_bot_logs"
|
35
37
|
require_relative "commands/on_bot/admin_master/send_message"
|
38
|
+
require_relative "commands/on_bot/admin_master/delete_message"
|
36
39
|
require_relative "commands/on_bot/admin_master/react_to"
|
37
|
-
require_relative "commands/general/bot_stats"
|
38
|
-
require_relative "commands/general/leaderboard"
|
40
|
+
require_relative "commands/on_bot/general/bot_stats"
|
41
|
+
require_relative "commands/on_bot/general/leaderboard"
|
39
42
|
require_relative "commands/general/add_announcement"
|
40
43
|
require_relative "commands/general/delete_announcement"
|
41
44
|
require_relative "commands/general/see_announcements"
|
@@ -48,3 +51,23 @@ require_relative "commands/general_bot_commands"
|
|
48
51
|
require_relative "commands/general/share_messages"
|
49
52
|
require_relative "commands/general/see_shares"
|
50
53
|
require_relative "commands/general/delete_share"
|
54
|
+
require_relative "commands/general/see_admins"
|
55
|
+
require_relative "commands/general/add_admin"
|
56
|
+
require_relative "commands/general/remove_admin"
|
57
|
+
require_relative "commands/general/see_command_ids"
|
58
|
+
require_relative "commands/general/poster"
|
59
|
+
require_relative "commands/general/see_access"
|
60
|
+
require_relative "commands/general/allow_access"
|
61
|
+
require_relative "commands/general/deny_access"
|
62
|
+
require_relative "commands/general/add_team"
|
63
|
+
require_relative "commands/general/add_memo_team"
|
64
|
+
require_relative "commands/general/set_memo_status"
|
65
|
+
require_relative "commands/general/delete_memo_team"
|
66
|
+
require_relative "commands/general/see_teams"
|
67
|
+
require_relative "commands/general/update_team"
|
68
|
+
require_relative "commands/general/ping_team"
|
69
|
+
require_relative "commands/general/delete_team"
|
70
|
+
require_relative "commands/general/add_vacation"
|
71
|
+
require_relative "commands/general/remove_vacation"
|
72
|
+
require_relative "commands/general/see_vacations"
|
73
|
+
require_relative "commands/general/see_vacations_team"
|
@@ -4,39 +4,39 @@ class SlackSmartBot
|
|
4
4
|
@pings = []
|
5
5
|
@last_activity_check = Time.now
|
6
6
|
get_bots_created()
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
7
|
+
@buffer_complete = [] unless defined?(@buffer_complete)
|
8
|
+
b = File.read("#{config.path}/buffer_complete.log")
|
9
|
+
result = b.scan(/^\|(\w+)\|(\w+)\|(\w+)\|([^~]+)~~~/m)
|
10
|
+
result.delete(nil)
|
11
|
+
new_messages = result[@buffer_complete.size..-1]
|
12
|
+
unless new_messages.nil? or new_messages.empty?
|
13
|
+
@buffer_complete = result
|
14
|
+
new_messages.each do |message|
|
15
|
+
channel = message[0].strip
|
16
|
+
user = message[1].strip
|
17
|
+
user_name = message[2].strip
|
18
|
+
command = message[3].to_s.strip
|
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
|
+
@logger.info "treat message: #{message}" if config.testing
|
21
|
+
if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
|
22
|
+
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
23
|
+
if cmd.to_s != ""
|
24
|
+
cmd = "^#{cmd}"
|
25
|
+
treat_message({ channel: channel, user: user, text: cmd, user_name: user_name }, false)
|
27
26
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
end
|
28
|
+
elsif command.match?(/^\s*\-!/)
|
29
|
+
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
30
|
+
if cmd.to_s != ""
|
31
|
+
cmd = "!#{cmd}"
|
32
|
+
treat_message({ channel: channel, user: user, text: cmd, user_name: user_name }, false)
|
34
33
|
end
|
35
|
-
else
|
36
|
-
treat_message({channel: channel, user: user, text: command, user_name: user_name})
|
37
34
|
end
|
35
|
+
else
|
36
|
+
treat_message({ channel: channel, user: user, text: command, user_name: user_name })
|
38
37
|
end
|
39
38
|
end
|
39
|
+
end
|
40
40
|
end
|
41
41
|
|
42
42
|
def listen
|
@@ -48,7 +48,7 @@ class SlackSmartBot
|
|
48
48
|
unless data.user == "USLACKBOT" or data.text.nil?
|
49
49
|
if data.text.match?(/^\s*\-!!/) or data.text.match?(/^\s*\-\^/)
|
50
50
|
data.text.scan(/`([^`]+)`/).flatten.each do |cmd|
|
51
|
-
if cmd.to_s!=
|
51
|
+
if cmd.to_s != ""
|
52
52
|
datao = data.dup
|
53
53
|
datao.text = "^#{cmd}"
|
54
54
|
treat_message(datao, false)
|
@@ -56,7 +56,7 @@ class SlackSmartBot
|
|
56
56
|
end
|
57
57
|
elsif data.text.match?(/^\s*\-!/)
|
58
58
|
data.text.scan(/`([^`]+)`/).flatten.each do |cmd|
|
59
|
-
if cmd.to_s!=
|
59
|
+
if cmd.to_s != ""
|
60
60
|
datao = data.dup
|
61
61
|
datao.text = "!#{cmd}"
|
62
62
|
treat_message(datao, false)
|
@@ -99,6 +99,8 @@ class SlackSmartBot
|
|
99
99
|
/\Akill\s+bot\s+on\s+#(.+)\s*$/i, /\Akill\s+bot\s+on\s+(.+)\s*$/i
|
100
100
|
channel = $1
|
101
101
|
kill_bot_on_channel(dest, from, channel)
|
102
|
+
when /\A\s*(where\s+is|which\s+channels|where\s+is\s+a\s+member)\s+(#{@salutations.join("|")})\??\s*$/i
|
103
|
+
where_smartbot(user)
|
102
104
|
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
105
|
/\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
106
|
/\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,
|
@@ -150,29 +152,44 @@ class SlackSmartBot
|
|
150
152
|
see_routines(dest, from, user, all)
|
151
153
|
when /\A\s*get\s+bot\s+logs?\s*$/i
|
152
154
|
get_bot_logs(dest, from, typem)
|
153
|
-
when /\A\s*send\s+message\s+(on|to|in)\s
|
154
|
-
/\A\s*send\s+message\s+(on|to|in)\s
|
155
|
-
to
|
156
|
-
|
157
|
-
message = $
|
158
|
-
|
159
|
-
to_channel =
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
to
|
155
|
+
when /\A\s*send\s+message\s+(on|to|in)\s+<(https?:[^:]+)>\s*:\s*(.+)\s*$/im,
|
156
|
+
/\A\s*send\s+message\s+(on|to|in)\s+(https?:[^:]+)\s*:\s*(.+)\s*$/im,
|
157
|
+
/\A\s*send\s+message\s+(on|to|in)\s*([^:]+)\s*:\s*(.+)\s*$/im
|
158
|
+
opts = $2
|
159
|
+
message = $3
|
160
|
+
thread_ts = ''
|
161
|
+
to_channel = ''
|
162
|
+
to = []
|
163
|
+
|
164
|
+
opts.split(' ').each do |opt|
|
165
|
+
if opt.match?(/\Ahttps:/i)
|
166
|
+
to_channel, thread_ts = opt.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
|
167
|
+
to << to_channel
|
168
|
+
elsif opt.match(/<#([^>]+)\|.*>/) #channel
|
169
|
+
to << $1
|
170
|
+
elsif opt.match(/#([^\s]+)/) #channel
|
171
|
+
to << $1
|
172
|
+
elsif opt.match(/<@(\w+)>/)
|
173
|
+
to << $1
|
166
174
|
end
|
167
|
-
else
|
168
|
-
to = to_channel
|
169
175
|
end
|
176
|
+
|
177
|
+
thread_ts.gsub!('.','')
|
170
178
|
send_message(dest, from, typem, to, thread_ts, message)
|
171
|
-
when /\A\s*
|
179
|
+
when /\A\s*delete\s+message\s+(http.+)\s*$/i
|
180
|
+
url = $1
|
181
|
+
delete_message(from, typem, url)
|
182
|
+
when /\A\s*react\s+(on|to|in)\s*([^\s]+)\s+([p\d\.]+)\s+(.+)\s*$/i,
|
183
|
+
/\A\s*react\s+(on|to|in)\s*([^\s]+)\s+()(.+)\s*$/i
|
172
184
|
to = $2
|
173
185
|
thread_ts = $3.to_s
|
174
186
|
emojis = $4
|
175
|
-
|
187
|
+
|
188
|
+
if to.match?(/\A<?https:/i)
|
189
|
+
to_channel, thread_ts = to.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
|
190
|
+
else
|
191
|
+
to_channel = to.scan(/<#([^>]+)\|.*>/).join
|
192
|
+
end
|
176
193
|
if to_channel == ''
|
177
194
|
to_channel = to.scan(/#([^\s]+)/).join
|
178
195
|
to_channel = @channels_id[to_channel].to_s
|
@@ -251,6 +268,10 @@ class SlackSmartBot
|
|
251
268
|
|
252
269
|
when /\A\s*bot\s+stats\s*(.*)\s*$/i
|
253
270
|
opts = $1.to_s
|
271
|
+
exclude_members_channel = opts.scan(/exclude\s+members\s+<#(\w+)\|.*>/i).join #todo: add test
|
272
|
+
opts.gsub!(/exclude\s+members\s+<#\w+\|.*>/,'')
|
273
|
+
members_channel = opts.scan(/members\s+<#(\w+)\|.*>/i).join #todo: add test
|
274
|
+
opts.gsub!(/members\s+<#\w+\|.*>/,'')
|
254
275
|
all_opts = opts.downcase.split(' ')
|
255
276
|
all_data = all_opts.include?('alldata')
|
256
277
|
st_channel = opts.scan(/<#(\w+)\|.*>/).join
|
@@ -259,6 +280,7 @@ class SlackSmartBot
|
|
259
280
|
st_to = opts.scan(/to\s+(\d\d\d\d[\/\-\.]\d\d[\/\-\.]\d\d)/).join
|
260
281
|
st_to = st_to.gsub('.','-').gsub('/','-')
|
261
282
|
st_user = opts.scan(/<@([^>]+)>/).join
|
283
|
+
st_user = opts.scan(/@([^\s]+)/).join if st_user == ''
|
262
284
|
st_command = opts.scan(/\s+command\s+(\w+)/i).join.downcase
|
263
285
|
st_command = opts.scan(/^command\s+(\w+)/i).join.downcase if st_command == ''
|
264
286
|
exclude_masters = all_opts.include?('exclude') && all_opts.include?('masters')
|
@@ -284,7 +306,7 @@ class SlackSmartBot
|
|
284
306
|
if (typem == :on_master or typem == :on_bot) and dest[0]!='D' #routine bot stats to be published on DM
|
285
307
|
st_channel = dchannel
|
286
308
|
end
|
287
|
-
bot_stats(dest, user, typem, st_channel, st_from, st_to, st_user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data)
|
309
|
+
bot_stats(dest, user, typem, st_channel, st_from, st_to, st_user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data, members_channel, exclude_members_channel)
|
288
310
|
when /\A(set|turn)\s+maintenance\s+(on|off)\s*()\z/im, /\A(set|turn)\s+maintenance\s+(on)\s*(.+)\s*\z/im
|
289
311
|
status = $2.downcase
|
290
312
|
message = $3.to_s
|
@@ -376,11 +398,15 @@ class SlackSmartBot
|
|
376
398
|
when /\A\s*get\s+(repl|irb|live)\s+([\w\-]+)\s*/i
|
377
399
|
session_name = $2
|
378
400
|
get_repl(dest, user, session_name)
|
379
|
-
when /\A\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s
|
380
|
-
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/
|
401
|
+
when /\A\s*run\s+(repl|irb|live)\s+([\w\-]+)()\s*\z/im,
|
402
|
+
/^\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/im
|
381
403
|
session_name = $2
|
382
|
-
|
383
|
-
|
404
|
+
if Thread.current[:command_orig].match(/\s*run\s+(repl|irb|live)\s+([\w\-]+)\s+(.+)\s*$/im)
|
405
|
+
opts = " #{$3}"
|
406
|
+
else
|
407
|
+
opts = ''
|
408
|
+
end
|
409
|
+
env_vars = opts.scan(/\s+[\w\-]+="[^"]+"/i) + opts.scan(/\s+[\w\-]+='[^']+'/i)
|
384
410
|
opts.scan(/\s+[\w\-]+=[^'"\s]+/i).flatten.each do |ev|
|
385
411
|
env_vars << ev.gsub('=',"='") + "'"
|
386
412
|
end
|
@@ -389,12 +415,16 @@ class SlackSmartBot
|
|
389
415
|
ev.lstrip!
|
390
416
|
env_vars[idx] = "ENV['#{ev}"
|
391
417
|
end
|
392
|
-
|
418
|
+
prerun = Thread.current[:command_orig].gsub('```', '`').scan(/\s+`(.+)`/m)
|
419
|
+
run_repl(dest, user, session_name, env_vars.flatten, prerun.flatten, rules_file)
|
393
420
|
when /\A\s*(delete|remove)\s+(repl|irb|live)\s+([\w\-]+)\s*$/i
|
394
421
|
repl_name = $3
|
395
422
|
delete_repl(dest, user, repl_name)
|
396
423
|
when /\A\s*see\s+(repls|repl|irb|irbs)\s*$/i
|
397
424
|
see_repls(dest, user, typem)
|
425
|
+
when /\A\s*(kill)\s+(repl|irb|live)\s+([\w]+)\s*$/i
|
426
|
+
repl_id = $3
|
427
|
+
kill_repl(dest, user, repl_id)
|
398
428
|
else
|
399
429
|
processed2 = false
|
400
430
|
end #of case
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class SlackSmartBot
|
2
|
-
def process_first(user, text, dest, dchannel, typem, files, ts, thread_ts, routine, routine_name, routine_type)
|
2
|
+
def process_first(user, text, dest, dchannel, typem, files, ts, thread_ts, routine, routine_name, routine_type, command_orig)
|
3
3
|
nick = user.name
|
4
4
|
rules_file = ""
|
5
5
|
text.gsub!(/^!!/,'^') # to treat it just as ^
|
@@ -46,7 +46,6 @@ class SlackSmartBot
|
|
46
46
|
rules_file = "/rules/general_rules.rb"
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
50
49
|
if nick == config[:nick] #if message is coming from the bot
|
51
50
|
begin
|
52
51
|
case text
|
@@ -197,6 +196,7 @@ class SlackSmartBot
|
|
197
196
|
Thread.current[:routine_name] = routine_name
|
198
197
|
Thread.current[:routine_type] = routine_type
|
199
198
|
Thread.current[:dchannel] = dchannel
|
199
|
+
Thread.current[:command_orig] = command_orig
|
200
200
|
if thread_ts.to_s == ''
|
201
201
|
Thread.current[:on_thread] = false
|
202
202
|
Thread.current[:thread_ts] = Thread.current[:ts] # to create the thread if necessary
|
@@ -3,6 +3,7 @@ class SlackSmartBot
|
|
3
3
|
@buffered = false if config[:testing]
|
4
4
|
begin
|
5
5
|
begin
|
6
|
+
command_orig = data.text
|
6
7
|
unless data.text.to_s.match(/\A\s*\z/)
|
7
8
|
#to remove italic, bold... from data.text since there is no method on slack api
|
8
9
|
if remove_blocks and !data.blocks.nil? and data.blocks.size > 0
|
@@ -73,6 +74,12 @@ class SlackSmartBot
|
|
73
74
|
if !dest.nil? and config.on_master_bot and !data.text.nil? and data.text.match(/^ping from (.+)\s*$/) and data.user == config[:nick_id]
|
74
75
|
@pings << $1
|
75
76
|
end
|
77
|
+
if config.on_master_bot and @vacations_check != Date.today
|
78
|
+
@vacations_check = Date.today
|
79
|
+
t = Thread.new do
|
80
|
+
check_vacations(only_first_day: true)
|
81
|
+
end
|
82
|
+
end
|
76
83
|
typem = :dont_treat
|
77
84
|
if data.nil? or data.user.nil? or data.user.to_s==''
|
78
85
|
user_info = nil
|
@@ -86,6 +93,7 @@ class SlackSmartBot
|
|
86
93
|
end
|
87
94
|
end
|
88
95
|
if !dest.nil? and !data.text.nil? and !data.text.to_s.match?(/\A\s*\z/)
|
96
|
+
get_bots_created()
|
89
97
|
if data.channel[0] == "D" and !data.text.to_s.match?(/^\s*<@#{config[:nick_id]}>\s+/) and
|
90
98
|
(data.text.to_s.match?(/^\s*(on)?\s*<#\w+\|[^>]*>/i) or data.text.to_s.match?(/^\s*(on)?\s*#\w+/i))
|
91
99
|
data.text = "<@#{config[:nick_id]}> " + data.text.to_s
|
@@ -183,7 +191,8 @@ class SlackSmartBot
|
|
183
191
|
end
|
184
192
|
end
|
185
193
|
end
|
186
|
-
load "#{config.path}/rules/general_commands.rb" if File.
|
194
|
+
load "#{config.path}/rules/general_commands.rb" if File.exist?("#{config.path}/rules/general_commands.rb") and @datetime_general_commands != File.mtime("#{config.path}/rules/general_commands.rb")
|
195
|
+
eval(File.new(config.path + config.rules_file).read) if !defined?(rules) and File.exist?(config.path+config.rules_file) and !config.rules_file.empty?
|
187
196
|
unless typem == :dont_treat or user_info.nil?
|
188
197
|
if (Time.now - @last_activity_check) > 60 * 30 #every 30 minutes
|
189
198
|
@last_activity_check = Time.now
|
@@ -241,7 +250,6 @@ class SlackSmartBot
|
|
241
250
|
command += " ruby" if command != "ruby"
|
242
251
|
command = "#{command} #{res.body.to_s.force_encoding("UTF-8")}"
|
243
252
|
end
|
244
|
-
|
245
253
|
if typem == :on_call
|
246
254
|
command = "!" + command unless command[0] == "!" or command.match?(/^\s*$/) or command[0] == "^"
|
247
255
|
|
@@ -256,24 +264,24 @@ class SlackSmartBot
|
|
256
264
|
elsif @status != :on
|
257
265
|
respond "The bot in that channel is not :on", data.channel
|
258
266
|
elsif data.user == channel_found.creator or members.include?(data.user)
|
259
|
-
process_first(user_info, command, dest, channel_rules, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type)
|
267
|
+
process_first(user_info, command, dest, channel_rules, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type, command_orig)
|
260
268
|
else
|
261
269
|
respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", data.channel
|
262
270
|
end
|
263
271
|
elsif config.on_master_bot and typem == :on_extended and
|
264
272
|
command.size > 0 and command[0] != "-"
|
265
273
|
# to run ruby only from the master bot for the case more than one extended
|
266
|
-
process_first(user_info, command, dest, @channel_id, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type)
|
274
|
+
process_first(user_info, command, dest, @channel_id, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type, command_orig)
|
267
275
|
elsif !config.on_master_bot and @bots_created[@channel_id].key?(:extended) and
|
268
276
|
@bots_created[@channel_id][:extended].include?(@channels_name[data.channel]) and
|
269
277
|
command.size > 0 and command[0] != "-"
|
270
|
-
process_first(user_info, command, dest, @channel_id, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type)
|
278
|
+
process_first(user_info, command, dest, @channel_id, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type, command_orig)
|
271
279
|
elsif (dest[0] == "D" or @channel_id == data.channel or data.user == config[:nick_id]) and
|
272
280
|
command.size > 0 and command[0] != "-"
|
273
|
-
process_first(user_info, command, dest, data.channel, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type)
|
281
|
+
process_first(user_info, command, dest, data.channel, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type, command_orig)
|
274
282
|
# if @botname on #channel_rules: do something
|
275
283
|
elsif typem == :on_pub or typem == :on_pg
|
276
|
-
process_first(user_info, command, dest, channel_rules, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type)
|
284
|
+
process_first(user_info, command, dest, channel_rules, typem, data.files, data.ts, data.thread_ts, data.routine, data.routine_name, data.routine_type, command_orig)
|
277
285
|
end
|
278
286
|
rescue Exception => stack
|
279
287
|
@logger.fatal stack
|
@@ -337,23 +345,21 @@ class SlackSmartBot
|
|
337
345
|
get_bots_created()
|
338
346
|
when /global shortcut added/
|
339
347
|
sleep 2
|
340
|
-
if File.exist?("#{config.path}/shortcuts/shortcuts_global.
|
341
|
-
|
342
|
-
unless file_sc.to_s() == ""
|
343
|
-
@shortcuts_global = eval(file_sc)
|
344
|
-
end
|
348
|
+
if File.exist?("#{config.path}/shortcuts/shortcuts_global.yaml")
|
349
|
+
@shortcuts_global = YAML.load(File.read("#{config.path}/shortcuts/shortcuts_global.yaml"))
|
345
350
|
end
|
346
351
|
when /global shortcut deleted/
|
347
352
|
sleep 2
|
348
|
-
if File.exist?("#{config.path}/shortcuts/shortcuts_global.
|
349
|
-
|
350
|
-
unless file_sc.to_s() == ""
|
351
|
-
@shortcuts_global = eval(file_sc)
|
352
|
-
end
|
353
|
+
if File.exist?("#{config.path}/shortcuts/shortcuts_global.yaml")
|
354
|
+
@shortcuts_global = YAML.load(File.read("#{config.path}/shortcuts/shortcuts_global.yaml"))
|
353
355
|
end
|
354
356
|
end
|
355
357
|
end
|
356
358
|
end
|
359
|
+
unless data.nil? or data.channel.nil? or data.channel.empty?
|
360
|
+
@announcements_activity_after[data.channel] ||= 0
|
361
|
+
@announcements_activity_after[data.channel] += 1
|
362
|
+
end
|
357
363
|
rescue Exception => stack
|
358
364
|
@logger.fatal stack
|
359
365
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def check_vacations(date: Date.today, user: nil, set_status: true, only_first_day: true)
|
3
|
+
get_vacations()
|
4
|
+
if user.nil?
|
5
|
+
users = @vacations.keys
|
6
|
+
else
|
7
|
+
users = [user]
|
8
|
+
end
|
9
|
+
on_vacation = []
|
10
|
+
users.each do |user|
|
11
|
+
type = nil
|
12
|
+
expiration = nil
|
13
|
+
@vacations[user].periods.each do |p|
|
14
|
+
if only_first_day and p.from == date.strftime("%Y/%m/%d")
|
15
|
+
type = p.type
|
16
|
+
on_vacation << user
|
17
|
+
expiration = p.to
|
18
|
+
break
|
19
|
+
elsif !only_first_day and p.from <= date.strftime("%Y/%m/%d") and p.to >= date.strftime("%Y/%m/%d")
|
20
|
+
type = p.type
|
21
|
+
on_vacation << user
|
22
|
+
expiration = p.to
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
unless type.nil? or !set_status
|
27
|
+
icon = ''
|
28
|
+
if type == 'vacation'
|
29
|
+
icon = ':palm_tree:'
|
30
|
+
elsif type == 'sick'
|
31
|
+
icon = ':face_with_thermometer:'
|
32
|
+
elsif type == 'sick child'
|
33
|
+
icon = ':baby:'
|
34
|
+
end
|
35
|
+
unless icon.empty?
|
36
|
+
expiration_date = Date.parse(expiration,'%Y/%m/%d') + 1 #next day at 0:00
|
37
|
+
set_status(@vacations[user].user_id, status: icon, expiration: expiration_date, message: "#{type} until #{expiration}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return on_vacation
|
42
|
+
end
|
43
|
+
end
|
@@ -25,7 +25,7 @@ class SlackSmartBot
|
|
25
25
|
(@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s!='weekday' and @routines[@channel_id][name][:dayweek].to_s!='weekend') or
|
26
26
|
(@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s=='weekday' and Date.today.wday>=1 and Date.today.wday<=5) or
|
27
27
|
(@routines[@channel_id][name].key?(:dayweek) and @routines[@channel_id][name][:dayweek].to_s=='weekend' and (Date.today.wday==6 or Date.today.wday==0))
|
28
|
-
File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.
|
28
|
+
File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.exist?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
|
29
29
|
if @routines[@channel_id][name][:file_path] != ""
|
30
30
|
process_to_run = "#{ruby}#{Dir.pwd}#{@routines[@channel_id][name][:file_path][1..-1]}"
|
31
31
|
process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def get_access_channels()
|
4
|
+
if File.exist?("#{config.path}/rules/#{@channel_id}/access_channels.rb")
|
5
|
+
file_conf = IO.readlines("#{config.path}/rules/#{@channel_id}/access_channels.rb").join
|
6
|
+
unless file_conf.to_s() == ""
|
7
|
+
@access_channels = eval(file_conf)
|
8
|
+
end
|
9
|
+
else
|
10
|
+
@access_channels = {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def get_admins_channels()
|
4
|
+
require 'yaml'
|
5
|
+
admins_file = "#{config.path}/rules/#{@channel_id}/admins_channels.yaml"
|
6
|
+
|
7
|
+
if File.exist?(admins_file.gsub(".yaml", ".rb")) #backwards compatible
|
8
|
+
file_conf = IO.readlines(admins_file.gsub(".yaml", ".rb")).join
|
9
|
+
if file_conf.to_s() == ""
|
10
|
+
@admins_channels = {}
|
11
|
+
else
|
12
|
+
@admins_channels = eval(file_conf)
|
13
|
+
end
|
14
|
+
File.open(admins_file, 'w') {|file| file.write(@admins_channels.to_yaml) }
|
15
|
+
File.delete(admins_file.gsub(".yaml", ".rb"))
|
16
|
+
end
|
17
|
+
|
18
|
+
if File.exist?(admins_file)
|
19
|
+
admins_channels = @admins_channels
|
20
|
+
10.times do
|
21
|
+
admins_channels = YAML.load(File.read(admins_file))
|
22
|
+
if admins_channels.is_a?(Hash)
|
23
|
+
break
|
24
|
+
else
|
25
|
+
sleep (0.1*(rand(2)+1))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@admins_channels = admins_channels unless admins_channels.is_a?(FalseClass)
|
29
|
+
else
|
30
|
+
@admins_channels = {}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,16 +1,33 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
def get_bots_created
|
3
|
-
|
3
|
+
require 'yaml'
|
4
|
+
bots_file = config.file_path.gsub(".rb", "_bots.yaml")
|
5
|
+
|
6
|
+
if File.exist?(config.file_path.gsub(".rb", "_bots.rb")) #backwards compatible
|
7
|
+
file_conf = IO.readlines(config.file_path.gsub(".rb", "_bots.rb")).join
|
8
|
+
if file_conf.to_s() == ""
|
9
|
+
@bots_created = {}
|
10
|
+
else
|
11
|
+
@bots_created = eval(file_conf)
|
12
|
+
end
|
13
|
+
File.open(bots_file, 'w') {|file| file.write(@bots_created.to_yaml) }
|
14
|
+
File.delete(config.file_path.gsub(".rb", "_bots.rb"))
|
15
|
+
end
|
16
|
+
|
17
|
+
if File.exist?(bots_file)
|
4
18
|
|
5
|
-
if !defined?(@datetime_bots_created) or @datetime_bots_created != File.mtime(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
19
|
+
if !defined?(@datetime_bots_created) or @datetime_bots_created != File.mtime(bots_file)
|
20
|
+
bots_created = @bots_created
|
21
|
+
10.times do
|
22
|
+
bots_created = YAML.load(File.read(bots_file))
|
23
|
+
if bots_created.is_a?(Hash)
|
24
|
+
break
|
25
|
+
else
|
26
|
+
sleep (0.1*(rand(2)+1))
|
27
|
+
end
|
12
28
|
end
|
13
|
-
@
|
29
|
+
@bots_created = bots_created unless bots_created.is_a?(FalseClass)
|
30
|
+
@datetime_bots_created = File.mtime(bots_file)
|
14
31
|
@extended_from = {}
|
15
32
|
@bots_created.each do |k, v|
|
16
33
|
v[:extended] = [] unless v.key?(:extended)
|
@@ -20,7 +37,7 @@ class SlackSmartBot
|
|
20
37
|
end
|
21
38
|
v[:rules_file] ||= ''
|
22
39
|
v[:rules_file].gsub!(/^\./, '')
|
23
|
-
end
|
40
|
+
end
|
24
41
|
end
|
25
42
|
end
|
26
43
|
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
3
|
def get_channels_name_and_id
|
4
|
-
|
4
|
+
@channels_list = get_channels()
|
5
5
|
@channels_id = Hash.new()
|
6
6
|
@channels_name = Hash.new()
|
7
|
-
|
7
|
+
@channels_creator = Hash.new()
|
8
|
+
@users = get_users() if @users.empty?
|
9
|
+
@channels_list.each do |ch|
|
8
10
|
unless ch.is_archived
|
9
11
|
@channels_id[ch.name] = ch.id
|
10
12
|
@channels_name[ch.id] = ch.name
|
13
|
+
user_info = @users.select{|u| u.id == ch.creator or (u.key?(:enterprise_user) and u.enterprise_user.id == ch.creator)}[-1]
|
14
|
+
@channels_creator[ch.id] = user_info.name unless user_info.nil?
|
15
|
+
@channels_creator[ch.name] = user_info.name unless user_info.nil?
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|