slack-smart-bot 1.7.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -12
  3. data/lib/slack-smart-bot.rb +52 -43
  4. data/lib/slack-smart-bot_general_rules.rb +7 -4
  5. data/lib/slack-smart-bot_rules.rb +8 -6
  6. data/lib/slack/smart-bot/comm.rb +6 -1
  7. data/lib/slack/smart-bot/comm/ask.rb +12 -5
  8. data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
  9. data/lib/slack/smart-bot/comm/event_hello.rb +30 -0
  10. data/lib/slack/smart-bot/comm/get_channel_members.rb +8 -0
  11. data/lib/slack/smart-bot/comm/get_channels.rb +20 -0
  12. data/lib/slack/smart-bot/comm/get_user_info.rb +16 -0
  13. data/lib/slack/smart-bot/comm/react.rb +21 -8
  14. data/lib/slack/smart-bot/comm/respond.rb +11 -6
  15. data/lib/slack/smart-bot/comm/send_file.rb +1 -1
  16. data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
  17. data/lib/slack/smart-bot/comm/send_msg_user.rb +4 -4
  18. data/lib/slack/smart-bot/comm/unreact.rb +29 -0
  19. data/lib/slack/smart-bot/commands.rb +3 -1
  20. data/lib/slack/smart-bot/commands/general/bot_help.rb +16 -3
  21. data/lib/slack/smart-bot/commands/general/bot_stats.rb +313 -0
  22. data/lib/slack/smart-bot/commands/general/bot_status.rb +1 -1
  23. data/lib/slack/smart-bot/commands/general/bye_bot.rb +1 -1
  24. data/lib/slack/smart-bot/commands/general/hi_bot.rb +1 -1
  25. data/lib/slack/smart-bot/commands/general/use_rules.rb +2 -6
  26. data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
  27. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +65 -33
  28. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +33 -9
  29. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +3 -7
  30. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
  31. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +9 -2
  32. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
  33. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
  34. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +52 -21
  35. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +5 -5
  36. data/lib/slack/smart-bot/commands/on_bot/repl.rb +50 -18
  37. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +34 -9
  38. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +2 -3
  39. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -1
  40. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +27 -9
  41. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +14 -1
  42. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -3
  43. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -1
  44. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +41 -0
  45. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +4 -8
  46. data/lib/slack/smart-bot/listen.rb +6 -5
  47. data/lib/slack/smart-bot/process.rb +227 -186
  48. data/lib/slack/smart-bot/process_first.rb +104 -87
  49. data/lib/slack/smart-bot/treat_message.rb +116 -52
  50. data/lib/slack/smart-bot/utils.rb +2 -0
  51. data/lib/slack/smart-bot/utils/answer.rb +18 -0
  52. data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
  53. data/lib/slack/smart-bot/utils/build_help.rb +57 -5
  54. data/lib/slack/smart-bot/utils/create_routine_thread.rb +48 -8
  55. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
  56. data/lib/slack/smart-bot/utils/get_help.rb +79 -17
  57. data/lib/slack/smart-bot/utils/save_stats.rb +21 -8
  58. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
  59. data/whats_new.txt +18 -0
  60. metadata +22 -12
  61. data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -135
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-smart-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.14'
19
+ version: '0.17'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.14.6
22
+ version: 0.17.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.14'
29
+ version: '0.17'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.14.6
32
+ version: 0.17.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: nice_http
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +81,7 @@ dependencies:
81
81
  version: '1'
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 1.1.0
84
+ version: 1.3.0
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,7 +91,7 @@ dependencies:
91
91
  version: '1'
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 1.1.0
94
+ version: 1.3.0
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: rspec
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -130,19 +130,26 @@ files:
130
130
  - lib/slack/smart-bot/comm.rb
131
131
  - lib/slack/smart-bot/comm/ask.rb
132
132
  - lib/slack/smart-bot/comm/dont_understand.rb
133
+ - lib/slack/smart-bot/comm/event_hello.rb
134
+ - lib/slack/smart-bot/comm/get_channel_members.rb
135
+ - lib/slack/smart-bot/comm/get_channels.rb
136
+ - lib/slack/smart-bot/comm/get_user_info.rb
133
137
  - lib/slack/smart-bot/comm/react.rb
134
138
  - lib/slack/smart-bot/comm/respond.rb
135
139
  - lib/slack/smart-bot/comm/respond_direct.rb
136
140
  - lib/slack/smart-bot/comm/send_file.rb
137
141
  - lib/slack/smart-bot/comm/send_msg_channel.rb
138
142
  - lib/slack/smart-bot/comm/send_msg_user.rb
143
+ - lib/slack/smart-bot/comm/unreact.rb
139
144
  - lib/slack/smart-bot/commands.rb
140
145
  - lib/slack/smart-bot/commands/general/bot_help.rb
146
+ - lib/slack/smart-bot/commands/general/bot_stats.rb
141
147
  - lib/slack/smart-bot/commands/general/bot_status.rb
142
148
  - lib/slack/smart-bot/commands/general/bye_bot.rb
143
149
  - lib/slack/smart-bot/commands/general/hi_bot.rb
144
150
  - lib/slack/smart-bot/commands/general/stop_using_rules.rb
145
151
  - lib/slack/smart-bot/commands/general/use_rules.rb
152
+ - lib/slack/smart-bot/commands/general/whats_new.rb
146
153
  - lib/slack/smart-bot/commands/on_bot/add_shortcut.rb
147
154
  - lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb
148
155
  - lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb
@@ -154,7 +161,6 @@ files:
154
161
  - lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb
155
162
  - lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb
156
163
  - lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb
157
- - lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb
158
164
  - lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb
159
165
  - lib/slack/smart-bot/commands/on_bot/delete_repl.rb
160
166
  - lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb
@@ -168,12 +174,15 @@ files:
168
174
  - lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb
169
175
  - lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb
170
176
  - lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb
177
+ - lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb
171
178
  - lib/slack/smart-bot/commands/on_master/create_bot.rb
172
179
  - lib/slack/smart-bot/listen.rb
173
180
  - lib/slack/smart-bot/process.rb
174
181
  - lib/slack/smart-bot/process_first.rb
175
182
  - lib/slack/smart-bot/treat_message.rb
176
183
  - lib/slack/smart-bot/utils.rb
184
+ - lib/slack/smart-bot/utils/answer.rb
185
+ - lib/slack/smart-bot/utils/answer_delete.rb
177
186
  - lib/slack/smart-bot/utils/build_help.rb
178
187
  - lib/slack/smart-bot/utils/create_routine_thread.rb
179
188
  - lib/slack/smart-bot/utils/get_bots_created.rb
@@ -189,6 +198,7 @@ files:
189
198
  - lib/slack/smart-bot/utils/update_routines.rb
190
199
  - lib/slack/smart-bot/utils/update_rules_imported.rb
191
200
  - lib/slack/smart-bot/utils/update_shortcuts_file.rb
201
+ - whats_new.txt
192
202
  homepage: https://github.com/MarioRuiz/slack-smart-bot
193
203
  licenses:
194
204
  - MIT
@@ -208,8 +218,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
218
  - !ruby/object:Gem::Version
209
219
  version: '0'
210
220
  requirements: []
211
- rubygems_version: 3.0.3
212
- signing_key:
221
+ rubygems_version: 3.2.3
222
+ signing_key:
213
223
  specification_version: 4
214
224
  summary: Create a Slack bot that is smart and so easy to expand, create new bots on
215
225
  demand, run ruby code on chat, create shortcuts...
@@ -1,135 +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 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) 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
-
50
- Dir["#{config.stats_path}.*.log"].sort.each do |file|
51
- if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
52
- CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
53
- row[:date] = row[:date].to_s
54
- if !exclude_masters or (exclude_masters and !config.masters.include?(row[:user_name]))
55
- if user=='' or (user!='' and row[:user_id] == user)
56
- if exclude_command == '' or (exclude_command!='' and row[:command]!=exclude_command)
57
- if row[:bot_channel_id] == channel_id or channel_id == ''
58
- if row[:date] >= from and row[:date] <= to
59
- rows << row.to_h
60
- if monthly
61
- rows_month[row[:date][0..6]] = 0 unless rows_month.key?(row[:date][0..6])
62
- rows_month[row[:date][0..6]] += 1
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
71
- end
72
-
73
- total = rows.size
74
- if exclude_masters
75
- message << 'Excluding master admins'
76
- end
77
- if exclude_command != ''
78
- message << "Excluding command #{exclude_command}"
79
- end
80
- if user!=''
81
- message << "Showing only user <@#{user}>"
82
- end
83
- if channel_id == ''
84
- message << "*Total calls*: #{total} from #{from_short} to #{to_short}"
85
- else
86
- message << "*Total calls <##{channel_id}>*: #{total} from #{from_short} to #{to_short}"
87
- end
88
- if total > 0
89
- if monthly
90
- message << '*Totals by month*'
91
- rows_month.each do |k,v|
92
- message << "\t#{k}: #{v} (#{(v.to_f*100/total).round(2)}%)"
93
- end
94
- end
95
-
96
- if channel_id == ''
97
- message << "*Channels*"
98
- channels = rows.bot_channel.uniq.sort
99
- channels.each do |channel|
100
- count = rows.count {|h| h.bot_channel==channel}
101
- message << "\t#{channel}: #{count} (#{(count.to_f*100/total).round(2)}%)"
102
- end
103
- end
104
- if user==''
105
- message << "*Users*"
106
- users = rows.user_name.uniq.sort
107
- users.each do |user|
108
- count = rows.count {|h| h.user_name==user}
109
- message << "\t#{user}: #{count} (#{(count.to_f*100/total).round(2)}%)"
110
- end
111
- end
112
-
113
- message << "*Commands*"
114
- commands = rows.command.uniq.sort
115
- commands.each do |command|
116
- count = rows.count {|h| h.command==command}
117
- message << "\t#{command}: #{count} (#{(count.to_f*100/total).round(2)}%)"
118
- end
119
-
120
- message << "*Message type*"
121
- types = rows.type_message.uniq.sort
122
- types.each do |type|
123
- count = rows.count {|h| h.type_message==type}
124
- message << "\t#{type}: #{count} (#{(count.to_f*100/total).round(2)}%)"
125
- end
126
- message << "*Last activity*: #{rows[-1].date} #{rows[-1].bot_channel} #{rows[-1].type_message} #{rows[-1].user_name} #{rows[-1].command}"
127
- end
128
-
129
- end
130
- else
131
- message<<"Only Master admin users on a private conversation with the bot can see the bot stats."
132
- end
133
- respond "#{message.join("\n")}", dest
134
- end
135
- end