slack-smart-bot 1.9.1 → 1.11.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 +184 -16
- data/lib/slack/smart-bot/comm/ask.rb +55 -49
- data/lib/slack/smart-bot/comm/delete.rb +13 -0
- data/lib/slack/smart-bot/comm/dont_understand.rb +3 -3
- data/lib/slack/smart-bot/comm/event_hello.rb +8 -4
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -4
- data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
- data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +19 -2
- data/lib/slack/smart-bot/comm/respond.rb +224 -53
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +59 -33
- data/lib/slack/smart-bot/comm/unreact.rb +22 -18
- data/lib/slack/smart-bot/comm.rb +4 -0
- data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
- data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +69 -33
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
- data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- 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/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 +115 -0
- data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +53 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +91 -0
- data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +504 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +45 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +6 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +3 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +4 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +8 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +33 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +13 -10
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +6 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +3 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +4 -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 +34 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +37 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +4 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +7 -8
- data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +3 -4
- data/lib/slack/smart-bot/commands/on_bot/general/leaderboard.rb +201 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +12 -6
- data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +36 -0
- data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +13 -11
- 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 +4 -5
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +76 -21
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +3 -4
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +15 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +5 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -6
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +7 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +3 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +33 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +39 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +10 -1
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +28 -14
- data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
- data/lib/slack/smart-bot/commands.rb +36 -5
- data/lib/slack/smart-bot/listen.rb +31 -33
- data/lib/slack/smart-bot/process.rb +234 -73
- data/lib/slack/smart-bot/process_first.rb +119 -38
- data/lib/slack/smart-bot/treat_message.rb +310 -237
- data/lib/slack/smart-bot/utils/build_help.rb +2 -2
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
- data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
- data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
- data/lib/slack/smart-bot/utils/get_bots_created.rb +28 -8
- 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 +79 -73
- 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_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
- data/lib/slack/smart-bot/utils/has_access.rb +28 -0
- data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +46 -41
- data/lib/slack/smart-bot/utils/save_status.rb +67 -0
- data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
- data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -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.rb +11 -0
- data/lib/slack-smart-bot.rb +72 -12
- data/lib/slack-smart-bot_general_commands.rb +61 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +43 -17
- data/whats_new.txt +20 -15
- metadata +76 -9
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -313
@@ -0,0 +1,252 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def see_teams(user, team_name, search = "", add_stats: true)
|
3
|
+
save_stats(__method__) if add_stats
|
4
|
+
|
5
|
+
get_teams()
|
6
|
+
teams = @teams.deep_copy
|
7
|
+
if teams.empty?
|
8
|
+
respond "There are no teams added yet. Use `add team` command to add a team."
|
9
|
+
elsif team_name.to_s != "" and !teams.key?(team_name.to_sym) and (teams.keys.select {|t| (t.to_s.gsub('-','').gsub('_','') == team_name.to_s)}).empty?
|
10
|
+
respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
|
11
|
+
else
|
12
|
+
users_link = (Thread.current[:dest][0] == "D")
|
13
|
+
filter = (search != '')
|
14
|
+
react :runner
|
15
|
+
@users = get_users() if add_stats
|
16
|
+
|
17
|
+
messages = []
|
18
|
+
search_members = []
|
19
|
+
search_channels = []
|
20
|
+
search_info = []
|
21
|
+
if filter
|
22
|
+
search.split(' ').each do |s|
|
23
|
+
if s.match(/<@(\w+)>/i)
|
24
|
+
m = $1
|
25
|
+
user_info = @users.select { |u| u.id.downcase == m.downcase or (u.key?(:enterprise_user) and u.enterprise_user.id.downcase == m.downcase) }[-1]
|
26
|
+
search_members << user_info.name unless user_info.nil?
|
27
|
+
elsif s.match(/<#(\w+)\|[^>]*>/i)
|
28
|
+
c = $1.upcase
|
29
|
+
search_channels << @channels_name[c] if @channels_name.key?(c)
|
30
|
+
else
|
31
|
+
search_info << s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
if team_name.to_s == '' and search.to_s == ''
|
36
|
+
dest = :on_thread
|
37
|
+
messages.unshift('Since there are many lines returned the results are returned on a thread by default.')
|
38
|
+
else
|
39
|
+
dest = Thread.current[:dest]
|
40
|
+
end
|
41
|
+
|
42
|
+
teams.each do |name, team|
|
43
|
+
filter ? add = false : add = true
|
44
|
+
if team_name.to_s == "" or (team_name.to_s == name.to_s) or (name.to_s.gsub('-','').gsub('_','') == team_name.to_s)
|
45
|
+
message = []
|
46
|
+
message << "*#{name.capitalize}*"
|
47
|
+
|
48
|
+
if filter and search_info.size > 0
|
49
|
+
all_info = true
|
50
|
+
search_info.each do |s|
|
51
|
+
if (team.members.keys.find { |e| /#{s}/i =~ e})
|
52
|
+
add = true
|
53
|
+
break
|
54
|
+
end
|
55
|
+
if !name.match?(/#{s}/i)
|
56
|
+
all_info = false
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
add = true if all_info
|
61
|
+
end
|
62
|
+
|
63
|
+
message << " > *_members_*"
|
64
|
+
|
65
|
+
assigned_members = team.members.values.flatten
|
66
|
+
assigned_members.uniq!
|
67
|
+
assigned_members.dup.each do |m|
|
68
|
+
user_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]
|
69
|
+
assigned_members.delete(m) if user_info.nil? or user_info.deleted
|
70
|
+
end
|
71
|
+
|
72
|
+
if team.channels.key?("members")
|
73
|
+
team_members = []
|
74
|
+
team.channels["members"].each do |ch|
|
75
|
+
get_channels_name_and_id() unless @channels_id.key?(ch)
|
76
|
+
tm = get_channel_members(@channels_id[ch])
|
77
|
+
if tm.nil?
|
78
|
+
respond ":exclamation: Add the Smart Bot to *##{ch}* channel to be able to get the list of members.", dest
|
79
|
+
else
|
80
|
+
tm.each do |m|
|
81
|
+
user_info = @users.select { |u| u.id == m or (u.key?(:enterprise_user) and u.enterprise_user.id == m) }[-1]
|
82
|
+
team_members << user_info.name unless user_info.is_app_user or user_info.is_bot
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
team_members.flatten!
|
87
|
+
team_members.uniq!
|
88
|
+
unassigned_members = team_members - assigned_members
|
89
|
+
unassigned_members.delete(config.nick)
|
90
|
+
not_on_team_channel = assigned_members - team_members
|
91
|
+
else
|
92
|
+
unassigned_members = []
|
93
|
+
not_on_team_channel = []
|
94
|
+
end
|
95
|
+
unless unassigned_members.empty?
|
96
|
+
um = unassigned_members.dup
|
97
|
+
um.each do |m|
|
98
|
+
user_info = @users.select { |u| u.name == m or (u.key?(:enterprise_user) and u.enterprise_user.name == m) }[-1]
|
99
|
+
unless user_info.nil? or user_info.profile.title.to_s==''
|
100
|
+
team.members[user_info.profile.title.to_snake_case] ||= []
|
101
|
+
team.members[user_info.profile.title.to_snake_case] << m
|
102
|
+
unassigned_members.delete(m)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
unless unassigned_members.empty?
|
106
|
+
team.members["unassigned"] ||= []
|
107
|
+
team.members["unassigned"] += unassigned_members
|
108
|
+
team.members["unassigned"].sort!
|
109
|
+
end
|
110
|
+
end
|
111
|
+
unless not_on_team_channel.empty?
|
112
|
+
team.members["not on members channel"] = not_on_team_channel
|
113
|
+
team.members["not on members channel"].sort!
|
114
|
+
end
|
115
|
+
add = true if (team.members.values.flatten & search_members).size > 0
|
116
|
+
add = true if (team.channels.values.flatten & search_channels).size > 0
|
117
|
+
if filter and search_info.size > 0
|
118
|
+
all_info = true
|
119
|
+
search_info.each do |s|
|
120
|
+
if (team.members.keys.find { |e| /#{s}/i =~ e})
|
121
|
+
add = true
|
122
|
+
break
|
123
|
+
end
|
124
|
+
if !team.info.match?(/#{s}/i)
|
125
|
+
all_info = false
|
126
|
+
break
|
127
|
+
end
|
128
|
+
end
|
129
|
+
add = true if all_info
|
130
|
+
end
|
131
|
+
|
132
|
+
if add
|
133
|
+
if team_name.to_s != ""
|
134
|
+
team.members.each do |type, members|
|
135
|
+
message << " _`#{type}`_: "
|
136
|
+
members.each do |member|
|
137
|
+
types = [":palm_tree:", ":spiral_calendar_pad:", ":face_with_thermometer:"]
|
138
|
+
member_info = @users.select { |u| u.name == member }[-1]
|
139
|
+
if !member_info.nil? and !member_info.deleted
|
140
|
+
member_id = member_info.id
|
141
|
+
info = get_user_info(member_id)
|
142
|
+
emoji = info.user.profile.status_emoji
|
143
|
+
if types.include?(emoji)
|
144
|
+
status = emoji
|
145
|
+
else
|
146
|
+
active = (get_presence(member_id).presence.to_s == "active")
|
147
|
+
if active
|
148
|
+
user_info = @users.select { |u| u.id == member_id or (u.key?(:enterprise_user) and u.enterprise_user.name == member_id) }[-1]
|
149
|
+
if (user_info.tz_offset-user.tz_offset).abs <= (4*3600)
|
150
|
+
status = ":large_green_circle:"
|
151
|
+
else
|
152
|
+
status = ":large_yellow_circle:"
|
153
|
+
end
|
154
|
+
else
|
155
|
+
status = ":white_circle:"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
else
|
159
|
+
status = ":exclamation:"
|
160
|
+
end
|
161
|
+
unless status == ':exclamation:'
|
162
|
+
if users_link
|
163
|
+
message[-1] += " #{status}<@#{member}>, "
|
164
|
+
else
|
165
|
+
user_info = @users.select { |u| u.name == member or (u.key?(:enterprise_user) and u.enterprise_user.name == member) }[-1]
|
166
|
+
unless user_info.nil?
|
167
|
+
if user_info.profile.display_name == ''
|
168
|
+
name = user_info.name
|
169
|
+
else
|
170
|
+
name = user_info.profile.display_name
|
171
|
+
end
|
172
|
+
message[-1] += " #{status} #{name}, "
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
message[-1].chop!
|
178
|
+
message[-1].chop!
|
179
|
+
end
|
180
|
+
else
|
181
|
+
team.members.each do |type, members|
|
182
|
+
if users_link
|
183
|
+
message << " _`#{type}`_: <@#{members.join(">, <@")}>"
|
184
|
+
else
|
185
|
+
membersn = []
|
186
|
+
members.each do |m|
|
187
|
+
user_info = @users.select { |u| u.name == m or (u.key?(:enterprise_user) and u.enterprise_user.name == m) }[-1]
|
188
|
+
unless user_info.nil? or user_info.deleted
|
189
|
+
if user_info.profile.display_name == ''
|
190
|
+
name = user_info.name
|
191
|
+
else
|
192
|
+
name = user_info.profile.display_name
|
193
|
+
end
|
194
|
+
membersn << name
|
195
|
+
end
|
196
|
+
end
|
197
|
+
message << " _`#{type}`_: #{membersn.join(" / ")}"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
if add
|
205
|
+
message << " > *_channels_*"
|
206
|
+
team.channels.each do |type, channels|
|
207
|
+
channel_ids = []
|
208
|
+
channels.each do |ch|
|
209
|
+
channel_info = @channels_list.select { |c| c.name.to_s.downcase == ch.to_s.downcase}[-1]
|
210
|
+
if @channels_id.key?(ch) and (!channel_info.is_private or (channel_info.is_private and (team.members.values+[team.creator]).flatten.include?(user.name)))
|
211
|
+
channel_ids << @channels_id[ch]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
message << " _`#{type}`_: <##{channel_ids.join("> <#")}>" unless channel_ids.empty?
|
215
|
+
end
|
216
|
+
|
217
|
+
unless team.info.empty?
|
218
|
+
team.info.split("\n").each do |m|
|
219
|
+
message << ">#{m}"
|
220
|
+
end
|
221
|
+
message << "> "
|
222
|
+
message << "> "
|
223
|
+
end
|
224
|
+
messages << message.join("\n")
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
unreact :runner
|
229
|
+
if messages.empty?
|
230
|
+
if filter
|
231
|
+
respond "It seems like we didn't find any team with the criteria supplied. Call `see teams` for a full list of teams."
|
232
|
+
else
|
233
|
+
respond "It seems like there are no teams added.\nUse `add team TEAM_NAME PROPERTIES` to add one. Call `bot help add team` for extended info."
|
234
|
+
end
|
235
|
+
else
|
236
|
+
if team_name.to_s != ""
|
237
|
+
message = "\n\n:palm_tree: On vacation / "
|
238
|
+
message += ":spiral_calendar_pad: In a meeting / "
|
239
|
+
message += ":face_with_thermometer: Sick leave / "
|
240
|
+
message += ":white_circle: Away / "
|
241
|
+
message += ":large_yellow_circle: Available in remote timezone / "
|
242
|
+
message += ":large_green_circle: Available"
|
243
|
+
messages[-1] << message
|
244
|
+
messages[-1] << "\n:information_source: Remote Time zone is >4h away from your current (#{user.tz_label})"
|
245
|
+
end
|
246
|
+
messages.each do |msg|
|
247
|
+
respond msg, dest, unfurl_links: false, unfurl_media: false
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
#todo: reaction type not added yet since RTM doesn't support it. See if we can add it as an event
|
3
|
+
def share_messages(user, from_channel, to_channel, condition)
|
4
|
+
save_stats(__method__)
|
5
|
+
if has_access?(__method__, user)
|
6
|
+
#todo: add a @shared variable to control not to be shared more than once when using reactions
|
7
|
+
#todo: it is only possible to share if smartbot is a member in both channels and the person adding the share command also
|
8
|
+
if Thread.current[:typem] == :on_call or Thread.current[:typem] == :on_dm
|
9
|
+
respond "You can use this command only from the source channel."
|
10
|
+
elsif from_channel == to_channel
|
11
|
+
respond "You cannot share messages on the same channel than source channel."
|
12
|
+
else
|
13
|
+
channels = get_channels(types: 'public_channel')
|
14
|
+
channel_found = channels.detect { |c| c.name == from_channel }
|
15
|
+
get_channels_name_and_id() unless @channels_id.key?(to_channel)
|
16
|
+
channel_found = false if !@channels_id.key?(to_channel)
|
17
|
+
if channel_found
|
18
|
+
members = get_channel_members(@channels_id[to_channel])
|
19
|
+
if members.include?(config.nick_id) and members.include?(user.id)
|
20
|
+
if condition.match?(/^\/.+\/$/)
|
21
|
+
type = :regexp
|
22
|
+
elsif condition.match?(/^".+"$/) or condition.match?(/^'.+'$/)
|
23
|
+
type = :text
|
24
|
+
else
|
25
|
+
type = :reaction
|
26
|
+
end
|
27
|
+
if File.exist?("#{config.path}/shares/#{from_channel}.csv")
|
28
|
+
t = CSV.table("#{config.path}/shares/#{from_channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
|
29
|
+
@shares[from_channel] = t
|
30
|
+
if t.size>0
|
31
|
+
num = t[:share_id].max + 1
|
32
|
+
else
|
33
|
+
num = 1
|
34
|
+
end
|
35
|
+
elsif !@shares.key?(from_channel)
|
36
|
+
File.open("#{config.path}/shares/#{from_channel}.csv","w")
|
37
|
+
t = CSV.table("#{config.path}/shares/#{from_channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
|
38
|
+
num = 1
|
39
|
+
@shares[from_channel] = t
|
40
|
+
else
|
41
|
+
num = @shares[from_channel][:share_id].max + 1
|
42
|
+
end
|
43
|
+
values = [num, '', user.name, Time.now.strftime("%Y/%m/%d"), Time.now.strftime("%H:%M"), type.to_s, to_channel, condition]
|
44
|
+
@shares[from_channel] << values
|
45
|
+
CSV.open("#{config.path}/shares/#{from_channel}.csv", "a+") do |csv|
|
46
|
+
csv << values
|
47
|
+
end
|
48
|
+
respond "*Share command*: id:#{num} Messages #{condition} will be shared from now on. Related commands `see shares`, `delete share ID`"
|
49
|
+
else
|
50
|
+
respond "*Share command*: The channel ##{to_channel} need to exist and the SmartBot and you have to be members."
|
51
|
+
end
|
52
|
+
else
|
53
|
+
respond "*Share command*: The channel <##{@channels_id[from_channel]}|#{from_channel}> has to be a public channel and the destination channel has to be a valid channel."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
def update_team(user, team_name, new_name: "", new_info: "", delete_opts: "", add_opts: "")
|
3
|
+
save_stats(__method__)
|
4
|
+
get_teams()
|
5
|
+
if !@teams.key?(team_name.to_sym)
|
6
|
+
respond "It seems like the team *#{team_name}* doesn't exist.\nRelated commands `add team TEAM_NAME PROPERTIES`, `see team TEAM_NAME`, `see teams`"
|
7
|
+
elsif !(@teams[team_name.to_sym].members.values + [@teams[team_name.to_sym].creator] + config.masters).flatten.include?(user.name)
|
8
|
+
respond "You have to be a member of the team, the creator or a Master admin to be able to update this team."
|
9
|
+
else
|
10
|
+
wrong = false
|
11
|
+
if new_name != ""
|
12
|
+
team = @teams[team_name.to_sym].deep_copy
|
13
|
+
@teams[new_name.to_sym] = team
|
14
|
+
@teams.delete(team_name.to_sym)
|
15
|
+
message = "The *#{team_name}* team has been renamed #{new_name}."
|
16
|
+
team_name = new_name
|
17
|
+
elsif new_info != ""
|
18
|
+
@teams[team_name.to_sym].info = new_info
|
19
|
+
elsif delete_opts != ""
|
20
|
+
last_type = nil
|
21
|
+
delete_opts.split(" ").each do |opt|
|
22
|
+
if opt.match?(/^\s*$/)
|
23
|
+
#blank
|
24
|
+
elsif opt.match?(/^[\w\-]+$/i)
|
25
|
+
last_type = opt
|
26
|
+
elsif opt.match(/<?@(\w+)>?/i) #accepts also @username for the case the user has been deactivated
|
27
|
+
member_id = $1
|
28
|
+
member_info = @users.select { |u| u.id == member_id or u.name == member_id or (u.key?(:enterprise_user) and u.enterprise_user.id == member_id) }[-1]
|
29
|
+
if last_type.nil?
|
30
|
+
@teams[team_name.to_sym].members.each do |type, members|
|
31
|
+
@teams[team_name.to_sym].members[type].delete(member_info.name)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@teams[team_name.to_sym].members[last_type] ||= []
|
35
|
+
@teams[team_name.to_sym].members[last_type].delete(member_info.name)
|
36
|
+
end
|
37
|
+
elsif opt.match(/<#(\w+)\|[^>]*>/i)
|
38
|
+
channel_id = $1
|
39
|
+
get_channels_name_and_id() unless @channels_name.keys.include?(channel_id)
|
40
|
+
channel = @channels_name[channel_id]
|
41
|
+
if last_type.nil?
|
42
|
+
@teams[team_name.to_sym].channels.each do |type, channels|
|
43
|
+
@teams[team_name.to_sym].channels[type].delete(channel)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
@teams[team_name.to_sym].channels[last_type] ||= []
|
47
|
+
@teams[team_name.to_sym].channels[last_type].delete(channel)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
respond "It seems like the members or channel list is not correct. Please double check."
|
51
|
+
wrong = true
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
tmembers = @teams[team_name.to_sym].members.deep_copy
|
56
|
+
tmembers.each do |type, members|
|
57
|
+
@teams[team_name.to_sym].members.delete(type) if members.empty?
|
58
|
+
end
|
59
|
+
tchannels = @teams[team_name.to_sym].channels.deep_copy
|
60
|
+
tchannels.each do |type, channels|
|
61
|
+
@teams[team_name.to_sym].channels.delete(type) if channels.empty?
|
62
|
+
end
|
63
|
+
elsif add_opts != ""
|
64
|
+
last_type = nil
|
65
|
+
add_opts.split(" ").each do |opt|
|
66
|
+
if opt.match?(/^\s*$/)
|
67
|
+
#blank
|
68
|
+
elsif opt.match?(/^[\w\-]+$/i)
|
69
|
+
last_type = opt
|
70
|
+
elsif opt.match(/<@(\w+)>/i)
|
71
|
+
member_id = $1
|
72
|
+
member_info = @users.select { |u| u.id == member_id or (u.key?(:enterprise_user) and u.enterprise_user.id == member_id) }[-1]
|
73
|
+
@teams[team_name.to_sym].members[last_type] ||= []
|
74
|
+
@teams[team_name.to_sym].members[last_type] << member_info.name
|
75
|
+
@teams[team_name.to_sym].members[last_type].uniq!
|
76
|
+
elsif opt.match(/<#(\w+)\|[^>]*>/i)
|
77
|
+
channel_id = $1
|
78
|
+
get_channels_name_and_id() unless @channels_name.keys.include?(channel_id)
|
79
|
+
channel = @channels_name[channel_id]
|
80
|
+
@teams[team_name.to_sym].channels[last_type] ||= []
|
81
|
+
@teams[team_name.to_sym].channels[last_type] << channel
|
82
|
+
@teams[team_name.to_sym].channels[last_type].uniq!
|
83
|
+
else
|
84
|
+
respond "It seems like the members or channel list is not correct. Please double check."
|
85
|
+
wrong = true
|
86
|
+
break
|
87
|
+
end
|
88
|
+
end
|
89
|
+
tmembers = @teams[team_name.to_sym].members.deep_copy
|
90
|
+
tmembers.each do |type, members|
|
91
|
+
@teams[team_name.to_sym].members.delete(type) if members.empty?
|
92
|
+
end
|
93
|
+
tchannels = @teams[team_name.to_sym].channels.deep_copy
|
94
|
+
tchannels.each do |type, channels|
|
95
|
+
@teams[team_name.to_sym].channels.delete(type) if channels.empty?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
unless wrong
|
99
|
+
message ||= "The *#{team_name}* team has been updated."
|
100
|
+
@teams[team_name.to_sym].status = :updated
|
101
|
+
@teams[team_name.to_sym].user = user.name
|
102
|
+
@teams[team_name.to_sym].date = Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")[0..18]
|
103
|
+
update_teams()
|
104
|
+
end
|
105
|
+
respond message
|
106
|
+
see_teams(user, team_name, add_stats: false) unless wrong
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|