slack-smart-bot 1.14.2 → 1.15.1
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 +181 -76
- data/lib/slack-smart-bot_general_commands.rb +10 -9
- data/whats_new.txt +30 -13
- metadata +128 -20
@@ -3,18 +3,19 @@ class SlackSmartBot
|
|
3
3
|
module General
|
4
4
|
module Teams
|
5
5
|
module Memos
|
6
|
-
def see_memos_team(user, type: "all", name: nil, topic: "", add_stats: true, team: nil, memo_id: nil)
|
6
|
+
def see_memos_team(user, type: "all", name: nil, topic: "", add_stats: true, team: nil, memo_id: nil, precise: true)
|
7
7
|
save_stats(__method__) if add_stats
|
8
|
-
|
9
8
|
get_teams()
|
10
9
|
type = "all" if type.match?(/all\s+memo/i)
|
11
10
|
message = []
|
12
11
|
if @teams.size > 0
|
12
|
+
num_memos = 0
|
13
13
|
if team.nil?
|
14
14
|
@teams.each do |team_name, teamv|
|
15
15
|
if (team_name.to_s == name.to_s) or (name.to_s.gsub("-", "").gsub("_", "") == team_name.to_s)
|
16
|
-
|
17
|
-
|
16
|
+
team = teamv.deep_copy
|
17
|
+
if team.key?(:memos) and team[:memos].size > 0
|
18
|
+
num_memos = teamv[:memos].size
|
18
19
|
else
|
19
20
|
respond "There are no memos for the team #{name}." unless !add_stats
|
20
21
|
end
|
@@ -22,7 +23,8 @@ class SlackSmartBot
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
|
-
if team
|
26
|
+
num_memos = team[:memos].size if team and num_memos == 0
|
27
|
+
if team and num_memos > 0
|
26
28
|
react :running unless !add_stats
|
27
29
|
all_memos = {}
|
28
30
|
assigned_members, unassigned_members, not_on_team_channel, channels_members, all_team_members = get_team_members(team)
|
@@ -37,12 +39,14 @@ class SlackSmartBot
|
|
37
39
|
end
|
38
40
|
team[:memos].each do |memo|
|
39
41
|
if memo_id.nil? or memo[:memo_id] == memo_id.to_i
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
if topic == "" or (memo.topic == topic and precise) or (memo.topic.to_s.downcase.include?(topic.to_s.downcase) and !precise)
|
43
|
+
memos_filtered << memo
|
44
|
+
all_topics << memo.topic
|
45
|
+
if memo.key?(:search) and memo.key?(:issues) and memo.issues.size > 0
|
46
|
+
num_issues += memo.issues.size
|
47
|
+
else
|
48
|
+
num_issues += 1
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
@@ -57,22 +61,22 @@ class SlackSmartBot
|
|
57
61
|
elsif memos_filtered.size > 0
|
58
62
|
memos_filtered.each do |memo|
|
59
63
|
if memo.privacy.empty? or
|
60
|
-
(memo.privacy == "private" and (all_team_members.include?(user.name) and (users_link or channels_members.include?(Thread.current[:dest])))) or
|
61
|
-
(memo.privacy == "personal" and memo.user == user.name and users_link)
|
64
|
+
(memo.privacy == "private" and (all_team_members.include?("#{user.team_id}_#{user.name}") and (users_link or channels_members.include?(Thread.current[:dest])))) or
|
65
|
+
(memo.privacy == "personal" and memo.user == "#{user.team_id}_#{user.name}" and users_link)
|
62
66
|
if memo.type == "jira" and config.jira.host != ""
|
63
67
|
http = NiceHttp.new(config.jira.host)
|
64
68
|
http.headers.authorization = NiceHttpUtils.basic_authentication(user: config.jira.user, password: config.jira.password)
|
65
69
|
if memo.message.match?(/^\w+\-\d+$/) or (memo.key?(:search) and !memo.search)
|
66
70
|
resp = http.get("/rest/api/latest/issue/#{memo.message}")
|
67
|
-
issues = [resp.data.json] if resp.code == 200
|
71
|
+
issues = [resp.data.json] if resp.code.to_s == '200'
|
68
72
|
memo.search = false
|
69
73
|
else
|
70
74
|
resp = http.get("/rest/api/latest/search/?jql=#{memo.message}")
|
71
|
-
issues = resp.data.json().issues if resp.code == 200
|
75
|
+
issues = resp.data.json().issues if resp.code.to_s == '200'
|
72
76
|
memo.search = true
|
73
77
|
end
|
74
|
-
if resp.code == 200
|
75
|
-
unless issues.empty?
|
78
|
+
if resp.code.to_s == '200'
|
79
|
+
unless issues.nil? or issues.empty?
|
76
80
|
if memo.search
|
77
81
|
if memo.key?(:issues)
|
78
82
|
orig_issues = memo.issues.deep_copy.sort
|
@@ -98,7 +102,8 @@ class SlackSmartBot
|
|
98
102
|
if memo.topic == :no_topic and !issue.fields.labels.empty?
|
99
103
|
jira_memo.topic = issue.fields.labels.sort.join("_").split(" ").join("_")
|
100
104
|
end
|
101
|
-
if topic == "" or (topic != "" and jira_memo.topic.to_s.downcase == topic.to_s.downcase)
|
105
|
+
if topic == "" or (topic != "" and jira_memo.topic.to_s.downcase == topic.to_s.downcase and precise) or
|
106
|
+
(topic != "" and jira_memo.topic.to_s.downcase.include?(topic.to_s.downcase) and !precise)
|
102
107
|
case issue.fields.issuetype.name
|
103
108
|
when "Story"; jira_memo.type = ":abc:"; jira_memo.mtype = "memo"
|
104
109
|
when "Bug"; jira_memo.type = ":bug:"; jira_memo.mtype = "bug"
|
@@ -148,7 +153,7 @@ class SlackSmartBot
|
|
148
153
|
resp = http.get("/repos/#{issue_url}")
|
149
154
|
issues = resp.data.json()
|
150
155
|
issues = [issues] unless issues.is_a?(Array)
|
151
|
-
if resp.code == 200
|
156
|
+
if resp.code.to_s == '200'
|
152
157
|
unless issues.empty?
|
153
158
|
if memo.search
|
154
159
|
if memo.key?(:issues)
|
@@ -179,7 +184,8 @@ class SlackSmartBot
|
|
179
184
|
if memo.topic == :no_topic and !issue.labels.empty?
|
180
185
|
github_memo.topic = labels
|
181
186
|
end
|
182
|
-
if topic == "" or (topic != "" and github_memo.topic.to_s.downcase == topic.to_s.downcase)
|
187
|
+
if topic == "" or (topic != "" and github_memo.topic.to_s.downcase == topic.to_s.downcase and precise) or
|
188
|
+
(topic != "" and github_memo.topic.to_s.downcase.include?(topic.to_s.downcase) and !precise)
|
183
189
|
case labels
|
184
190
|
when /bug/i; github_memo.type = ":bug:"; github_memo.mtype = "bug"
|
185
191
|
when /docum/i; github_memo.type = ":abc:"; github_memo.mtype = "note"
|
@@ -218,7 +224,8 @@ class SlackSmartBot
|
|
218
224
|
end
|
219
225
|
http.close
|
220
226
|
else
|
221
|
-
if topic == "" or (topic != "" and memo.topic.to_s.downcase == topic.to_s.downcase)
|
227
|
+
if topic == "" or (topic != "" and memo.topic.to_s.downcase == topic.to_s.downcase and precise) or
|
228
|
+
(topic != "" and memo.topic.to_s.downcase.include?(topic.to_s.downcase) and !precise)
|
222
229
|
if (type == "all" or type.to_s == memo[:type].to_s or type == "")
|
223
230
|
memo.jira = false
|
224
231
|
memo.github = false
|
@@ -263,7 +270,8 @@ class SlackSmartBot
|
|
263
270
|
when "personal"; priv = " `personal`"
|
264
271
|
else priv = ""
|
265
272
|
end
|
266
|
-
|
273
|
+
uname = memo.user.split("_")[1..-1].join("_")
|
274
|
+
message << " #{memo.type} #{memo.date.gsub("-", "/")[0..9]}: #{memo.status} #{memo.message} (#{uname} #{memo.memo_id})#{priv}#{" :spiral_note_pad:" if memo.key?(:comments) and !memo.comments.empty?}#{" :mag:" if memo.key?(:search) and memo.search}"
|
267
275
|
end
|
268
276
|
end
|
269
277
|
all_memos[:no_topic] = []
|
@@ -276,7 +284,8 @@ class SlackSmartBot
|
|
276
284
|
when "personal"; priv = " `personal`"
|
277
285
|
else priv = ""
|
278
286
|
end
|
279
|
-
|
287
|
+
uname = memo.user.split("_")[1..-1].join("_")
|
288
|
+
message << " #{memo.type} #{memo.date.gsub("-", "/")[0..9]}: #{memo.status} #{memo.message} (#{uname} #{memo.memo_id})#{priv}#{" :spiral_note_pad:" if memo.key?(:comments) and !memo.comments.empty?}#{" :mag:" if memo.key?(:search) and memo.search}"
|
280
289
|
end
|
281
290
|
end
|
282
291
|
end
|
@@ -285,7 +294,7 @@ class SlackSmartBot
|
|
285
294
|
message << "There are no memos #{name} team #{type} #{topic}." unless !add_stats
|
286
295
|
end
|
287
296
|
unreact :running unless !add_stats
|
288
|
-
|
297
|
+
elsif team.nil?
|
289
298
|
respond "There is no team named #{name}." unless !add_stats
|
290
299
|
end
|
291
300
|
if add_stats
|
@@ -17,8 +17,8 @@ class SlackSmartBot
|
|
17
17
|
get_channels_name_and_id() unless @channels_id.key?(ch)
|
18
18
|
tm = get_channel_members(@channels_id[ch])
|
19
19
|
tm.each do |m|
|
20
|
-
user_info =
|
21
|
-
team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
|
20
|
+
user_info = find_user(m)
|
21
|
+
team_members << "#{user_info.team_id}_#{user_info.name}" unless user_info.is_app_user or user_info.is_bot
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -30,7 +30,7 @@ class SlackSmartBot
|
|
30
30
|
|
31
31
|
if !@teams.key?(team_name.to_sym)
|
32
32
|
respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
|
33
|
-
elsif !(all_team_members + config.
|
33
|
+
elsif !(all_team_members + config.team_id_masters).flatten.include?("#{user.team_id}_#{user.name}")
|
34
34
|
respond "You have to be a member of the team or a Master admin to be able to set the status of a memo."
|
35
35
|
elsif !@teams[team_name.to_sym].key?(:memos) or @teams[team_name.to_sym][:memos].empty? or !@teams[team_name.to_sym][:memos].memo_id.include?(memo_id.to_i)
|
36
36
|
respond "It seems like there is no memo with id #{memo_id}"
|
@@ -39,7 +39,7 @@ class SlackSmartBot
|
|
39
39
|
if memo_selected.type == "jira" or memo_selected.type == "github"
|
40
40
|
#todo: add tests for jira and github
|
41
41
|
respond "The memo specified is a #{memo_selected.type} and the status in those cases are linked to the specific issues in #{memo_selected.type}."
|
42
|
-
elsif memo_selected.privacy == "personal" and memo_selected.user != user.name
|
42
|
+
elsif memo_selected.privacy == "personal" and memo_selected.user != "#{user.team_id}_#{user.name}"
|
43
43
|
respond "Only the creator can set the status of a personal memo."
|
44
44
|
else
|
45
45
|
answer_delete
|
@@ -22,7 +22,8 @@ class SlackSmartBot
|
|
22
22
|
assigned_members = team.members.values.flatten
|
23
23
|
assigned_members.uniq!
|
24
24
|
assigned_members.dup.each do |m|
|
25
|
-
|
25
|
+
# extract the team_id from the member name: team_id_user_name. so everything after the first _ is the user_name. user_name can include _.
|
26
|
+
user_info = find_user(m)
|
26
27
|
assigned_members.delete(m) if user_info.nil? or user_info.deleted
|
27
28
|
end
|
28
29
|
unassigned_members = []
|
@@ -34,19 +35,19 @@ class SlackSmartBot
|
|
34
35
|
get_channels_name_and_id() unless @channels_id.key?(ch)
|
35
36
|
tm = get_channel_members(@channels_id[ch])
|
36
37
|
tm.each do |m|
|
37
|
-
user_info =
|
38
|
-
team_members << user_info.name unless user_info.nil? or user_info.is_app_user or user_info.is_bot or user_info.deleted
|
38
|
+
user_info = find_user(m)
|
39
|
+
team_members << "#{user_info.team_id}_#{user_info.name}" unless user_info.nil? or user_info.is_app_user or user_info.is_bot or user_info.deleted
|
39
40
|
end
|
40
41
|
end
|
41
42
|
team_members.flatten!
|
42
43
|
team_members.uniq!
|
43
44
|
unassigned_members = team_members - assigned_members
|
44
|
-
unassigned_members.delete(config.nick)
|
45
|
+
unassigned_members.delete("#{config.team_id}_#{config.nick}")
|
45
46
|
|
46
47
|
unless unassigned_members.empty?
|
47
48
|
um = unassigned_members.dup
|
48
49
|
um.each do |m|
|
49
|
-
user_info =
|
50
|
+
user_info = find_user(m)
|
50
51
|
unless user_info.nil? or user_info.profile.title.to_s == "" or user_info.deleted
|
51
52
|
team.members[user_info.profile.title.to_snake_case] ||= []
|
52
53
|
team.members[user_info.profile.title.to_snake_case] << m
|
@@ -70,7 +71,7 @@ class SlackSmartBot
|
|
70
71
|
if type == :ping
|
71
72
|
active_members = []
|
72
73
|
members_list.each do |member|
|
73
|
-
member_info =
|
74
|
+
member_info = find_user(member)
|
74
75
|
unless member_info.nil? or member_info.deleted
|
75
76
|
active = (get_presence(member_info.id).presence.to_s == "active")
|
76
77
|
active_members << member if active
|
@@ -81,12 +82,13 @@ class SlackSmartBot
|
|
81
82
|
members = members_list
|
82
83
|
end
|
83
84
|
members.dup.each do |m|
|
84
|
-
user_info =
|
85
|
+
user_info = find_user(m)
|
85
86
|
members.delete(m) if user_info.nil? or user_info.deleted
|
86
87
|
end
|
87
88
|
|
88
89
|
if members.size > 0
|
89
|
-
|
90
|
+
members_names = members.map { |m| m.split("_")[1..-1].join("_") }
|
91
|
+
respond "#{icon} *#{type} #{team_name} team #{member_type}*\nfrom <@#{user.name}>\nto <@#{members_names[0..29].join(">, <@")}>#{", #{members_names[30..-1].join(", ")}" if members.size > 30} \n> #{message.split("\n").join("\n> ")}"
|
90
92
|
elsif type == :ping
|
91
93
|
respond "It seems like there are no available #{member_type} members on #{team_name} team. Please call `see team #{team_name}`"
|
92
94
|
else
|
@@ -2,7 +2,7 @@ class SlackSmartBot
|
|
2
2
|
module Commands
|
3
3
|
module General
|
4
4
|
module Teams
|
5
|
-
def see_teams(user, team_name, search = "", add_stats: true)
|
5
|
+
def see_teams(user, team_name, search = "", add_stats: true, ttype: '')
|
6
6
|
save_stats(__method__) if add_stats
|
7
7
|
|
8
8
|
get_teams()
|
@@ -14,6 +14,8 @@ class SlackSmartBot
|
|
14
14
|
else
|
15
15
|
users_link = (Thread.current[:dest][0] == "D")
|
16
16
|
filter = (search != "")
|
17
|
+
members_displayed = []
|
18
|
+
|
17
19
|
react :runner
|
18
20
|
@users = get_users() if add_stats
|
19
21
|
|
@@ -25,8 +27,9 @@ class SlackSmartBot
|
|
25
27
|
search.split(" ").each do |s|
|
26
28
|
if s.match(/<@(\w+)>/i)
|
27
29
|
m = $1
|
28
|
-
|
29
|
-
|
30
|
+
#upcase since from the smartbot command we get it in lowercase
|
31
|
+
user_info = find_user(m.upcase)
|
32
|
+
search_members << "#{user_info.team_id}_#{user_info.name}" unless user_info.nil?
|
30
33
|
elsif s.match(/<#(\w+)\|[^>]*>/i)
|
31
34
|
c = $1.upcase
|
32
35
|
search_channels << @channels_name[c] if @channels_name.key?(c)
|
@@ -46,7 +49,7 @@ class SlackSmartBot
|
|
46
49
|
filter ? add = false : add = true
|
47
50
|
if team_name.to_s == "" or (team_name.to_s == name.to_s) or (name.to_s.gsub("-", "").gsub("_", "") == team_name.to_s)
|
48
51
|
message = []
|
49
|
-
message << "*#{name.capitalize}*"
|
52
|
+
message << "*#{name.capitalize}#{" #{ttype}" unless ttype.empty?}*"
|
50
53
|
|
51
54
|
if filter and search_info.size > 0
|
52
55
|
all_info = true
|
@@ -70,7 +73,7 @@ class SlackSmartBot
|
|
70
73
|
unless unassigned_members.empty?
|
71
74
|
um = unassigned_members.dup
|
72
75
|
um.each do |m|
|
73
|
-
user_info =
|
76
|
+
user_info = find_user(m)
|
74
77
|
unless user_info.nil? or user_info.profile.title.to_s == ""
|
75
78
|
team.members[user_info.profile.title.to_snake_case] ||= []
|
76
79
|
team.members[user_info.profile.title.to_snake_case] << m
|
@@ -107,69 +110,75 @@ class SlackSmartBot
|
|
107
110
|
if add
|
108
111
|
if team_name.to_s != ""
|
109
112
|
team.members.each do |type, members|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
if
|
125
|
-
|
113
|
+
if ttype.empty? or type.include?(ttype)
|
114
|
+
message << " _`#{type}`_: "
|
115
|
+
members.each do |member|
|
116
|
+
types = [":palm_tree:", ":spiral_calendar_pad:", ":face_with_thermometer:", ":baby:"]
|
117
|
+
member_info = find_user(member)
|
118
|
+
if !member_info.nil? and !member_info.deleted
|
119
|
+
member_id = member_info.id
|
120
|
+
members_displayed << "#{member_info.team_id}_#{member_info.name}"
|
121
|
+
info = get_user_info(member_id) #to get the status_emoji right now
|
122
|
+
emoji = info.user.profile.status_emoji
|
123
|
+
if types.include?(emoji)
|
124
|
+
status = emoji
|
125
|
+
else
|
126
|
+
active = (get_presence(member_id).presence.to_s == "active")
|
127
|
+
if active
|
128
|
+
if member_info.key?(:tz_offset) and user.key?(:tz_offset) and (member_info.tz_offset - user.tz_offset).abs <= (4 * 3600)
|
129
|
+
status = ":large_green_circle:"
|
130
|
+
else
|
131
|
+
status = ":large_yellow_circle:"
|
132
|
+
end
|
126
133
|
else
|
127
|
-
status = ":
|
134
|
+
status = ":white_circle:"
|
128
135
|
end
|
129
|
-
else
|
130
|
-
status = ":white_circle:"
|
131
136
|
end
|
132
|
-
end
|
133
|
-
else
|
134
|
-
status = ":exclamation:"
|
135
|
-
end
|
136
|
-
unless status == ":exclamation:"
|
137
|
-
if users_link
|
138
|
-
message[-1] += " #{status}<@#{member}>, "
|
139
137
|
else
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
138
|
+
status = ":exclamation:"
|
139
|
+
end
|
140
|
+
unless status == ":exclamation:"
|
141
|
+
if users_link
|
142
|
+
message[-1] += " #{status}<@#{member_info.name}>, "
|
143
|
+
else
|
144
|
+
unless member_info.nil?
|
145
|
+
if member_info.profile.display_name == ""
|
146
|
+
name = member_info.name
|
147
|
+
else
|
148
|
+
name = member_info.profile.display_name
|
149
|
+
end
|
150
|
+
message[-1] += " #{status} #{name}, "
|
146
151
|
end
|
147
|
-
message[-1] += " #{status} #{name}, "
|
148
152
|
end
|
149
153
|
end
|
150
154
|
end
|
155
|
+
message[-1].chop!
|
156
|
+
message[-1].chop!
|
151
157
|
end
|
152
|
-
message[-1].chop!
|
153
|
-
message[-1].chop!
|
154
158
|
end
|
155
159
|
else
|
156
160
|
team.members.each do |type, members|
|
157
|
-
if
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
161
|
+
if ttype.empty? or type.include?(ttype)
|
162
|
+
if users_link
|
163
|
+
members_displayed += members
|
164
|
+
members_names = members.map { |m| m.split("_")[1..-1].join("_") }
|
165
|
+
message << " _`#{type}`_: <@#{members_names.join(">, <@")}>"
|
166
|
+
else
|
167
|
+
membersn = []
|
168
|
+
members.each do |m|
|
169
|
+
user_info = find_user(m)
|
170
|
+
unless user_info.nil? or user_info.deleted
|
171
|
+
members_displayed << "#{user_info.team_id}_#{user_info.name}"
|
172
|
+
if user_info.profile.display_name == ""
|
173
|
+
name = user_info.name
|
174
|
+
else
|
175
|
+
name = user_info.profile.display_name
|
176
|
+
end
|
177
|
+
membersn << name
|
168
178
|
end
|
169
|
-
membersn << name
|
170
179
|
end
|
180
|
+
message << " _`#{type}`_: #{membersn.join(" / ")}"
|
171
181
|
end
|
172
|
-
message << " _`#{type}`_: #{membersn.join(" / ")}"
|
173
182
|
end
|
174
183
|
end
|
175
184
|
end
|
@@ -178,18 +187,21 @@ class SlackSmartBot
|
|
178
187
|
if add
|
179
188
|
message << " > *_channels_*"
|
180
189
|
team.channels.each do |type, channels|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
190
|
+
if ttype.empty? or type.include?(ttype)
|
191
|
+
channel_ids = []
|
192
|
+
channels.each do |ch|
|
193
|
+
channel_info = @channels_list.select { |c| c.name.to_s.downcase == ch.to_s.downcase }[-1]
|
194
|
+
# remove team_id from team members values
|
195
|
+
if @channels_id.key?(ch) and (!channel_info.is_private or (channel_info.is_private and (team.members.values + [team.creator]).flatten.include?("#{user.team_id}_#{user.name}")))
|
196
|
+
channel_ids << @channels_id[ch]
|
197
|
+
end
|
186
198
|
end
|
199
|
+
message << " _`#{type}`_: <##{channel_ids.join("> <#")}>" unless channel_ids.empty?
|
187
200
|
end
|
188
|
-
message << " _`#{type}`_: <##{channel_ids.join("> <#")}>" unless channel_ids.empty?
|
189
201
|
end
|
190
202
|
|
191
203
|
unless !team.key?(:memos) or team.memos.empty? or (team_name.to_s == "" and search.to_s == "")
|
192
|
-
message += see_memos_team(user, type: "all", add_stats: false, team: team)
|
204
|
+
message += see_memos_team(user, type: "all", add_stats: false, team: team, topic: ttype, precise: false)
|
193
205
|
end
|
194
206
|
|
195
207
|
unless team.info.empty?
|
@@ -225,7 +237,7 @@ class SlackSmartBot
|
|
225
237
|
respond msg, dest, unfurl_links: false, unfurl_media: false
|
226
238
|
end
|
227
239
|
unless team_name.to_s.empty?
|
228
|
-
see_vacations_team(user, team_name, Date.today.strftime("%Y/%m/%d"), add_stats: false)
|
240
|
+
see_vacations_team(user, team_name, Date.today.strftime("%Y/%m/%d"), add_stats: false, filter_members: members_displayed)
|
229
241
|
end
|
230
242
|
end
|
231
243
|
end
|
@@ -2,7 +2,7 @@ class SlackSmartBot
|
|
2
2
|
module Commands
|
3
3
|
module General
|
4
4
|
module Teams
|
5
|
-
def see_vacations_team(user, team_name, date, add_stats: true)
|
5
|
+
def see_vacations_team(user, team_name, date, add_stats: true, filter_members: [])
|
6
6
|
save_stats(__method__) if add_stats
|
7
7
|
|
8
8
|
get_teams()
|
@@ -20,15 +20,16 @@ class SlackSmartBot
|
|
20
20
|
end
|
21
21
|
date.gsub!("-", "/")
|
22
22
|
get_vacations()
|
23
|
+
members_by_country_region = {}
|
23
24
|
team = teams[team_name.to_sym]
|
24
25
|
assigned_members = team.members.values.flatten
|
25
26
|
assigned_members.uniq!
|
26
27
|
assigned_members.dup.each do |m|
|
27
|
-
user_info =
|
28
|
+
user_info = find_user(m)
|
28
29
|
assigned_members.delete(m) if user_info.nil? or user_info.deleted
|
29
30
|
end
|
30
31
|
|
31
|
-
channels_members = []
|
32
|
+
channels_members = [] #todo: check if this is used in here. Remove.
|
32
33
|
all_team_members = assigned_members.dup
|
33
34
|
if team.channels.key?("members")
|
34
35
|
team_members = []
|
@@ -40,8 +41,8 @@ class SlackSmartBot
|
|
40
41
|
else
|
41
42
|
channels_members << @channels_id[ch]
|
42
43
|
tm.each do |m|
|
43
|
-
user_info =
|
44
|
-
team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
|
44
|
+
user_info = find_user(m)
|
45
|
+
team_members << "#{user_info.team_id}_#{user_info.name}" unless user_info.nil? or user_info.is_app_user or user_info.is_bot
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -49,6 +50,10 @@ class SlackSmartBot
|
|
49
50
|
all_team_members += team_members
|
50
51
|
all_team_members.uniq!
|
51
52
|
end
|
53
|
+
if filter_members.size > 0
|
54
|
+
all_team_members = all_team_members & filter_members
|
55
|
+
end
|
56
|
+
|
52
57
|
unless all_team_members.empty?
|
53
58
|
blocks_header =
|
54
59
|
{
|
@@ -69,8 +74,7 @@ class SlackSmartBot
|
|
69
74
|
defaulted_country_region = ""
|
70
75
|
end
|
71
76
|
all_team_members.each do |m|
|
72
|
-
|
73
|
-
info = @users.select { |u| u.id == m or (u.key?(:enterprise_user) and u.enterprise_user.id == m) or u.name == m or (u.key?(:enterprise_user) and u.enterprise_user.name == m) }[-1]
|
77
|
+
info = find_user(m)
|
74
78
|
unless info.nil?
|
75
79
|
country_region = ""
|
76
80
|
if @vacations.key?(m) and @vacations[m][:public_holidays].to_s != ""
|
@@ -78,8 +82,8 @@ class SlackSmartBot
|
|
78
82
|
elsif config[:public_holidays].key?(:default_calendar) and country_region.empty?
|
79
83
|
country_region = defaulted_country_region
|
80
84
|
end
|
81
|
-
|
82
|
-
|
85
|
+
members_by_country_region[country_region] ||= []
|
86
|
+
members_by_country_region[country_region] << "#{info.team_id}_#{info.name}"
|
83
87
|
if @vacations.key?(m)
|
84
88
|
v = ""
|
85
89
|
(from..(from + 20)).each do |d|
|
@@ -148,8 +152,8 @@ class SlackSmartBot
|
|
148
152
|
elements: [
|
149
153
|
{
|
150
154
|
type: "image",
|
151
|
-
image_url: info.
|
152
|
-
alt_text: info.
|
155
|
+
image_url: info.profile.image_24,
|
156
|
+
alt_text: info.name,
|
153
157
|
},
|
154
158
|
{
|
155
159
|
type: "plain_text",
|
@@ -171,8 +175,19 @@ class SlackSmartBot
|
|
171
175
|
if !defaulted_country_region.empty?
|
172
176
|
message = "Defaulted public holidays calendar: #{defaulted_country_region}\n"
|
173
177
|
end
|
174
|
-
|
175
|
-
|
178
|
+
if members_by_country_region.size > 0 and members_by_country_region.keys.size > 1
|
179
|
+
message_tmp = []
|
180
|
+
members_by_country_region.each do |region, members|
|
181
|
+
#use only the user name on members
|
182
|
+
members_names = members.map { |m| m.split("_")[1..-1].join("_") }
|
183
|
+
message_tmp << "`#{region}`: <#{members_names.sort.join(", ")}>"
|
184
|
+
end
|
185
|
+
message += "Members by region:\n\t#{message_tmp.join(". ")}\n"
|
186
|
+
end
|
187
|
+
if all_team_members.include?(user.name)
|
188
|
+
message += "To change your public holidays calendar, use the command `set public holidays to COUNTRY/STATE`. "
|
189
|
+
message += "\nExamples: `set public holidays to Iceland`, `set public holidays to Spain/Madrid`"
|
190
|
+
end
|
176
191
|
respond message
|
177
192
|
end
|
178
193
|
end
|
@@ -15,8 +15,8 @@ class SlackSmartBot
|
|
15
15
|
get_channels_name_and_id() unless @channels_id.key?(ch)
|
16
16
|
tm = get_channel_members(@channels_id[ch])
|
17
17
|
tm.each do |m|
|
18
|
-
user_info =
|
19
|
-
team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
|
18
|
+
user_info = find_user(m)
|
19
|
+
team_members << "#{user_info.team_id}_#{user_info.name}" unless user_info.is_app_user or user_info.is_bot
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -27,7 +27,7 @@ class SlackSmartBot
|
|
27
27
|
end
|
28
28
|
if !@teams.key?(team_name.to_sym)
|
29
29
|
respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
|
30
|
-
elsif !(all_team_members + [@teams[team_name.to_sym].creator] + config.
|
30
|
+
elsif !(all_team_members + [@teams[team_name.to_sym].creator] + config.team_id_masters).flatten.include?("#{user.team_id}_#{user.name}")
|
31
31
|
respond "You have to be a member of the team, the creator or a Master admin to be able to update this team."
|
32
32
|
else
|
33
33
|
wrong = false
|
@@ -49,14 +49,14 @@ class SlackSmartBot
|
|
49
49
|
last_type = opt
|
50
50
|
elsif opt.match(/<?@(\w+)>?/i) #accepts also @username for the case the user has been deactivated
|
51
51
|
member_id = $1
|
52
|
-
member_info =
|
52
|
+
member_info = find_user(member_id)
|
53
53
|
if last_type.nil?
|
54
54
|
@teams[team_name.to_sym].members.each do |type, members|
|
55
|
-
@teams[team_name.to_sym].members[type].delete(member_info.name)
|
55
|
+
@teams[team_name.to_sym].members[type].delete("#{member_info.team_id}_#{member_info.name}")
|
56
56
|
end
|
57
57
|
else
|
58
58
|
@teams[team_name.to_sym].members[last_type] ||= []
|
59
|
-
@teams[team_name.to_sym].members[last_type].delete(member_info.name)
|
59
|
+
@teams[team_name.to_sym].members[last_type].delete("#{member_info.team_id}_#{member_info.name}")
|
60
60
|
end
|
61
61
|
elsif opt.match(/<#(\w+)\|[^>]*>/i)
|
62
62
|
channel_id = $1
|
@@ -94,9 +94,9 @@ class SlackSmartBot
|
|
94
94
|
elsif opt.match(/<@(\w+)>/i)
|
95
95
|
member_id = $1
|
96
96
|
last_type = "no_type" if last_type.nil?
|
97
|
-
member_info =
|
97
|
+
member_info = find_user(member_id)
|
98
98
|
@teams[team_name.to_sym].members[last_type] ||= []
|
99
|
-
@teams[team_name.to_sym].members[last_type] << member_info.name
|
99
|
+
@teams[team_name.to_sym].members[last_type] << "#{member_info.team_id}_#{member_info.name}"
|
100
100
|
@teams[team_name.to_sym].members[last_type].uniq!
|
101
101
|
elsif opt.match(/<#(\w+)\|[^>]*>/i)
|
102
102
|
channel_id = $1
|
@@ -123,7 +123,7 @@ class SlackSmartBot
|
|
123
123
|
unless wrong
|
124
124
|
message ||= "The *#{team_name}* team has been updated."
|
125
125
|
@teams[team_name.to_sym].status = :updated
|
126
|
-
@teams[team_name.to_sym].user = user.name
|
126
|
+
@teams[team_name.to_sym].user = "#{user.team_id}_#{user.name}"
|
127
127
|
@teams[team_name.to_sym].date = Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")[0..18]
|
128
128
|
update_teams()
|
129
129
|
end
|