slack-smart-bot 1.8.0 → 1.8.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19ab121009af799ef4d1338e6b274c3212aa3fb9eed9098ab32b4d445e620a14
|
4
|
+
data.tar.gz: d9d16f6eb8de9fe372865e56f4f4e22ae2b10acdd55918f2d17a38a25f7111d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94f2a3b0f5f26c1ece8f9d9241b89e26714e6565104a1591c2f0ab0bac0bb9273d2e64e5a988fde4c18cdea0e89a8bcb98d5ee1f36ab22756b30d2b3cf61fff
|
7
|
+
data.tar.gz: 2dadb23423038f6141e0f8fdf540b15ec5da160058eb7d286e7fee9b6b7672c58d348f33221848b472997a42818283ea76cb67748ad1d2437784ac0a61f41b3d
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -177,10 +177,20 @@ class SlackSmartBot
|
|
177
177
|
get_rules_imported()
|
178
178
|
|
179
179
|
begin
|
180
|
+
#todo: take in consideration the case that the value supplied on config.masters and config.admins are the ids and not the user names
|
180
181
|
@admin_users_id = []
|
182
|
+
@master_admin_users_id = []
|
181
183
|
config.admins.each do |au|
|
182
184
|
user_info = client.web_client.users_info(user: "@#{au}")
|
183
185
|
@admin_users_id << user_info.user.id
|
186
|
+
if config.masters.include?(au)
|
187
|
+
@master_admin_users_id << user_info.user.id
|
188
|
+
end
|
189
|
+
sleep 1
|
190
|
+
end
|
191
|
+
(config.masters-config.admins).each do |au|
|
192
|
+
user_info = client.web_client.users_info(user: "@#{au}")
|
193
|
+
@master_admin_users_id << user_info.user.id
|
184
194
|
sleep 1
|
185
195
|
end
|
186
196
|
rescue Slack::Web::Api::Errors::TooManyRequestsError
|
@@ -2,7 +2,7 @@ class SlackSmartBot
|
|
2
2
|
# list of available emojis: https://www.webfx.com/tools/emoji-cheat-sheet/
|
3
3
|
# react(:thumbsup)
|
4
4
|
def react(emoji, parent=false)
|
5
|
-
if parent
|
5
|
+
if parent or Thread.current[:ts].to_s == ''
|
6
6
|
ts = Thread.current[:thread_ts]
|
7
7
|
else
|
8
8
|
ts = Thread.current[:ts]
|
@@ -32,14 +32,10 @@ class SlackSmartBot
|
|
32
32
|
message = ["You need to set stats to true to generate the stats when running the bot instance."]
|
33
33
|
end
|
34
34
|
save_stats(__method__)
|
35
|
-
if config.masters.include?(from_user) and typem==:on_dm #master admin user
|
35
|
+
if (config.masters.include?(from_user) or @master_admin_users_id.include?(from_user)) and typem==:on_dm #master admin user
|
36
36
|
if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
|
37
37
|
message<<'No stats'
|
38
38
|
else
|
39
|
-
if user!=''
|
40
|
-
user_info = client.web_client.users_info(user: user)
|
41
|
-
user_name = user_info.user.name
|
42
|
-
end
|
43
39
|
from = "#{Time.now.strftime("%Y-%m")}-01" if from == ''
|
44
40
|
to = "#{Time.now.strftime("%Y-%m-%d")}" if to == ''
|
45
41
|
from_short = from
|
@@ -52,13 +48,56 @@ class SlackSmartBot
|
|
52
48
|
rows_month = {}
|
53
49
|
users_month = {}
|
54
50
|
commands_month = {}
|
55
|
-
|
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
|
+
|
56
91
|
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
57
92
|
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
58
93
|
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
59
94
|
row[:date] = row[:date].to_s
|
60
|
-
|
61
|
-
|
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)
|
62
101
|
if exclude_command == '' or (exclude_command!='' and row[:command]!=exclude_command)
|
63
102
|
if row[:bot_channel_id] == channel_id or channel_id == ''
|
64
103
|
if row[:date] >= from and row[:date] <= to
|
@@ -68,7 +107,7 @@ class SlackSmartBot
|
|
68
107
|
users_month[row[:date][0..6]] = [] unless users_month.key?(row[:date][0..6])
|
69
108
|
commands_month[row[:date][0..6]] = [] unless commands_month.key?(row[:date][0..6])
|
70
109
|
rows_month[row[:date][0..6]] += 1
|
71
|
-
users_month[row[:date][0..6]] << row[:
|
110
|
+
users_month[row[:date][0..6]] << row[:user_id]
|
72
111
|
commands_month[row[:date][0..6]] << row[:command]
|
73
112
|
end
|
74
113
|
end
|
@@ -79,7 +118,6 @@ class SlackSmartBot
|
|
79
118
|
end
|
80
119
|
end
|
81
120
|
end
|
82
|
-
|
83
121
|
total = rows.size
|
84
122
|
if exclude_masters
|
85
123
|
message << 'Excluding master admins'
|
@@ -111,7 +149,7 @@ class SlackSmartBot
|
|
111
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}"
|
112
150
|
end
|
113
151
|
end
|
114
|
-
|
152
|
+
|
115
153
|
if channel_id == ''
|
116
154
|
message << "*Channels*"
|
117
155
|
channels = rows.bot_channel.uniq.sort
|
@@ -121,21 +159,25 @@ class SlackSmartBot
|
|
121
159
|
end
|
122
160
|
end
|
123
161
|
if user==''
|
124
|
-
users = rows.
|
162
|
+
users = rows.user_id.uniq.sort
|
125
163
|
message << "*Users* - #{users.size}"
|
164
|
+
count_user = {}
|
126
165
|
users.each do |user|
|
127
|
-
count = rows.count {|h| h.
|
128
|
-
|
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)}%)"
|
129
171
|
end
|
130
172
|
end
|
131
|
-
|
173
|
+
|
132
174
|
commands = rows.command.uniq.sort
|
133
175
|
message << "*Commands* - #{commands.size}"
|
134
176
|
commands.each do |command|
|
135
177
|
count = rows.count {|h| h.command==command}
|
136
178
|
message << "\t#{command}: #{count} (#{(count.to_f*100/total).round(2)}%)"
|
137
179
|
end
|
138
|
-
|
180
|
+
|
139
181
|
message << "*Message type*"
|
140
182
|
types = rows.type_message.uniq.sort
|
141
183
|
types.each do |type|
|
@@ -144,7 +186,6 @@ class SlackSmartBot
|
|
144
186
|
end
|
145
187
|
message << "*Last activity*: #{rows[-1].date} #{rows[-1].bot_channel} #{rows[-1].type_message} #{rows[-1].user_name} #{rows[-1].command}"
|
146
188
|
end
|
147
|
-
|
148
189
|
end
|
149
190
|
else
|
150
191
|
message<<"Only Master admin users on a private conversation with the bot can see the bot stats."
|
@@ -117,7 +117,8 @@ class SlackSmartBot
|
|
117
117
|
begin
|
118
118
|
#todo: when changed @questions user_id then move user_info inside the ifs to avoid calling it when not necessary
|
119
119
|
user_info = client.web_client.users_info(user: data.user)
|
120
|
-
user_info.user.id = data.user #todo: remove this line when slack issue with Wxxxx Uxxxx fixed
|
120
|
+
#user_info.user.id = data.user #todo: remove this line when slack issue with Wxxxx Uxxxx fixed
|
121
|
+
data.user = user_info.user.id #todo: remove this line when slack issue with Wxxxx Uxxxx fixed
|
121
122
|
if @questions.key?(user_info.user.name)
|
122
123
|
if data.text.match?(/^\s*(Bye|Bæ|Good\sBye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s(#{@salutations.join("|")})\s*$/i)
|
123
124
|
@questions.delete(user_info.user.name)
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-smart-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.15.0
|
20
17
|
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '0.15'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.15.1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.15.0
|
30
27
|
- - "~>"
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '0.15'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.15.1
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: nice_http
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|