slack-smart-bot 1.14.2 → 1.15.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 +222 -37
- data/img/chat_gpt.png +0 -0
- data/img/chat_gpt_session.png +0 -0
- data/img/chat_gpt_share.png +0 -0
- data/img/command_add_sc.png +0 -0
- data/img/command_bot_help_echo.png +0 -0
- data/img/command_loop.png +0 -0
- data/img/command_my_timeoff.png +0 -0
- data/img/command_recap.png +0 -0
- data/img/command_repl1.png +0 -0
- data/img/command_repl2.png +0 -0
- data/img/command_ruby.png +0 -0
- data/img/command_run_repl.png +0 -0
- data/img/command_see_announcements.png +0 -0
- data/img/command_see_statuses.png +0 -0
- data/img/command_see_team.png +0 -0
- data/img/command_summarize.png +0 -0
- data/img/commands_inline.png +0 -0
- data/img/commands_on_demand.png +0 -0
- data/img/commands_on_external_call.png +0 -0
- data/img/image_editing.png +0 -0
- data/img/image_generation.png +0 -0
- data/img/image_variations.png +0 -0
- data/img/openai-300.png +0 -0
- data/img/openai.png +0 -0
- data/img/slack-300.png +0 -0
- data/img/slack.png +0 -0
- data/img/smart-bot-150.png +0 -0
- data/img/smart-bot-profile-pic-2.png +0 -0
- data/img/smart-bot-profile-pic.png +0 -0
- data/img/smart-bot.png +0 -0
- data/img/whisper.png +0 -0
- data/lib/slack/smart-bot/ai/open_ai/connect.rb +165 -43
- data/lib/slack/smart-bot/ai/open_ai/models.rb +61 -9
- data/lib/slack/smart-bot/ai/open_ai/send_gpt_chat.rb +67 -11
- data/lib/slack/smart-bot/ai/open_ai/send_image_edit.rb +4 -3
- data/lib/slack/smart-bot/ai/open_ai/send_image_generation.rb +4 -4
- data/lib/slack/smart-bot/ai/open_ai/send_image_variation.rb +4 -3
- data/lib/slack/smart-bot/ai/open_ai/whisper_transcribe.rb +4 -3
- data/lib/slack/smart-bot/comm/ask.rb +20 -8
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +30 -1
- data/lib/slack/smart-bot/comm/get_channel_members.rb +2 -1
- data/lib/slack/smart-bot/comm/get_presence.rb +1 -0
- data/lib/slack/smart-bot/comm/get_smartbot_team_info.rb +10 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +45 -6
- data/lib/slack/smart-bot/comm/get_users.rb +8 -1
- data/lib/slack/smart-bot/comm/respond.rb +225 -196
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
- data/lib/slack/smart-bot/comm/send_msg_user.rb +10 -9
- data/lib/slack/smart-bot/comm/unreact.rb +2 -2
- data/lib/slack/smart-bot/comm.rb +1 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +16 -6
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +3 -3
- data/lib/slack/smart-bot/commands/general/add_vacation.rb +28 -12
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb +272 -23
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_add_collaborator.rb +42 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_copy_session.rb +89 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_delete_session.rb +45 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_get_prompts.rb +41 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_list_sessions.rb +81 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_share_session.rb +52 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat_use_model.rb +52 -0
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_edit_image.rb +14 -11
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_generate_image.rb +15 -11
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_models.rb +29 -17
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_variations_image.rb +16 -13
- data/lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_whisper.rb +13 -7
- data/lib/slack/smart-bot/commands/general/allow_access.rb +8 -4
- data/lib/slack/smart-bot/commands/general/bot_help.rb +24 -10
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +9 -5
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +2 -1
- data/lib/slack/smart-bot/commands/general/delete_share.rb +2 -1
- data/lib/slack/smart-bot/commands/general/deny_access.rb +1 -1
- data/lib/slack/smart-bot/commands/general/get_smartbot_readme.rb +15 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +10 -4
- data/lib/slack/smart-bot/commands/general/personal_settings.rb +26 -8
- data/lib/slack/smart-bot/commands/general/poster.rb +26 -2
- data/lib/slack/smart-bot/commands/general/public_holidays.rb +14 -24
- data/lib/slack/smart-bot/commands/general/recap.rb +399 -0
- data/lib/slack/smart-bot/commands/general/remove_admin.rb +19 -9
- data/lib/slack/smart-bot/commands/general/remove_vacation.rb +23 -6
- data/lib/slack/smart-bot/commands/general/see_access.rb +2 -1
- data/lib/slack/smart-bot/commands/general/see_admins.rb +8 -4
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +5 -5
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +4 -4
- data/lib/slack/smart-bot/commands/general/see_shares.rb +1 -1
- data/lib/slack/smart-bot/commands/general/see_vacations.rb +34 -17
- data/lib/slack/smart-bot/commands/general/set_public_holidays.rb +4 -2
- data/lib/slack/smart-bot/commands/general/share_messages.rb +3 -3
- data/lib/slack/smart-bot/commands/general/summarize.rb +191 -0
- data/lib/slack/smart-bot/commands/general/teams/add_team.rb +4 -8
- data/lib/slack/smart-bot/commands/general/teams/delete_team.rb +3 -3
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team.rb +34 -29
- data/lib/slack/smart-bot/commands/general/teams/memos/add_memo_team_comment.rb +1 -1
- data/lib/slack/smart-bot/commands/general/teams/memos/delete_memo_team.rb +6 -4
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memo_team.rb +26 -15
- data/lib/slack/smart-bot/commands/general/teams/memos/see_memos_team.rb +33 -24
- data/lib/slack/smart-bot/commands/general/teams/memos/set_memo_status.rb +4 -4
- data/lib/slack/smart-bot/commands/general/teams/ping_team.rb +10 -8
- data/lib/slack/smart-bot/commands/general/teams/see_teams.rb +73 -61
- data/lib/slack/smart-bot/commands/general/teams/see_vacations_team.rb +28 -13
- data/lib/slack/smart-bot/commands/general/teams/update_team.rb +9 -9
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +1152 -839
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +18 -17
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +11 -9
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +5 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +7 -6
- data/lib/slack/smart-bot/commands/on_bot/admin_master/update_message.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +21 -20
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +40 -7
- data/lib/slack/smart-bot/commands/on_bot/general/bot_status.rb +6 -2
- data/lib/slack/smart-bot/commands/on_bot/general/stop_using_rules.rb +7 -6
- data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +5 -4
- data/lib/slack/smart-bot/commands/on_bot/general/use_rules.rb +4 -3
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -4
- data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +109 -53
- data/lib/slack/smart-bot/commands/on_bot/repl_client.rb +35 -29
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -5
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -2
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -4
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +22 -12
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +12 -7
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -2
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +1 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +5 -5
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +5 -5
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +3 -3
- data/lib/slack/smart-bot/commands.rb +10 -0
- data/lib/slack/smart-bot/config.rb +126 -0
- data/lib/slack/smart-bot/listen.rb +12 -11
- data/lib/slack/smart-bot/process.rb +62 -55
- data/lib/slack/smart-bot/process_first.rb +106 -65
- data/lib/slack/smart-bot/treat_message.rb +79 -47
- data/lib/slack/smart-bot/utils/answer.rb +11 -3
- data/lib/slack/smart-bot/utils/answer_delete.rb +11 -3
- data/lib/slack/smart-bot/utils/check_vacations.rb +21 -3
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +13 -13
- data/lib/slack/smart-bot/utils/display_calendar.rb +42 -8
- data/lib/slack/smart-bot/utils/encryption/decrypt.rb +16 -9
- data/lib/slack/smart-bot/utils/encryption/encrypt.rb +14 -11
- data/lib/slack/smart-bot/utils/find_user.rb +71 -0
- data/lib/slack/smart-bot/utils/get_access_channels.rb +22 -3
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +3 -4
- data/lib/slack/smart-bot/utils/get_command_ids.rb +5 -5
- data/lib/slack/smart-bot/utils/get_countries_candelarific.rb +18 -0
- data/lib/slack/smart-bot/utils/get_help.rb +21 -19
- data/lib/slack/smart-bot/utils/get_openai_sessions.rb +47 -0
- data/lib/slack/smart-bot/utils/get_personal_settings.rb +29 -3
- data/lib/slack/smart-bot/utils/get_rules_imported.rb +27 -6
- data/lib/slack/smart-bot/utils/get_shares.rb +1 -1
- data/lib/slack/smart-bot/utils/get_team_members.rb +4 -4
- data/lib/slack/smart-bot/utils/get_vacations.rb +15 -7
- data/lib/slack/smart-bot/utils/has_access.rb +10 -4
- data/lib/slack/smart-bot/utils/is_admin.rb +25 -17
- data/lib/slack/smart-bot/utils/local_time.rb +29 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +5 -3
- data/lib/slack/smart-bot/utils/update_access_channels.rb +19 -3
- data/lib/slack/smart-bot/utils/update_openai_sessions.rb +42 -0
- data/lib/slack/smart-bot/utils/update_personal_settings.rb +11 -3
- data/lib/slack/smart-bot/utils/update_rules_imported.rb +18 -3
- data/lib/slack/smart-bot/utils/update_vacations.rb +5 -2
- data/lib/slack/smart-bot/utils/upgrade_to_use_team_ids.rb +276 -0
- data/lib/slack/smart-bot/utils.rb +6 -1
- data/lib/slack-smart-bot.rb +182 -76
- data/lib/slack-smart-bot_general_commands.rb +10 -9
- data/whats_new.txt +30 -13
- metadata +148 -20
@@ -26,73 +26,74 @@ class SlackSmartBot
|
|
26
26
|
save_stats(__method__)
|
27
27
|
unless typem == :on_extended
|
28
28
|
from = user.name
|
29
|
+
team_id_user = user.team_id + '_' + from
|
29
30
|
if has_access?(__method__, user)
|
30
31
|
shortcut_name.strip!
|
31
|
-
if global
|
32
|
+
if global
|
32
33
|
if !config.on_master_bot or typem != :on_master
|
33
34
|
respond "It is only possible to add global shortcuts from Master channel"
|
34
35
|
else
|
35
|
-
@shortcuts_global[
|
36
|
+
@shortcuts_global[team_id_user] = Hash.new() unless @shortcuts_global.keys.include?(team_id_user)
|
36
37
|
found_other = false
|
37
38
|
if for_all.to_s != ""
|
38
39
|
@shortcuts_global.each { |sck, scv|
|
39
|
-
if sck != :all and sck !=
|
40
|
+
if sck != :all and sck != team_id_user and scv.key?(shortcut_name)
|
40
41
|
found_other = true
|
41
42
|
end
|
42
43
|
}
|
43
44
|
end
|
44
|
-
if @shortcuts_global[:all].include?(shortcut_name) or @shortcuts_global[
|
45
|
+
if @shortcuts_global[:all].include?(shortcut_name) or @shortcuts_global[team_id_user].include?(shortcut_name)
|
45
46
|
respond "Global shortcut name already in use. Please use another shortcut name."
|
46
47
|
elsif found_other
|
47
48
|
respond "You cannot create a global shortcut for all with the same name than other user is using."
|
48
|
-
elsif !@shortcuts_global[
|
49
|
+
elsif !@shortcuts_global[team_id_user].include?(shortcut_name)
|
49
50
|
#new shortcut
|
50
|
-
@shortcuts_global[
|
51
|
+
@shortcuts_global[team_id_user][shortcut_name] = command_to_run
|
51
52
|
@shortcuts_global[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
52
53
|
update_shortcuts_file()
|
53
54
|
respond "global shortcut added"
|
54
55
|
else
|
55
56
|
respond "Not possible to add the global shortcut" #todo: check if this is ever gonna be the case
|
56
|
-
end
|
57
|
+
end
|
57
58
|
end
|
58
59
|
else
|
59
|
-
@shortcuts[
|
60
|
+
@shortcuts[team_id_user] = Hash.new() unless @shortcuts.keys.include?(team_id_user)
|
60
61
|
|
61
62
|
found_other = false
|
62
63
|
if for_all.to_s != ""
|
63
64
|
@shortcuts.each { |sck, scv|
|
64
|
-
if sck != :all and sck !=
|
65
|
+
if sck != :all and sck != team_id_user and scv.key?(shortcut_name)
|
65
66
|
found_other = true
|
66
67
|
end
|
67
68
|
}
|
68
69
|
end
|
69
|
-
if !is_admin?(
|
70
|
+
if !is_admin?(user) and @shortcuts[:all].include?(shortcut_name) and !@shortcuts[team_id_user].include?(shortcut_name)
|
70
71
|
respond "Only the creator of the shortcut can modify it", dest
|
71
72
|
elsif found_other
|
72
73
|
respond "You cannot create a shortcut for all with the same name than other user is using", dest
|
73
|
-
elsif !@shortcuts[
|
74
|
+
elsif !@shortcuts[team_id_user].include?(shortcut_name)
|
74
75
|
#new shortcut
|
75
|
-
@shortcuts[
|
76
|
+
@shortcuts[team_id_user][shortcut_name] = command_to_run
|
76
77
|
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
77
78
|
update_shortcuts_file()
|
78
79
|
respond "shortcut added", dest
|
79
80
|
else
|
80
81
|
#are you sure? to avoid overwriting existing
|
81
82
|
if answer.empty?
|
82
|
-
ask("The shortcut already exists, are you sure you want to overwrite it?", command,
|
83
|
+
ask("The shortcut already exists, are you sure you want to overwrite it?", command, team_id_user, dest)
|
83
84
|
else
|
84
85
|
case answer
|
85
86
|
when /^(yes|yep)/i
|
86
|
-
@shortcuts[
|
87
|
+
@shortcuts[team_id_user][shortcut_name] = command_to_run
|
87
88
|
@shortcuts[:all][shortcut_name] = command_to_run if for_all.to_s != ""
|
88
89
|
update_shortcuts_file()
|
89
90
|
respond "shortcut added", dest
|
90
|
-
answer_delete(
|
91
|
+
answer_delete(team_id_user)
|
91
92
|
when /^no/i
|
92
93
|
respond "ok, I won't add it", dest
|
93
|
-
answer_delete(
|
94
|
+
answer_delete(team_id_user)
|
94
95
|
else
|
95
|
-
ask "I don't understand, yes or no?", command,
|
96
|
+
ask "I don't understand, yes or no?", command, team_id_user, dest
|
96
97
|
end
|
97
98
|
end
|
98
99
|
end
|
@@ -42,11 +42,12 @@ class SlackSmartBot
|
|
42
42
|
# helpadmin:
|
43
43
|
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel, routine_type)
|
44
44
|
save_stats(__method__)
|
45
|
-
if files.nil? or files.size == 0 or (files.size > 0 and config.
|
45
|
+
if files.nil? or files.size == 0 or (files.size > 0 and config.team_id_masters.include?("#{user.team_id}_#{user.name}"))
|
46
46
|
if is_admin?
|
47
47
|
if @routines.key?(@channel_id) && @routines[@channel_id].key?(name)
|
48
48
|
respond "I'm sorry but there is already a routine with that name.\nCall `see routines` to see added routines", dest
|
49
49
|
else
|
50
|
+
react :running
|
50
51
|
number_time += ":00" if number_time.split(":").size == 2
|
51
52
|
if (type != "every") && !number_time.match?(/^[01][0-9]:[0-5][0-9]:[0-5][0-9]$/) &&
|
52
53
|
!number_time.match?(/^2[0-3]:[0-5][0-9]:[0-5][0-9]$/)
|
@@ -91,14 +92,14 @@ class SlackSmartBot
|
|
91
92
|
next_time = Date.new(next_month.year, next_month.month, day)
|
92
93
|
end
|
93
94
|
days = (next_time - Date.today).to_i
|
94
|
-
every_in_seconds = days * 24 * 60 * 60 # one day
|
95
|
-
|
95
|
+
every_in_seconds = days * 24 * 60 * 60 # one day
|
96
|
+
|
96
97
|
elsif type != 'at' and type!='weekday' and type!='weekend'
|
97
98
|
dayweek = type.downcase
|
98
99
|
|
99
100
|
days = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday']
|
100
101
|
incr = days.index(dayweek) - Time.now.wday
|
101
|
-
if incr < 0
|
102
|
+
if incr < 0
|
102
103
|
incr = (7+incr)*24*60*60
|
103
104
|
else
|
104
105
|
incr = incr * 24 * 60 * 60
|
@@ -137,7 +138,7 @@ class SlackSmartBot
|
|
137
138
|
file_path += ".rb"
|
138
139
|
end
|
139
140
|
if files[0].key?(:content)
|
140
|
-
File.open(file_path, 'w') do |f|
|
141
|
+
File.open(file_path, 'w') do |f|
|
141
142
|
f.write files[0].content
|
142
143
|
end
|
143
144
|
else
|
@@ -154,18 +155,19 @@ class SlackSmartBot
|
|
154
155
|
elsif @channels_id.key?(channel) #it is a channel name
|
155
156
|
channel_id = @channels_id[channel]
|
156
157
|
end
|
157
|
-
|
158
|
+
|
158
159
|
channel_id = dest if channel_id.to_s == ''
|
159
160
|
@routines[@channel_id] = {} unless @routines.key?(@channel_id)
|
160
|
-
@routines[@channel_id][name] = { channel_name: config.channel, creator: from, creator_id: user.id, status: :on,
|
161
|
-
every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, daymonth: daymonth, file_path: file_path,
|
161
|
+
@routines[@channel_id][name] = { channel_name: config.channel, creator_team_id: user.team_id, creator: from, creator_id: user.id, status: :on,
|
162
|
+
every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, daymonth: daymonth, file_path: file_path,
|
162
163
|
command: command_to_run.to_s.strip, silent: silent,
|
163
|
-
next_run: next_run.to_s, dest: channel_id, last_run: "", last_elapsed: "",
|
164
|
+
next_run: next_run.to_s, dest: channel_id, last_run: "", last_elapsed: "",
|
164
165
|
running: false, routine_type: routine_type}
|
165
166
|
update_routines()
|
166
167
|
respond "Added routine *`#{name}`* to the channel", dest
|
167
168
|
create_routine_thread(name, @routines[@channel_id][name])
|
168
169
|
end
|
170
|
+
unreact :running
|
169
171
|
end
|
170
172
|
else
|
171
173
|
respond "Only admin users can use this command", dest
|
@@ -16,10 +16,12 @@ class SlackSmartBot
|
|
16
16
|
save_stats(__method__)
|
17
17
|
if is_admin?
|
18
18
|
if @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
|
19
|
+
react :running
|
19
20
|
@routines[@channel_id][name][:thread].exit
|
20
21
|
@routines[@channel_id].delete(name)
|
21
22
|
update_routines()
|
22
23
|
respond "The routine *`#{name}`* has been removed.", dest
|
24
|
+
unreact :running
|
23
25
|
else
|
24
26
|
respond "There isn't a routine with that name: *`#{name}`*.\nCall `see routines` to see added routines", dest
|
25
27
|
end
|
@@ -42,6 +42,7 @@ class SlackSmartBot
|
|
42
42
|
started = Time.now
|
43
43
|
data = { channel: @routines[@channel_id][name][:dest],
|
44
44
|
user: @routines[@channel_id][name][:creator_id],
|
45
|
+
team_id: @routines[@channel_id][name][:creator_team_id],
|
45
46
|
text: @routines[@channel_id][name][:command],
|
46
47
|
files: nil,
|
47
48
|
routine_name: name,
|
@@ -14,6 +14,7 @@ class SlackSmartBot
|
|
14
14
|
def see_routines(dest, from, user, all, header, regexp)
|
15
15
|
save_stats(__method__)
|
16
16
|
if is_admin?
|
17
|
+
react :running
|
17
18
|
if all
|
18
19
|
routines = {}
|
19
20
|
if config.on_master_bot
|
@@ -28,8 +29,8 @@ class SlackSmartBot
|
|
28
29
|
routines = @routines
|
29
30
|
end
|
30
31
|
else
|
31
|
-
if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name) and dest[0] == "D"
|
32
|
-
routines = YAML.load(File.read("#{config.path}/routines/routines_#{@rules_imported[user.name][user.name]}.yaml"))
|
32
|
+
if @rules_imported.key?("#{user.team_id}_#{user.name}") and @rules_imported["#{user.team_id}_#{user.name}"].key?(user.name) and dest[0] == "D"
|
33
|
+
routines = YAML.load(File.read("#{config.path}/routines/routines_#{@rules_imported["#{user.team_id}_#{user.name}"][user.name]}.yaml"))
|
33
34
|
routines = {} if routines.is_a?(FalseClass)
|
34
35
|
else
|
35
36
|
routines = @routines
|
@@ -81,7 +82,7 @@ class SlackSmartBot
|
|
81
82
|
msg << "\tStatus: #{v[:status]}"
|
82
83
|
msg << "\tEvery: #{v[:every]}" unless v[:every] == ""
|
83
84
|
msg << "\tAt: #{v[:at]}" unless v[:at] == ""
|
84
|
-
msg << "\tOn: #{v[:dayweek]}" unless !v.key?(:dayweek) or v[:dayweek].to_s == ""
|
85
|
+
msg << "\tOn: #{v[:dayweek]}" unless !v.key?(:dayweek) or v[:dayweek].to_s == ""
|
85
86
|
msg << "\tNext Run: #{v[:next_run]}"
|
86
87
|
msg << "\tLast Run: #{v[:last_run]}"
|
87
88
|
msg << "\tTime consumed on last run: #{v[:last_elapsed]}" unless v[:command] !=''
|
@@ -93,6 +94,7 @@ class SlackSmartBot
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
end
|
97
|
+
unreact :running
|
96
98
|
else
|
97
99
|
respond "Only admin users can use this command", dest
|
98
100
|
end
|
@@ -6,10 +6,10 @@ class SlackSmartBot
|
|
6
6
|
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
7
7
|
# helpadmin: command_id: :delete_message
|
8
8
|
# helpadmin:
|
9
|
-
def delete_message(
|
9
|
+
def delete_message(user, typem, url)
|
10
10
|
save_stats(__method__)
|
11
11
|
channel, ts = url.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
|
12
|
-
if config.
|
12
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") and typem==:on_dm and !channel.nil? #master admin user
|
13
13
|
ts = "#{ts[0..-7]}.#{ts[-6..-1]}"
|
14
14
|
succ = delete(channel, ts)
|
15
15
|
if succ
|
@@ -22,4 +22,3 @@ class SlackSmartBot
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
@@ -6,9 +6,9 @@ class SlackSmartBot
|
|
6
6
|
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
7
7
|
# helpadmin: command_id: :get_bot_logs
|
8
8
|
# helpadmin:
|
9
|
-
def get_bot_logs(dest,
|
9
|
+
def get_bot_logs(dest, user, typem)
|
10
10
|
save_stats(__method__)
|
11
|
-
if config.
|
11
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") and typem==:on_dm #master admin user
|
12
12
|
respond 'Remember this data is private'
|
13
13
|
send_file(dest, "Logs for #{config.channel}", "#{config.path}/logs/#{config.log_file}", 'Remember this data is private', 'text/plain', "text")
|
14
14
|
else
|
@@ -16,4 +16,3 @@ class SlackSmartBot
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
@@ -11,9 +11,9 @@ class SlackSmartBot
|
|
11
11
|
# helpadmin: _react to #sales p1622550707012100 :thumbsup: :heavy_check_mark: :bathtub:_
|
12
12
|
# helpadmin: command_id: :react_to
|
13
13
|
# helpadmin:
|
14
|
-
def react_to(dest,
|
14
|
+
def react_to(dest, user, typem, to, thread_ts, emojis)
|
15
15
|
save_stats(__method__)
|
16
|
-
if config.
|
16
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") and typem==:on_dm #master admin user
|
17
17
|
succs = []
|
18
18
|
emojis.split(' ').each do |emoji|
|
19
19
|
succs << (react emoji, thread_ts, to)
|
@@ -31,4 +31,3 @@ class SlackSmartBot
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
@@ -13,9 +13,9 @@ class SlackSmartBot
|
|
13
13
|
# helpadmin: In case from and to specified will send a DM to all users that have been using the SmartBot according to the SmartBot Stats. One message every 5sc. #CHANNEL and COMMAND_ID are optional filters.
|
14
14
|
# helpadmin: command_id: :send_message
|
15
15
|
# helpadmin:
|
16
|
-
def send_message(dest,
|
16
|
+
def send_message(dest, user, typem, to, thread_ts, stats_from, stats_to, stats_channel_filter, stats_command_filter, message)
|
17
17
|
save_stats(__method__)
|
18
|
-
if config.
|
18
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") and typem==:on_dm #master admin user
|
19
19
|
react :runner
|
20
20
|
unless Thread.current[:command_orig].to_s == ''
|
21
21
|
message_orig = Thread.current[:command_orig].to_s.gsub("\u00A0", " ").scan(/[^:]+\s*:\s+(.+)/im).join
|
@@ -32,13 +32,13 @@ class SlackSmartBot
|
|
32
32
|
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
33
33
|
if file >= "#{config.stats_path}.#{stats_from[0..6]}.log" and file <= "#{config.stats_path}.#{stats_to[0..6]}.log"
|
34
34
|
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
35
|
-
if row[:date] >= stats_from and row[:date] <= stats_to and !users.include?(row[:user_name])
|
35
|
+
if row[:date] >= stats_from and row[:date] <= stats_to and !users.include?(row[:user_name])
|
36
36
|
if (stats_channel_filter=='' and stats_command_filter=='') or
|
37
37
|
(stats_channel_filter!='' and stats_command_filter=='' and (row[:bot_channel_id]==stats_channel_filter or row[:dest_channel_id]==stats_channel_filter)) or
|
38
|
-
(stats_command_filter!='' and stats_channel_filter=='' and row[:command]==stats_command_filter) or
|
38
|
+
(stats_command_filter!='' and stats_channel_filter=='' and row[:command]==stats_command_filter) or
|
39
39
|
(stats_channel_filter!='' and stats_command_filter!='' and ((row[:bot_channel_id]==stats_channel_filter or row[:dest_channel_id]==stats_channel_filter) and row[:command]==stats_command_filter))
|
40
40
|
|
41
|
-
user_ids << row[:user_id]
|
41
|
+
user_ids << row[:user_id]
|
42
42
|
users << row[:user_name]
|
43
43
|
end
|
44
44
|
end
|
@@ -50,6 +50,7 @@ class SlackSmartBot
|
|
50
50
|
users_failed = []
|
51
51
|
|
52
52
|
user_ids.each do |u|
|
53
|
+
@buffered = false if config.testing
|
53
54
|
succ = (respond message, u, thread_ts: thread_ts, web_client: true)
|
54
55
|
if succ
|
55
56
|
users_success << u
|
@@ -65,6 +66,7 @@ class SlackSmartBot
|
|
65
66
|
else
|
66
67
|
to.each do |t|
|
67
68
|
unless t.match?(/^\s*$/)
|
69
|
+
@buffered = false if config.testing
|
68
70
|
succ = (respond message, t, thread_ts: thread_ts, web_client: true) && succ
|
69
71
|
end
|
70
72
|
end
|
@@ -80,4 +82,3 @@ class SlackSmartBot
|
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
83
|
-
|
@@ -6,10 +6,10 @@ class SlackSmartBot
|
|
6
6
|
# helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
7
7
|
# helpadmin: command_id: :update_message
|
8
8
|
# helpadmin:
|
9
|
-
def update_message(
|
9
|
+
def update_message(user, typem, url, text)
|
10
10
|
save_stats(__method__)
|
11
11
|
channel, ts = url.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
|
12
|
-
if config.
|
12
|
+
if config.team_id_masters.include?("#{user.team_id}_#{user.name}") and typem==:on_dm and !channel.nil? #master admin user
|
13
13
|
ts = "#{ts[0..-7]}.#{ts[-6..-1]}"
|
14
14
|
succ = update(channel, ts, text)
|
15
15
|
if succ
|
@@ -22,4 +22,3 @@ class SlackSmartBot
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
@@ -14,7 +14,7 @@ class SlackSmartBot
|
|
14
14
|
if has_access?(__method__, user)
|
15
15
|
if @repls.key?(session_name)
|
16
16
|
Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
|
17
|
-
if is_admin?(user
|
17
|
+
if is_admin?(user) or (@repls[session_name].creator_name == user.name and @repls[session_name].creator_team_id == user.team_id)
|
18
18
|
@repls.delete(session_name)
|
19
19
|
update_repls()
|
20
20
|
File.rename("#{config.path}/repl/#{@channel_id}/#{session_name}.input", "#{config.path}/repl/#{@channel_id}/#{session_name}_#{Time.now.strftime("%Y%m%d%H%M%S%N")}.deleted")
|
@@ -13,26 +13,27 @@ class SlackSmartBot
|
|
13
13
|
save_stats(__method__)
|
14
14
|
unless typem == :on_extended
|
15
15
|
from = user.name
|
16
|
+
team_id_user = user.team_id + '_' + from
|
16
17
|
if has_access?(__method__, user)
|
17
|
-
deleted = false
|
18
|
+
deleted = false
|
18
19
|
shortcut.strip!
|
19
20
|
if global
|
20
21
|
if !config.on_master_bot or typem != :on_master
|
21
22
|
respond "It is only possible to delete global shortcuts from Master channel"
|
22
23
|
else
|
23
|
-
if !is_admin?(
|
24
|
-
(!@shortcuts_global.key?(
|
24
|
+
if !is_admin?(user) and @shortcuts_global[:all].include?(shortcut) and
|
25
|
+
(!@shortcuts_global.key?(team_id_user) or !@shortcuts_global[team_id_user].include?(shortcut))
|
25
26
|
respond "Only the creator of the shortcut or an admin user can delete it"
|
26
|
-
elsif (@shortcuts_global.key?(
|
27
|
-
(is_admin?(
|
28
|
-
|
27
|
+
elsif (@shortcuts_global.key?(team_id_user) and @shortcuts_global[team_id_user].keys.include?(shortcut)) or
|
28
|
+
(is_admin?(user) and @shortcuts_global[:all].include?(shortcut))
|
29
|
+
|
29
30
|
respond "global shortcut deleted!", dest
|
30
|
-
if @shortcuts_global.key?(
|
31
|
-
respond("#{shortcut}: #{@shortcuts_global[
|
31
|
+
if @shortcuts_global.key?(team_id_user) and @shortcuts_global[team_id_user].key?(shortcut)
|
32
|
+
respond("#{shortcut}: #{@shortcuts_global[team_id_user][shortcut]}", dest)
|
32
33
|
elsif @shortcuts_global.key?(:all) and @shortcuts_global[:all].key?(shortcut)
|
33
34
|
respond("#{shortcut}: #{@shortcuts_global[:all][shortcut]}", dest)
|
34
35
|
end
|
35
|
-
@shortcuts_global[
|
36
|
+
@shortcuts_global[team_id_user].delete(shortcut) if @shortcuts_global.key?(team_id_user) and @shortcuts_global[team_id_user].key?(shortcut)
|
36
37
|
@shortcuts_global[:all].delete(shortcut) if @shortcuts_global.key?(:all) and @shortcuts_global[:all].key?(shortcut)
|
37
38
|
update_shortcuts_file()
|
38
39
|
else
|
@@ -40,32 +41,32 @@ class SlackSmartBot
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
else
|
43
|
-
if !is_admin?(
|
44
|
-
(!@shortcuts.key?(
|
44
|
+
if !is_admin?(user) and @shortcuts[:all].include?(shortcut) and
|
45
|
+
(!@shortcuts.key?(team_id_user) or !@shortcuts[team_id_user].include?(shortcut))
|
45
46
|
respond "Only the creator of the shortcut or an admin user can delete it", dest
|
46
|
-
elsif (@shortcuts.keys.include?(
|
47
|
-
(is_admin?(
|
47
|
+
elsif (@shortcuts.keys.include?(team_id_user) and @shortcuts[team_id_user].keys.include?(shortcut)) or
|
48
|
+
(is_admin?(user) and @shortcuts[:all].include?(shortcut))
|
48
49
|
#are you sure? to avoid deleting by mistake
|
49
50
|
if answer.empty?
|
50
|
-
ask("are you sure you want to delete it?", command,
|
51
|
+
ask("are you sure you want to delete it?", command, team_id_user, dest)
|
51
52
|
else
|
52
53
|
case answer
|
53
54
|
when /^(yes|yep)/i
|
54
|
-
answer_delete(
|
55
|
+
answer_delete(team_id_user)
|
55
56
|
respond "shortcut deleted!", dest
|
56
|
-
if @shortcuts.key?(
|
57
|
-
respond("#{shortcut}: #{@shortcuts[
|
57
|
+
if @shortcuts.key?(team_id_user) and @shortcuts[team_id_user].key?(shortcut)
|
58
|
+
respond("#{shortcut}: #{@shortcuts[team_id_user][shortcut]}", dest)
|
58
59
|
elsif @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
|
59
60
|
respond("#{shortcut}: #{@shortcuts[:all][shortcut]}", dest)
|
60
61
|
end
|
61
|
-
@shortcuts[
|
62
|
+
@shortcuts[team_id_user].delete(shortcut) if @shortcuts.key?(team_id_user) and @shortcuts[team_id_user].key?(shortcut)
|
62
63
|
@shortcuts[:all].delete(shortcut) if @shortcuts.key?(:all) and @shortcuts[:all].key?(shortcut)
|
63
64
|
update_shortcuts_file()
|
64
65
|
when /^no/i
|
65
|
-
answer_delete(
|
66
|
+
answer_delete(team_id_user)
|
66
67
|
respond "ok, I won't delete it", dest
|
67
68
|
else
|
68
|
-
ask("I don't understand, are you sure you want to delete it? (yes or no)", command,
|
69
|
+
ask("I don't understand, are you sure you want to delete it? (yes or no)", command, team_id_user, dest)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
else
|
@@ -62,7 +62,7 @@ class SlackSmartBot
|
|
62
62
|
user = "" # for the case we are on the stats channel
|
63
63
|
end
|
64
64
|
if (from_user.id != user and
|
65
|
-
(config.
|
65
|
+
(config.team_id_masters.include?("#{from_user.team_id}_#{from_user.name}") or master_admin_users_id.include?(from_user.id) or dest == @channels_id[config.stats_channel]) and
|
66
66
|
(typem == :on_dm or dest[0] == "D" or dest == @channels_id[config.stats_channel]))
|
67
67
|
on_dm_master = true #master admin user
|
68
68
|
else
|
@@ -88,14 +88,14 @@ class SlackSmartBot
|
|
88
88
|
wrong = true
|
89
89
|
else
|
90
90
|
tm.each do |m|
|
91
|
-
user_info =
|
91
|
+
user_info = find_user(m)
|
92
92
|
members_list << user_info.name unless user_info.is_app_user or user_info.is_bot
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
if header.size > 0
|
98
|
-
headers = ["date", "bot_channel", "bot_channel_id", "dest_channel", "dest_channel_id", "type_message", "user_name", "user_id", "text", "command", "files", "time_zone", "job_title"]
|
98
|
+
headers = ["date", "bot_channel", "bot_channel_id", "dest_channel", "dest_channel_id", "type_message", "user_name", "user_id", "text", "command", "files", "time_zone", "job_title", "team_id"]
|
99
99
|
header.each do |h|
|
100
100
|
if !headers.include?(h.downcase)
|
101
101
|
message << ":exclamation: Wrong header #{h}. It should be one of the following: #{headers.join(", ")}"
|
@@ -117,6 +117,8 @@ class SlackSmartBot
|
|
117
117
|
tzone_users = {}
|
118
118
|
job_title_users = {}
|
119
119
|
users_by_job_title = {}
|
120
|
+
users_by_team = {}
|
121
|
+
total_calls_by_team = {}
|
120
122
|
unless wrong
|
121
123
|
type_group = :monthly if only_graph and type_group == ""
|
122
124
|
if on_dm_master or (from_user.id == user) # normal user can only see own stats
|
@@ -163,7 +165,7 @@ class SlackSmartBot
|
|
163
165
|
end
|
164
166
|
#end
|
165
167
|
if user != ""
|
166
|
-
user_info =
|
168
|
+
user_info = find_user(user)
|
167
169
|
if user_info.nil? # for the case the user is populated from outside of slack
|
168
170
|
user_name = user
|
169
171
|
user_id = user
|
@@ -197,6 +199,7 @@ class SlackSmartBot
|
|
197
199
|
(exclude_channel_members and !members_list.include?(row[:user_name])) or
|
198
200
|
(!include_channel_members and !exclude_channel_members)
|
199
201
|
row[:date] = row[:date].to_s
|
202
|
+
row[:team_id] = config.team_id if row[:team_id].to_s == ''
|
200
203
|
if row[:dest_channel_id].to_s[0] == "D"
|
201
204
|
row[:dest_channel] = "DM"
|
202
205
|
elsif row[:dest_channel].to_s == ""
|
@@ -217,7 +220,7 @@ class SlackSmartBot
|
|
217
220
|
header.each_with_index do |h, i|
|
218
221
|
if !row[h.downcase.to_sym].to_s.match?(/#{regexp[i]}/i)
|
219
222
|
add = false
|
220
|
-
break
|
223
|
+
break
|
221
224
|
end
|
222
225
|
end
|
223
226
|
end
|
@@ -367,6 +370,35 @@ class SlackSmartBot
|
|
367
370
|
end
|
368
371
|
end
|
369
372
|
|
373
|
+
team_ids = rows.team_id.uniq
|
374
|
+
client_web = Slack::Web::Client.new(token: config.token)
|
375
|
+
client_web.auth_test
|
376
|
+
team_ids.each do |team_id|
|
377
|
+
resp = client_web.team_info(team: team_id)
|
378
|
+
team_name = resp.team.name
|
379
|
+
users_by_team[team_name] ||= []
|
380
|
+
users_by_team[team_name] += rows.select { |h| h.team_id == team_id }.map { |h| h.user_id }.uniq
|
381
|
+
total_calls_by_team[team_name] ||= 0
|
382
|
+
total_calls_by_team[team_name] += rows.count { |h| h.team_id == team_id }
|
383
|
+
end
|
384
|
+
client_web = nil
|
385
|
+
|
386
|
+
#print users by team
|
387
|
+
if users_by_team.size > 0
|
388
|
+
message << "*Users by Space*"
|
389
|
+
users_by_team.each do |team_name, users|
|
390
|
+
message << "\t#{team_name}: #{users.size} (#{(users.size.to_f * 100 / users_id_name.size).round(2)}%)"
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
#print total calls by user team
|
395
|
+
if total_calls_by_team.size > 0
|
396
|
+
message << "*Total calls by User Space*"
|
397
|
+
total_calls_by_team.each do |team_name, total_calls|
|
398
|
+
message << "\t#{team_name}: #{total_calls} (#{(total_calls.to_f * 100 / total).round(2)}%)"
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
370
402
|
if !only_graph
|
371
403
|
users_attachment = []
|
372
404
|
if user == ""
|
@@ -386,7 +418,7 @@ class SlackSmartBot
|
|
386
418
|
tzone_users[rows[i].values[11]] += 1
|
387
419
|
end
|
388
420
|
else
|
389
|
-
user_info =
|
421
|
+
user_info = find_user(usr)
|
390
422
|
unless user_info.nil? or user_info.is_app_user or user_info.is_bot
|
391
423
|
tzone_users[user_info.tz_label] ||= 0
|
392
424
|
tzone_users[user_info.tz_label] += 1
|
@@ -422,7 +454,7 @@ class SlackSmartBot
|
|
422
454
|
users_by_job_title[job_title] << rows.user_name[i]
|
423
455
|
end
|
424
456
|
else
|
425
|
-
user_info =
|
457
|
+
user_info = find_user(usr)
|
426
458
|
unless user_info.nil? or user_info.is_app_user or user_info.is_bot
|
427
459
|
if job_title_users.key?(user_info.profile.title)
|
428
460
|
job_title = user_info.profile.title
|
@@ -443,6 +475,7 @@ class SlackSmartBot
|
|
443
475
|
users_by_job_title.each do |job_title, users|
|
444
476
|
users.uniq!
|
445
477
|
end
|
478
|
+
|
446
479
|
if users.size > 10
|
447
480
|
message << "*Users* - #{users.size} (Top 10)"
|
448
481
|
else
|
@@ -20,8 +20,12 @@ class SlackSmartBot
|
|
20
20
|
ip_address = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
|
21
21
|
respond "*#{Socket.gethostname} (#{ip_address})*\n\tStatus: #{@status}.\n\tVersion: #{VERSION}.#{version_message}\n\tRules file: #{File.basename config.rules_file}\n\tExtended: #{@bots_created[@channel_id][:extended] unless config.on_master_bot}\n\tAdmins: #{config.admins}\n\tBot time: #{Time.now}", dest
|
22
22
|
if @status == :on
|
23
|
-
|
24
|
-
|
23
|
+
#@listening.keys delete :threads key
|
24
|
+
listening_keys = @listening.keys - [:threads]
|
25
|
+
#remove team id from keys, key is a symbol
|
26
|
+
listening_keys = listening_keys.map{|k| k.to_s.gsub(user.team_id+"_",'').to_sym}
|
27
|
+
respond "I'm listening to [#{listening_keys.join(", ")}]", dest
|
28
|
+
if config.on_master_bot and config.team_id_admins.include?("#{user.team_id}_#{user.name}")
|
25
29
|
sleep 5
|
26
30
|
@bots_created.each do |k, v|
|
27
31
|
msg = []
|
@@ -15,12 +15,13 @@ class SlackSmartBot
|
|
15
15
|
channel_id = channel
|
16
16
|
end
|
17
17
|
|
18
|
+
team_id_user = "#{user.team_id}_#{user.name}"
|
18
19
|
if dest[0] == "C" or dest[0] == "G" #channel
|
19
|
-
if @rules_imported.key?(
|
20
|
-
if @rules_imported[
|
20
|
+
if @rules_imported.key?(team_id_user) and @rules_imported[team_id_user].key?(dchannel)
|
21
|
+
if @rules_imported[team_id_user][dchannel] != channel_id
|
21
22
|
respond "You are not using those rules.", dest
|
22
23
|
else
|
23
|
-
@rules_imported[
|
24
|
+
@rules_imported[team_id_user].delete(dchannel)
|
24
25
|
sleep 0.5
|
25
26
|
update_rules_imported()
|
26
27
|
respond "You won't be using those rules from now on.", dest
|
@@ -32,11 +33,11 @@ class SlackSmartBot
|
|
32
33
|
respond "You were not using those rules.", dest
|
33
34
|
end
|
34
35
|
else #direct message
|
35
|
-
if @rules_imported.key?(
|
36
|
-
if @rules_imported[
|
36
|
+
if @rules_imported.key?(team_id_user) and @rules_imported[team_id_user].key?(user.name)
|
37
|
+
if @rules_imported[team_id_user][user.name] != channel_id
|
37
38
|
respond "You are not using those rules.", dest
|
38
39
|
else
|
39
|
-
@rules_imported[
|
40
|
+
@rules_imported[team_id_user].delete(user.name)
|
40
41
|
sleep 0.5
|
41
42
|
update_rules_imported()
|
42
43
|
respond "You won't be using those rules from now on.", dest
|
@@ -12,10 +12,10 @@ class SlackSmartBot
|
|
12
12
|
# help: if used 'command' it will show any kind of command or rule.
|
13
13
|
# help: command_id: :suggest_command
|
14
14
|
# help:
|
15
|
-
def suggest_command(
|
15
|
+
def suggest_command(user, dest, dchannel, specific, rules_file)
|
16
16
|
save_stats(__method__)
|
17
17
|
dont_suggest = []
|
18
|
-
help_message = get_help(rules_file, dest,
|
18
|
+
help_message = get_help(rules_file, dest, user, specific, true, descriptions: false, only_normal_user: true)
|
19
19
|
commands = help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).flatten
|
20
20
|
commands.reject!{|c| c.match?(/These are specific commands for this bot on this/i) || c.match?(/\A\s*\z/)}
|
21
21
|
dont_suggest.each do |ds|
|
@@ -24,13 +24,14 @@ class SlackSmartBot
|
|
24
24
|
@last_suggested_commands ||= []
|
25
25
|
@last_suggested_commands.shift if @last_suggested_commands.size >=5
|
26
26
|
command = ''
|
27
|
-
begin
|
27
|
+
begin
|
28
28
|
command = commands.sample
|
29
29
|
end until !@last_suggested_commands.include?(command) or commands.size <= 5
|
30
30
|
@last_suggested_commands << command
|
31
31
|
command.gsub!(/^\s*command_id:\s+:\w+\s*$/,'')
|
32
|
+
command.gsub!(/^\s*>.+$/,'')
|
32
33
|
message = "*Command suggestion*:\n#{command}"
|
33
34
|
respond message, dest, unfurl_links: false, unfurl_media: false
|
34
35
|
end
|
35
36
|
|
36
|
-
end
|
37
|
+
end
|