slack-smart-bot 1.8.2 → 1.9.1
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 +18 -11
- data/lib/slack-smart-bot.rb +43 -44
- data/lib/slack-smart-bot_rules.rb +6 -6
- data/lib/slack/smart-bot/comm.rb +5 -1
- data/lib/slack/smart-bot/comm/ask.rb +12 -5
- data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
- data/lib/slack/smart-bot/comm/event_hello.rb +30 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +8 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +20 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +16 -0
- data/lib/slack/smart-bot/comm/react.rb +21 -8
- data/lib/slack/smart-bot/comm/respond.rb +10 -5
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
- data/lib/slack/smart-bot/comm/send_msg_user.rb +4 -4
- data/lib/slack/smart-bot/comm/unreact.rb +21 -8
- data/lib/slack/smart-bot/commands.rb +3 -1
- data/lib/slack/smart-bot/commands/general/bot_help.rb +16 -3
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +313 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +1 -1
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +1 -1
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +1 -1
- data/lib/slack/smart-bot/commands/general/use_rules.rb +2 -6
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +65 -33
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +3 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +8 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +52 -21
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +5 -5
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +50 -18
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +34 -9
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -1
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +27 -9
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +14 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +41 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +4 -8
- data/lib/slack/smart-bot/listen.rb +6 -5
- data/lib/slack/smart-bot/process.rb +227 -188
- data/lib/slack/smart-bot/process_first.rb +104 -87
- data/lib/slack/smart-bot/treat_message.rb +98 -38
- data/lib/slack/smart-bot/utils.rb +2 -0
- 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 +11 -2
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +79 -17
- data/lib/slack/smart-bot/utils/save_stats.rb +21 -8
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/whats_new.txt +18 -0
- metadata +21 -12
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -1,195 +0,0 @@
|
|
1
|
-
class SlackSmartBot
|
2
|
-
# helpadmin: ----------------------------------------------
|
3
|
-
# helpadmin: `bot stats`
|
4
|
-
# helpadmin: `bot stats USER_NAME`
|
5
|
-
# helpadmin: `bot stats exclude masters`
|
6
|
-
# helpadmin: `bot stats from YYYY/MM/DD`
|
7
|
-
# helpadmin: `bot stats from YYYY/MM/DD to YYYY/MM/DD`
|
8
|
-
# helpadmin: `bot stats CHANNEL`
|
9
|
-
# helpadmin: `bot stats CHANNEL from YYYY/MM/DD`
|
10
|
-
# helpadmin: `bot stats CHANNEL from YYYY/MM/DD to YYYY/MM/DD`
|
11
|
-
# helpadmin: `bot stats USER_NAME from YYYY/MM/DD to YYYY/MM/DD`
|
12
|
-
# helpadmin: `bot stats CHANNEL USER_NAME from YYYY/MM/DD to YYYY/MM/DD`
|
13
|
-
# helpadmin: `bot stats CHANNEL exclude masters from YYYY/MM/DD to YYYY/MM/DD`
|
14
|
-
# helpadmin: `bot stats today`
|
15
|
-
# helpadmin: `bot stats exclude COMMAND_ID`
|
16
|
-
# helpadmin: `bot stats monthly`
|
17
|
-
# helpadmin: To see the bot stats
|
18
|
-
# 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
|
19
|
-
# helpadmin: You need to set stats to true to generate the stats when running the bot instance.
|
20
|
-
# helpadmin: Examples:
|
21
|
-
# helpadmin: _bot stats #sales_
|
22
|
-
# helpadmin: _bot stats @peter.wind_
|
23
|
-
# helpadmin: _bot stats #sales from 2019/12/15 to 2019/12/31_
|
24
|
-
# helpadmin: _bot stats #sales today_
|
25
|
-
# helpadmin: _bot stats #sales from 2020-01-01 monthly_
|
26
|
-
# helpadmin:
|
27
|
-
def bot_stats(dest, from_user, typem, channel_id, from, to, user, exclude_masters, exclude_command, monthly)
|
28
|
-
require 'csv'
|
29
|
-
if config.stats
|
30
|
-
message = []
|
31
|
-
else
|
32
|
-
message = ["You need to set stats to true to generate the stats when running the bot instance."]
|
33
|
-
end
|
34
|
-
save_stats(__method__)
|
35
|
-
if (config.masters.include?(from_user) or @master_admin_users_id.include?(from_user)) and typem==:on_dm #master admin user
|
36
|
-
if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
|
37
|
-
message<<'No stats'
|
38
|
-
else
|
39
|
-
from = "#{Time.now.strftime("%Y-%m")}-01" if from == ''
|
40
|
-
to = "#{Time.now.strftime("%Y-%m-%d")}" if to == ''
|
41
|
-
from_short = from
|
42
|
-
to_short = to
|
43
|
-
from_file = from[0..3] + '-' + from[5..6]
|
44
|
-
to_file = to[0..3] + '-' + to[5..6]
|
45
|
-
from+= " 00:00:00 +0000"
|
46
|
-
to+= " 23:59:59 +0000"
|
47
|
-
rows = []
|
48
|
-
rows_month = {}
|
49
|
-
users_month = {}
|
50
|
-
commands_month = {}
|
51
|
-
users_id_name = {}
|
52
|
-
users_name_id = {}
|
53
|
-
|
54
|
-
# to translate global and enterprise users since sometimes was returning different names/ids
|
55
|
-
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
56
|
-
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
57
|
-
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
58
|
-
unless users_id_name.key?(row[:user_id])
|
59
|
-
users_id_name[row[:user_id]] = row[:user_name]
|
60
|
-
end
|
61
|
-
unless users_name_id.key?(row[:user_name])
|
62
|
-
users_name_id[row[:user_name]] = row[:user_id]
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
if user!=''
|
70
|
-
user_info = client.web_client.users_info(user: user)
|
71
|
-
if users_id_name.key?(user_info.user.id)
|
72
|
-
user_name = users_id_name[user_info.user.id]
|
73
|
-
else
|
74
|
-
user_name = user_info.user.name
|
75
|
-
end
|
76
|
-
if users_name_id.key?(user_info.user.name)
|
77
|
-
user_id = users_name_id[user_info.user.name]
|
78
|
-
else
|
79
|
-
user_id = user_info.user.id
|
80
|
-
end
|
81
|
-
end
|
82
|
-
master_admins = config.masters.dup
|
83
|
-
config.masters.each do |u|
|
84
|
-
if users_id_name.key?(u)
|
85
|
-
master_admins << users_id_name[u]
|
86
|
-
elsif users_name_id.key?(u)
|
87
|
-
master_admins << users_name_id[u]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
92
|
-
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
93
|
-
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
94
|
-
row[:date] = row[:date].to_s
|
95
|
-
row[:user_name] = users_id_name[row[:user_id]]
|
96
|
-
row[:user_id] = users_name_id[row[:user_name]]
|
97
|
-
if !exclude_masters or (exclude_masters and !master_admins.include?(row[:user_name]) and
|
98
|
-
!master_admins.include?(row[:user_id]) and
|
99
|
-
!@master_admin_users_id.include?(row[:user_id]))
|
100
|
-
if user=='' or (user!='' and row[:user_name] == user_name) or (user!='' and row[:user_id] == user_id)
|
101
|
-
if exclude_command == '' or (exclude_command!='' and row[:command]!=exclude_command)
|
102
|
-
if row[:bot_channel_id] == channel_id or channel_id == ''
|
103
|
-
if row[:date] >= from and row[:date] <= to
|
104
|
-
rows << row.to_h
|
105
|
-
if monthly
|
106
|
-
rows_month[row[:date][0..6]] = 0 unless rows_month.key?(row[:date][0..6])
|
107
|
-
users_month[row[:date][0..6]] = [] unless users_month.key?(row[:date][0..6])
|
108
|
-
commands_month[row[:date][0..6]] = [] unless commands_month.key?(row[:date][0..6])
|
109
|
-
rows_month[row[:date][0..6]] += 1
|
110
|
-
users_month[row[:date][0..6]] << row[:user_id]
|
111
|
-
commands_month[row[:date][0..6]] << row[:command]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
total = rows.size
|
122
|
-
if exclude_masters
|
123
|
-
message << 'Excluding master admins'
|
124
|
-
end
|
125
|
-
if exclude_command != ''
|
126
|
-
message << "Excluding command #{exclude_command}"
|
127
|
-
end
|
128
|
-
if user!=''
|
129
|
-
message << "Showing only user <@#{user}>"
|
130
|
-
end
|
131
|
-
if channel_id == ''
|
132
|
-
message << "*Total calls*: #{total} from #{from_short} to #{to_short}"
|
133
|
-
else
|
134
|
-
message << "*Total calls <##{channel_id}>*: #{total} from #{from_short} to #{to_short}"
|
135
|
-
end
|
136
|
-
if total > 0
|
137
|
-
if monthly
|
138
|
-
message << '*Totals by month / commands / users (%new)*'
|
139
|
-
all_users = []
|
140
|
-
new_users = []
|
141
|
-
rows_month.each do |k,v|
|
142
|
-
if all_users.empty?
|
143
|
-
message_new_users = ''
|
144
|
-
else
|
145
|
-
new_users = (users_month[k]-all_users).uniq
|
146
|
-
message_new_users = "(#{new_users.size*100/users_month[k].uniq.size}%)"
|
147
|
-
end
|
148
|
-
all_users += users_month[k]
|
149
|
-
message << "\t#{k}: #{v} (#{(v.to_f*100/total).round(2)}%) / #{commands_month[k].uniq.size} / #{users_month[k].uniq.size} #{message_new_users}"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
if channel_id == ''
|
154
|
-
message << "*Channels*"
|
155
|
-
channels = rows.bot_channel.uniq.sort
|
156
|
-
channels.each do |channel|
|
157
|
-
count = rows.count {|h| h.bot_channel==channel}
|
158
|
-
message << "\t#{channel}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
if user==''
|
162
|
-
users = rows.user_id.uniq.sort
|
163
|
-
message << "*Users* - #{users.size}"
|
164
|
-
count_user = {}
|
165
|
-
users.each do |user|
|
166
|
-
count = rows.count {|h| h.user_id==user}
|
167
|
-
count_user[user] = count
|
168
|
-
end
|
169
|
-
count_user.sort_by {|k,v| -v}.each do |user, count|
|
170
|
-
message << "\t#{users_id_name[user]}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
commands = rows.command.uniq.sort
|
175
|
-
message << "*Commands* - #{commands.size}"
|
176
|
-
commands.each do |command|
|
177
|
-
count = rows.count {|h| h.command==command}
|
178
|
-
message << "\t#{command}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
179
|
-
end
|
180
|
-
|
181
|
-
message << "*Message type*"
|
182
|
-
types = rows.type_message.uniq.sort
|
183
|
-
types.each do |type|
|
184
|
-
count = rows.count {|h| h.type_message==type}
|
185
|
-
message << "\t#{type}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
186
|
-
end
|
187
|
-
message << "*Last activity*: #{rows[-1].date} #{rows[-1].bot_channel} #{rows[-1].type_message} #{rows[-1].user_name} #{rows[-1].command}"
|
188
|
-
end
|
189
|
-
end
|
190
|
-
else
|
191
|
-
message<<"Only Master admin users on a private conversation with the bot can see the bot stats."
|
192
|
-
end
|
193
|
-
respond "#{message.join("\n")}", dest
|
194
|
-
end
|
195
|
-
end
|