slack-smart-bot 1.8.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +127 -21
- data/lib/slack/smart-bot/comm/ask.rb +55 -42
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +38 -8
- data/lib/slack/smart-bot/comm/respond.rb +219 -48
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +24 -7
- data/lib/slack/smart-bot/comm.rb +7 -1
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +13 -16
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +12 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +5 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +49 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
- data/lib/slack/smart-bot/commands.rb +19 -1
- data/lib/slack/smart-bot/listen.rb +7 -8
- data/lib/slack/smart-bot/process.rb +373 -192
- data/lib/slack/smart-bot/process_first.rb +202 -104
- data/lib/slack/smart-bot/treat_message.rb +325 -186
- data/lib/slack/smart-bot/utils/answer.rb +18 -0
- data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
- data/lib/slack/smart-bot/utils/build_help.rb +57 -5
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +83 -30
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +87 -35
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +23 -8
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/lib/slack/smart-bot/utils.rb +5 -0
- data/lib/slack-smart-bot.rb +88 -47
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +49 -23
- data/whats_new.txt +36 -0
- metadata +44 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -0,0 +1,314 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
# help: ----------------------------------------------
|
3
|
+
# help: `bot stats`
|
4
|
+
# helpmaster: `bot stats USER_NAME`
|
5
|
+
# help: `bot stats exclude masters`
|
6
|
+
# help: `bot stats exclude routines`
|
7
|
+
# help: `bot stats from YYYY/MM/DD`
|
8
|
+
# help: `bot stats from YYYY/MM/DD to YYYY/MM/DD`
|
9
|
+
# help: `bot stats CHANNEL`
|
10
|
+
# help: `bot stats CHANNEL from YYYY/MM/DD`
|
11
|
+
# help: `bot stats CHANNEL from YYYY/MM/DD to YYYY/MM/DD`
|
12
|
+
# help: `bot stats command COMMAND`
|
13
|
+
# helpmaster: `bot stats USER_NAME from YYYY/MM/DD to YYYY/MM/DD`
|
14
|
+
# helpmaster: `bot stats CHANNEL USER_NAME from YYYY/MM/DD to YYYY/MM/DD`
|
15
|
+
# help: `bot stats CHANNEL exclude masters from YYYY/MM/DD to YYYY/MM/DD`
|
16
|
+
# help: `bot stats today`
|
17
|
+
# help: `bot stats exclude COMMAND_ID`
|
18
|
+
# help: `bot stats monthly`
|
19
|
+
# help: `bot stats alldata`
|
20
|
+
# help: To see the bot stats
|
21
|
+
# helpmaster: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
|
22
|
+
# helpmaster: You need to set stats to true to generate the stats when running the bot instance.
|
23
|
+
# help: If alldata option supplied then it will be attached files including all data and not only the top 10.
|
24
|
+
# help: Examples:
|
25
|
+
# help: _bot stats #sales_
|
26
|
+
# helpmaster: _bot stats @peter.wind_
|
27
|
+
# help: _bot stats #sales from 2019/12/15 to 2019/12/31_
|
28
|
+
# help: _bot stats #sales today_
|
29
|
+
# help: _bot stats #sales from 2020-01-01 monthly_
|
30
|
+
# help: _bot stats exclude routines masters from 2021/01/01 monthly_
|
31
|
+
# help: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
32
|
+
# help:
|
33
|
+
def bot_stats(dest, from_user, typem, channel_id, from, to, user, st_command, exclude_masters, exclude_routines, exclude_command, monthly, all_data)
|
34
|
+
require 'csv'
|
35
|
+
if config.stats
|
36
|
+
message = []
|
37
|
+
else
|
38
|
+
message = ["You need to set stats to true to generate the stats when running the bot instance."]
|
39
|
+
end
|
40
|
+
save_stats(__method__)
|
41
|
+
if (from_user.id != user and (config.masters.include?(from_user.name) or @master_admin_users_id.include?(from_user.id)) and (typem==:on_dm or dest[0]=='D'))
|
42
|
+
on_dm_master = true #master admin user
|
43
|
+
else
|
44
|
+
on_dm_master = false
|
45
|
+
end
|
46
|
+
if on_dm_master or (from_user.id == user) # normal user can only see own stats
|
47
|
+
if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
|
48
|
+
message<<'No stats'
|
49
|
+
else
|
50
|
+
from = "#{Time.now.strftime("%Y-%m")}-01" if from == ''
|
51
|
+
to = "#{Time.now.strftime("%Y-%m-%d")}" if to == ''
|
52
|
+
from_short = from
|
53
|
+
to_short = to
|
54
|
+
from_file = from[0..3] + '-' + from[5..6]
|
55
|
+
to_file = to[0..3] + '-' + to[5..6]
|
56
|
+
from+= " 00:00:00 +0000"
|
57
|
+
to+= " 23:59:59 +0000"
|
58
|
+
rows = []
|
59
|
+
rows_month = {}
|
60
|
+
users_month = {}
|
61
|
+
commands_month = {}
|
62
|
+
users_id_name = {}
|
63
|
+
users_name_id = {}
|
64
|
+
count_users = {}
|
65
|
+
count_channels_dest = {}
|
66
|
+
|
67
|
+
# to translate global and enterprise users since sometimes was returning different names/ids
|
68
|
+
if from[0..3]=='2020' # this was an issue only on that period
|
69
|
+
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
70
|
+
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
71
|
+
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
72
|
+
unless users_id_name.key?(row[:user_id])
|
73
|
+
users_id_name[row[:user_id]] = row[:user_name]
|
74
|
+
end
|
75
|
+
unless users_name_id.key?(row[:user_name])
|
76
|
+
users_name_id[row[:user_name]] = row[:user_id]
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if user!=''
|
85
|
+
user_info = @users.select{|u| u.id == user or (u.key?(:enterprise_user) and u.enterprise_user.id == user)}[-1]
|
86
|
+
if users_id_name.key?(user_info.id)
|
87
|
+
user_name = users_id_name[user_info.id]
|
88
|
+
else
|
89
|
+
user_name = user_info.name
|
90
|
+
end
|
91
|
+
if users_name_id.key?(user_info.name)
|
92
|
+
user_id = users_name_id[user_info.name]
|
93
|
+
else
|
94
|
+
user_id = user_info.id
|
95
|
+
end
|
96
|
+
end
|
97
|
+
master_admins = config.masters.dup
|
98
|
+
if users_id_name.size > 0
|
99
|
+
config.masters.each do |u|
|
100
|
+
if users_id_name.key?(u)
|
101
|
+
master_admins << users_id_name[u]
|
102
|
+
elsif users_name_id.key?(u)
|
103
|
+
master_admins << users_name_id[u]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
109
|
+
if file >= "#{config.stats_path}.#{from_file}.log" and file <= "#{config.stats_path}.#{to_file}.log"
|
110
|
+
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
111
|
+
row[:date] = row[:date].to_s
|
112
|
+
if row[:dest_channel_id].to_s[0]=='D'
|
113
|
+
row[:dest_channel] = 'DM'
|
114
|
+
elsif row[:dest_channel].to_s == ''
|
115
|
+
row[:dest_channel] = row[:dest_channel_id]
|
116
|
+
end
|
117
|
+
if users_name_id.size > 0
|
118
|
+
row[:user_name] = users_id_name[row[:user_id]]
|
119
|
+
row[:user_id] = users_name_id[row[:user_name]]
|
120
|
+
else
|
121
|
+
users_id_name[row[:user_id]] ||= row[:user_name]
|
122
|
+
end
|
123
|
+
if !exclude_masters or (exclude_masters and !master_admins.include?(row[:user_name]) and
|
124
|
+
!master_admins.include?(row[:user_id]) and
|
125
|
+
!@master_admin_users_id.include?(row[:user_id]))
|
126
|
+
if !exclude_routines or (exclude_routines and !row[:user_name].match?(/^routine\//) )
|
127
|
+
if exclude_command == '' or (exclude_command!='' and row[:command]!=exclude_command)
|
128
|
+
if st_command == '' or (st_command != '' and row[:command] == st_command)
|
129
|
+
if row[:bot_channel_id] == channel_id or channel_id == '' or row[:dest_channel_id] == channel_id
|
130
|
+
if row[:date] >= from and row[:date] <= to
|
131
|
+
count_users[row[:user_id]] ||= 0
|
132
|
+
count_users[row[:user_id]] += 1
|
133
|
+
if user=='' or (user!='' and row[:user_name] == user_name) or (user!='' and row[:user_id] == user_id)
|
134
|
+
rows << row.to_h
|
135
|
+
count_channels_dest[row[:dest_channel]] ||= 0
|
136
|
+
count_channels_dest[row[:dest_channel]] += 1
|
137
|
+
if monthly
|
138
|
+
rows_month[row[:date][0..6]] = 0 unless rows_month.key?(row[:date][0..6])
|
139
|
+
users_month[row[:date][0..6]] = [] unless users_month.key?(row[:date][0..6])
|
140
|
+
commands_month[row[:date][0..6]] = [] unless commands_month.key?(row[:date][0..6])
|
141
|
+
rows_month[row[:date][0..6]] += 1
|
142
|
+
users_month[row[:date][0..6]] << row[:user_id]
|
143
|
+
commands_month[row[:date][0..6]] << row[:command]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
total = rows.size
|
156
|
+
if exclude_masters
|
157
|
+
message << 'Excluding master admins'
|
158
|
+
end
|
159
|
+
if exclude_routines
|
160
|
+
message << 'Excluding routines'
|
161
|
+
end
|
162
|
+
if exclude_command != ''
|
163
|
+
message << "Excluding command #{exclude_command}"
|
164
|
+
end
|
165
|
+
if st_command != ''
|
166
|
+
message << "Including only command #{st_command}"
|
167
|
+
end
|
168
|
+
if user!=''
|
169
|
+
if user==from_user.id
|
170
|
+
message << "Bot stats for <@#{user}>"
|
171
|
+
else
|
172
|
+
message << "Showing only user <@#{user}>"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
if channel_id == ''
|
176
|
+
message << "*Total calls*: #{total} from #{from_short} to #{to_short}"
|
177
|
+
else
|
178
|
+
message << "*Total calls <##{channel_id}>*: #{total} from #{from_short} to #{to_short}"
|
179
|
+
end
|
180
|
+
unless count_users.size == 0 or total == 0 or user == ''
|
181
|
+
my_place = (count_users.sort_by(&:last).reverse.to_h.keys.index(user_id)+1)
|
182
|
+
message <<"\tYou are the *\# #{my_place}* of *#{count_users.size}* users"
|
183
|
+
end
|
184
|
+
if total > 0
|
185
|
+
if monthly
|
186
|
+
if on_dm_master
|
187
|
+
message << '*Totals by month / commands / users (%new)*'
|
188
|
+
else
|
189
|
+
message << '*Totals by month / commands*'
|
190
|
+
end
|
191
|
+
|
192
|
+
all_users = []
|
193
|
+
new_users = []
|
194
|
+
rows_month.each do |k,v|
|
195
|
+
if all_users.empty?
|
196
|
+
message_new_users = ''
|
197
|
+
else
|
198
|
+
new_users = (users_month[k]-all_users).uniq
|
199
|
+
message_new_users = "(#{new_users.size*100/users_month[k].uniq.size}%)"
|
200
|
+
end
|
201
|
+
all_users += users_month[k]
|
202
|
+
if on_dm_master
|
203
|
+
message << "\t#{k}: #{v} (#{(v.to_f*100/total).round(2)}%) / #{commands_month[k].uniq.size} / #{users_month[k].uniq.size} #{message_new_users}"
|
204
|
+
else
|
205
|
+
message << "\t#{k}: #{v} (#{(v.to_f*100/total).round(2)}%) / #{commands_month[k].uniq.size}"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
if channel_id == ''
|
211
|
+
message << "*SmartBots*"
|
212
|
+
channels = rows.bot_channel.uniq.sort
|
213
|
+
channels.each do |channel|
|
214
|
+
count = rows.count {|h| h.bot_channel==channel}
|
215
|
+
message << "\t#{channel}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
channels_dest_attachment = []
|
219
|
+
count_channels_dest = count_channels_dest.sort_by(&:last).reverse.to_h
|
220
|
+
if count_channels_dest.size > 10
|
221
|
+
message << "*From Channel* - #{count_channels_dest.size} (Top 10)"
|
222
|
+
else
|
223
|
+
message << "*From Channel* - #{count_channels_dest.size}"
|
224
|
+
end
|
225
|
+
|
226
|
+
count_channels_dest.keys[0..9].each do |ch|
|
227
|
+
message << "\t#{ch}: #{count_channels_dest[ch]} (#{(count_channels_dest[ch].to_f*100/total).round(2)}%)"
|
228
|
+
end
|
229
|
+
if count_channels_dest.size > 10 and all_data
|
230
|
+
count_channels_dest.each do |ch, value|
|
231
|
+
channels_dest_attachment << "\t#{ch}: #{value} (#{(value.to_f*100/total).round(2)}%)"
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
users_attachment = []
|
237
|
+
if user==''
|
238
|
+
users = rows.user_id.uniq.sort
|
239
|
+
if users.size > 10
|
240
|
+
message << "*Users* - #{users.size} (Top 10)"
|
241
|
+
else
|
242
|
+
message << "*Users* - #{users.size}"
|
243
|
+
end
|
244
|
+
count_user = {}
|
245
|
+
users.each do |user|
|
246
|
+
count = rows.count {|h| h.user_id==user}
|
247
|
+
count_user[user] = count
|
248
|
+
end
|
249
|
+
i = 0
|
250
|
+
count_user.sort_by {|k,v| -v}.each do |user, count|
|
251
|
+
i+=1
|
252
|
+
if i <= 10
|
253
|
+
message << "\t#{users_id_name[user]}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
254
|
+
end
|
255
|
+
if users.size > 10 and all_data
|
256
|
+
users_attachment << "\t#{users_id_name[user]}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
commands_attachment = []
|
261
|
+
|
262
|
+
if st_command == ''
|
263
|
+
commands = rows.command.uniq.sort
|
264
|
+
count_command = {}
|
265
|
+
commands.each do |command|
|
266
|
+
count = rows.count {|h| h.command==command}
|
267
|
+
count_command[command] = count
|
268
|
+
end
|
269
|
+
|
270
|
+
if commands.size > 10
|
271
|
+
message << "*Commands* - #{commands.size} (Top 10)"
|
272
|
+
else
|
273
|
+
message << "*Commands* - #{commands.size}"
|
274
|
+
end
|
275
|
+
|
276
|
+
i = 0
|
277
|
+
count_command.sort_by {|k,v| -v}.each do |command, count|
|
278
|
+
i+=1
|
279
|
+
if i <= 10
|
280
|
+
message << "\t#{command}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
281
|
+
end
|
282
|
+
if commands.size > 10 and all_data
|
283
|
+
commands_attachment << "\t#{command}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
message << "*Message type*"
|
289
|
+
types = rows.type_message.uniq.sort
|
290
|
+
types.each do |type|
|
291
|
+
count = rows.count {|h| h.type_message==type}
|
292
|
+
message << "\t#{type}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
293
|
+
end
|
294
|
+
|
295
|
+
if on_dm_master
|
296
|
+
message << "*Last activity*: #{rows[-1].date} #{rows[-1].bot_channel} #{rows[-1].type_message} #{rows[-1].user_name} #{rows[-1].command}"
|
297
|
+
end
|
298
|
+
if users_attachment.size>0
|
299
|
+
send_file(dest, "", 'users.txt', "", 'text/plain', "text", content: users_attachment.join("\n"))
|
300
|
+
end
|
301
|
+
if commands_attachment.size>0
|
302
|
+
send_file(dest, "", 'commands.txt', "", 'text/plain', "text", content: commands_attachment.join("\n"))
|
303
|
+
end
|
304
|
+
if channels_dest_attachment.size>0
|
305
|
+
send_file(dest, "", 'channels_dest.txt', "", 'text/plain', "text", content: channels_dest_attachment.join("\n"))
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
else
|
310
|
+
message<<"Only Master admin users on a private conversation with the bot can see this kind of bot stats."
|
311
|
+
end
|
312
|
+
respond "#{message.join("\n")}", dest
|
313
|
+
end
|
314
|
+
end
|
@@ -3,18 +3,16 @@ class SlackSmartBot
|
|
3
3
|
# helpadmin: `bot status`
|
4
4
|
# helpadmin: Displays the status of the bot
|
5
5
|
# helpadmin: If on master channel and admin user also it will display info about bots created
|
6
|
+
# helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
|
6
7
|
# helpadmin:
|
7
8
|
def bot_status(dest, user)
|
8
9
|
save_stats(__method__)
|
9
10
|
get_bots_created()
|
10
|
-
if
|
11
|
-
(!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
|
12
|
-
respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
|
13
|
-
else
|
11
|
+
if has_access?(__method__, user)
|
14
12
|
gems_remote = `gem list slack-smart-bot --remote`
|
15
13
|
version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
|
16
14
|
version_message = ""
|
17
|
-
if version_remote
|
15
|
+
if Gem::Version.new(version_remote) > Gem::Version.new(VERSION)
|
18
16
|
version_message = " There is a new available version: #{version_remote}."
|
19
17
|
end
|
20
18
|
require "socket"
|
@@ -1,12 +1,5 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
|
-
# help: ----------------------------------------------
|
4
|
-
# help: `Bye Bot`
|
5
|
-
# help: `Bye Smart`
|
6
|
-
# help: `Bye NAME_OF_THE_BOT`
|
7
|
-
# help: Also apart of Bye you can use _Bæ, Good Bye, Adiós, Ciao, Bless, Bless Bless, Adeu_
|
8
|
-
# help: Bot stops listening to you
|
9
|
-
# help:
|
10
3
|
def bye_bot(dest, from, display_name)
|
11
4
|
if @status == :on
|
12
5
|
save_stats(__method__)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def delete_announcement(user, message_id)
|
4
|
+
save_stats(__method__)
|
5
|
+
if has_access?(__method__, user)
|
6
|
+
if Thread.current[:typem] == :on_call
|
7
|
+
channel = Thread.current[:dchannel]
|
8
|
+
else
|
9
|
+
channel = Thread.current[:dest]
|
10
|
+
end
|
11
|
+
if File.exists?("#{config.path}/announcements/#{channel}.csv") and !@announcements.key?(channel)
|
12
|
+
t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
|
13
|
+
@announcements[channel] = t
|
14
|
+
end
|
15
|
+
found = false
|
16
|
+
message = ''
|
17
|
+
if @announcements.key?(channel) and @announcements[channel][:message_id].include?(message_id.to_i)
|
18
|
+
CSV.open("#{config.path}/announcements/#{channel}.csv", "w") do |csv|
|
19
|
+
@announcements[channel].each do |row|
|
20
|
+
if row[:message_id].to_i == message_id.to_i
|
21
|
+
message = row[:message]
|
22
|
+
row[:user_deleted] = user.name
|
23
|
+
end
|
24
|
+
csv << row
|
25
|
+
end
|
26
|
+
end
|
27
|
+
respond "The announcement has been deleted: #{message}"
|
28
|
+
else
|
29
|
+
respond "Sorry but I didn't find the message id #{message_id}. Call `see announcements` to see the ids."
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def delete_share(user, share_id)
|
4
|
+
save_stats(__method__)
|
5
|
+
if has_access?(__method__, user)
|
6
|
+
if Thread.current[:typem] == :on_call
|
7
|
+
channel = Thread.current[:dchannel]
|
8
|
+
else
|
9
|
+
channel = Thread.current[:dest]
|
10
|
+
end
|
11
|
+
if File.exists?("#{config.path}/shares/#{@channels_name[channel]}.csv") and !@shares.key?(@channels_name[channel])
|
12
|
+
t = CSV.table("#{config.path}/shares/#{@channels_name[channel]}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
|
13
|
+
@shares[@channels_name[channel]] = t
|
14
|
+
end
|
15
|
+
found = false
|
16
|
+
message = ''
|
17
|
+
if @shares[@channels_name[channel]][:share_id].include?(share_id.to_i)
|
18
|
+
CSV.open("#{config.path}/shares/#{@channels_name[channel]}.csv", "w") do |csv|
|
19
|
+
@shares[@channels_name[channel]].each do |row|
|
20
|
+
if row[:share_id].to_i == share_id.to_i
|
21
|
+
message = row[:condition]
|
22
|
+
row[:user_deleted] = user.name
|
23
|
+
end
|
24
|
+
csv << row
|
25
|
+
end
|
26
|
+
end
|
27
|
+
respond "The share has been deleted: #{message}"
|
28
|
+
else
|
29
|
+
respond "Sorry but I didn't find the share id #{share_id}. Call `see shares` to see all the ids."
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,21 +1,26 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
|
3
|
-
|
4
|
-
# help: `Hi Bot`
|
5
|
-
# help: `Hi Smart`
|
6
|
-
# help: `Hello Bot` `Hola Bot` `Hallo Bot` `What's up Bot` `Hey Bot` `Hæ Bot`
|
7
|
-
# help: `Hello THE_NAME_OF_THE_BOT`
|
8
|
-
# help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
|
9
|
-
# help: Bot starts listening to you
|
10
|
-
# help: After that if you want to avoid a single message to be treated by the smart bot, start the message by -
|
11
|
-
# help:
|
12
|
-
def hi_bot(user, dest, dchannel, from, display_name)
|
3
|
+
def hi_bot(user, dest, from, display_name)
|
13
4
|
if @status == :on
|
14
5
|
save_stats(__method__)
|
15
6
|
greetings = ["Hello", "Hallo", "Hi", "Hola", "What's up", "Hey", "Hæ"].sample
|
16
7
|
respond "#{greetings} #{display_name}", dest
|
8
|
+
if Thread.current[:typem] == :on_pub or Thread.current[:typem] == :on_pg
|
9
|
+
respond "You are on a channel where the SmartBot is just a member. You can only run general bot commands.\nCall `bot help` to see the commands you can use."
|
10
|
+
elsif Thread.current[:typem] == :on_extended
|
11
|
+
message = ["You are on an extended channel from <##{@channel_id}> so you can use all specific commands from that channel just adding !, !! or ^ before the command."]
|
12
|
+
message << "Call `bot help` to see the commands you can use."
|
13
|
+
respond message.join("\n")
|
14
|
+
elsif Thread.current[:typem] == :on_dm and Thread.current[:using_channel] == ''
|
15
|
+
respond "To start using the rules from a Bot channel call `use #CHANNEL`.\nAvailable SmartBots: <##{@bots_created.keys.join('>, <#')}>\nIf you want to call just one command from a specific channel: `#CHANNEL COMMAND`"
|
16
|
+
else
|
17
|
+
respond "You are on <##{@channel_id}> SmartBot channel. Call `bot help` to see all commands you can use or `bot rules` just to see the specific commands for this Bot channel."
|
18
|
+
end
|
17
19
|
if Thread.current[:using_channel]!=''
|
18
|
-
|
20
|
+
message = ["You are using rules from <##{Thread.current[:using_channel]}>"]
|
21
|
+
message << "If you want to change bot channel rules call `use #CHANNEL` or `stop using rules from <##{Thread.current[:using_channel]}>` to stop using rules from this channel."
|
22
|
+
message << "You can call a command from any other channel by calling `#CHANNEL COMMAND`" if Thread.current[:typem] == :on_dm
|
23
|
+
respond message.join("\n")
|
19
24
|
end
|
20
25
|
@listening[from] = {} unless @listening.key?(from)
|
21
26
|
if Thread.current[:on_thread]
|