slack-smart-bot 1.8.2 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -11
  3. data/lib/slack-smart-bot.rb +43 -44
  4. data/lib/slack-smart-bot_rules.rb +6 -6
  5. data/lib/slack/smart-bot/comm.rb +5 -1
  6. data/lib/slack/smart-bot/comm/ask.rb +12 -5
  7. data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
  8. data/lib/slack/smart-bot/comm/event_hello.rb +30 -0
  9. data/lib/slack/smart-bot/comm/get_channel_members.rb +8 -0
  10. data/lib/slack/smart-bot/comm/get_channels.rb +20 -0
  11. data/lib/slack/smart-bot/comm/get_user_info.rb +16 -0
  12. data/lib/slack/smart-bot/comm/react.rb +21 -8
  13. data/lib/slack/smart-bot/comm/respond.rb +10 -5
  14. data/lib/slack/smart-bot/comm/send_msg_channel.rb +2 -2
  15. data/lib/slack/smart-bot/comm/send_msg_user.rb +4 -4
  16. data/lib/slack/smart-bot/comm/unreact.rb +21 -8
  17. data/lib/slack/smart-bot/commands.rb +3 -1
  18. data/lib/slack/smart-bot/commands/general/bot_help.rb +16 -3
  19. data/lib/slack/smart-bot/commands/general/bot_stats.rb +313 -0
  20. data/lib/slack/smart-bot/commands/general/bot_status.rb +1 -1
  21. data/lib/slack/smart-bot/commands/general/bye_bot.rb +1 -1
  22. data/lib/slack/smart-bot/commands/general/hi_bot.rb +1 -1
  23. data/lib/slack/smart-bot/commands/general/use_rules.rb +2 -6
  24. data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
  25. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +65 -33
  26. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +3 -7
  27. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +1 -0
  28. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +8 -2
  29. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +1 -0
  30. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +1 -1
  31. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +52 -21
  32. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +5 -5
  33. data/lib/slack/smart-bot/commands/on_bot/repl.rb +50 -18
  34. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +34 -9
  35. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +2 -3
  36. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +1 -1
  37. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +27 -9
  38. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +14 -1
  39. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -3
  40. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -1
  41. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +41 -0
  42. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +4 -8
  43. data/lib/slack/smart-bot/listen.rb +6 -5
  44. data/lib/slack/smart-bot/process.rb +227 -188
  45. data/lib/slack/smart-bot/process_first.rb +104 -87
  46. data/lib/slack/smart-bot/treat_message.rb +98 -38
  47. data/lib/slack/smart-bot/utils.rb +2 -0
  48. data/lib/slack/smart-bot/utils/answer.rb +18 -0
  49. data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
  50. data/lib/slack/smart-bot/utils/build_help.rb +57 -5
  51. data/lib/slack/smart-bot/utils/create_routine_thread.rb +11 -2
  52. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
  53. data/lib/slack/smart-bot/utils/get_help.rb +79 -17
  54. data/lib/slack/smart-bot/utils/save_stats.rb +21 -8
  55. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
  56. data/whats_new.txt +18 -0
  57. metadata +21 -12
  58. data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d35053e4911d77ae985b29fbd1564636eb0d078b38106601c2e126a401a03d5b
4
- data.tar.gz: d5aadeedbdbe0c7a6528cbeac1f1bb0990d88cf93fdb9f0a085cf9be9ec17c2d
3
+ metadata.gz: 0566062f8e9af6bc724b505bc1ee0821027e93bf5302a36781a0506e66d2cdf7
4
+ data.tar.gz: 3d10378e17c6dc94f70784c5a68854fbdac9c4d6e752f5616728f27b7c4ab706
5
5
  SHA512:
6
- metadata.gz: 19ed3708f96befda1f755358eb847facba2afaa62f6a92e08e7f68143e51659ef75ab7ef925c0d07e9a2b02072dcd02ddeda89697855363e50e84dc3f1970af6
7
- data.tar.gz: d40d1ac18d32074994c2c4ed3b835b74ada4e9ff46bbb5a7122df0f18f1b44eb777a6351ddaad3dd00b8bc129dbb62aee75572b9f3fe625e4fa972add2083107
6
+ metadata.gz: 4cc5736de96995f20e0530a54c2f0ddf5fdc8dee3288e6f04bc938ef446b869508fc003f58b8ed030b89bdab37959aff6ca1e0d59e556df581ca0c5a2abc5b01
7
+ data.tar.gz: 929465da66b5ca3660b1bad1b360d7badc391d43596fcbe834a8e69f0aca3decd0b970b67dfbb063df8d77cb0c50b47d4b2b4ed84b99663719532406958b6b34
data/README.md CHANGED
@@ -10,6 +10,8 @@ The main scope of this ruby gem is to be used internally in your company so team
10
10
 
11
11
  slack-smart-bot can create bots on demand, create shortcuts, run ruby code... just on a chat channel, you can access it just from your mobile phone if you want and run those tests you forgot to run, get the results, restart a server... no limits.
12
12
 
13
+ ![](slack.png)
14
+
13
15
  # Table of Contents
14
16
 
15
17
  - [Installation and configuration](#installation-and-configuration)
@@ -114,12 +116,12 @@ def rules(user, command, processed, dest)
114
116
  # help: it will sleep the bot for 10 seconds
115
117
  # help:
116
118
  when /^go\sto\ssleep/i
117
- unless @questions.keys.include?(from)
119
+ if answer.empty?
118
120
  ask "do you want me to take a siesta?"
119
121
  else
120
- case @questions[from]
122
+ case answer
121
123
  when /yes/i, /yep/i, /sure/i
122
- @questions.delete(from)
124
+ answer_delete
123
125
  respond "I'll be sleeping for 10 secs... just for you"
124
126
  respond "zZzzzzzZZZZZZzzzzzzz!"
125
127
  react :sleeping
@@ -127,11 +129,11 @@ def rules(user, command, processed, dest)
127
129
  unreact :sleeping
128
130
  react :sunny
129
131
  when /no/i, /nope/i, /cancel/i
130
- @questions.delete(from)
132
+ answer_delete
131
133
  respond "Thanks, I'm happy to be awake"
132
134
  else
133
135
  respond "I don't understand"
134
- ask "are you sure do you want me to sleep? (yes or no)"
136
+ ask "are you sure you want me to sleep? (yes or no)"
135
137
  end
136
138
  end
137
139
 
@@ -201,7 +203,7 @@ Examples run a command on demand:
201
203
  >**_Peter>_** `^echo Example`
202
204
  >. . . . . . . . .**_Smart-Bot>_** `Example`
203
205
 
204
- Also you can always call the Smart Bot from any channel, even from channels without a running Smart Bot. You can use the External Call on Demand: **_`@NAME_OF_BOT on #CHANNEL_NAME COMMAND`_**. In this case you will call the bot on #CHANNEL_NAME.
206
+ Also you can always call the Smart Bot from any channel, even from channels without a running Smart Bot. You can use the External Call on Demand: **_`@NAME_OF_BOT on #CHANNEL_NAME COMMAND`_**. In this case you will call the bot on #CHANNEL_NAME. You can supply more than one channel then all the bots will respond.
205
207
 
206
208
  Example:
207
209
  >**_Peter>_** `@smart-bot on #the_channel ruby puts Time.now`
@@ -221,9 +223,9 @@ Examples:
221
223
  >. . . . . . . . .**_Smart-Bot>_** `b`
222
224
 
223
225
  ### Bot Help
224
- To get a full list of all commands and rules for a specific Smart Bot: **_`bot help`_**. It will show only the specific available commands for the user requesting.
226
+ To get a full list of all commands and rules for a specific Smart Bot: **_`bot help`_**. It will show only the specific available commands for the user requesting. By default it will display only a short version of the bot help, call **_`bot help expanded`_** to get a expanded version of all commands.
225
227
 
226
- If you want to search just for a specific command: **_`bot help COMMAND`_**
228
+ If you want to search just for a specific command: **_`bot help COMMAND`_** It will display expanded explanations for the command.
227
229
 
228
230
  To show only the specific rules of the Smart Bot defined on the rules file: **_`bot rules`_** or **_`bot rules COMMAND`_**
229
231
 
@@ -239,6 +241,7 @@ Remember when you add code to your rules you need to specify the help that will
239
241
  For the examples use _ and for the rules `. This is a good example of a Help supplied on rules source code:
240
242
 
241
243
  ```ruby
244
+ # help: ----------------------------------------------
242
245
  # help: `run TYPE tests on LOCATION`
243
246
  # help: `execute TYPE tests on LOCATION`
244
247
  # help: run the specified tests on the indicated location
@@ -250,6 +253,8 @@ For the examples use _ and for the rules `. This is a good example of a Help sup
250
253
  # help: _execute smoke tests on db1_
251
254
  ```
252
255
 
256
+ To see what's new just call `What's new`
257
+
253
258
  ### Bot Management
254
259
  To create a new bot on a channel, run on MASTER CHANNEL: **_`create bot on CHANNEL`_**. The admins of this new bot on that channel will be the MASTER ADMINS, the creator of the bot and the creator of that channel. It will create a new rules file linked to this new bot.
255
260
 
@@ -259,9 +264,11 @@ If you want to pause a bot, from the channel of the bot: **_`pause bot`_**. To s
259
264
 
260
265
  To see the status of the bots, on the MASTER CHANNEL: **_`bot status`_**
261
266
 
267
+ If you need it you can set the SmartBot on maintenance mode by running: **_`set maintenance on`_**. A message to be displayed can be added if not the default message will be used. Run **_`set maintenance off`_** when you want the SmartBot to be running in normal conditions again.
268
+
262
269
  To close the Master Bot, run on MASTER CHANNEL: **_`exit bot`_**
263
270
 
264
- If you are a Master Admin on a Direct Message with the Smart Bot you can call the **_`bot stats`_** and get use stats of the users. You need to set to `true` the `stats` settings when initializing the Smart Bot. Take a look at `bot help bot stats` for more info.
271
+ If you are a Master Admin on a Direct Message with the Smart Bot you can call the **_`bot stats`_** and get use stats of the users. You need to set to `true` the `stats` settings when initializing the Smart Bot. As a normal user you will get your own stats when calling **_`bot stats`_**. Take a look at `bot help bot stats` for more info.
265
272
 
266
273
  You can also get the bot logs of the bot channel you are using by calling `get bot logs`. You need to be a Master Admin user on a DM with the Smart Bot.
267
274
 
@@ -309,7 +316,7 @@ If you declare on your rules file a method called `project_folder` returning the
309
316
 
310
317
  By default it will be automatically loaded the gems: `string_pattern`, `nice_hash` and `nice_http`
311
318
 
312
- To pre-execute some ruby when starting the session add the code to `.smart-bot-repl` file on the project root folder defined on `project_folder`
319
+ To pre-execute some ruby when starting the session add the code to `.smart-bot-repl` file on the project root folder defined on `project_folder`. Then that file will be always executed before the REPL started or created. In that case if we want to avoid to run that file before the REPL we can do it adding the word 'clean' before the command `clean repl`.
313
320
 
314
321
  If you want to see the methods of a class or module you created use `ls TheModuleOrClass`
315
322
 
@@ -367,7 +374,7 @@ That shortcut will be available for you, in case you want to make it available f
367
374
  Example:
368
375
  >**_Peter>_** `!add shortcut for all spanish bank account: ruby require 'iso/iban'; 3.times {puts ISO::IBAN.random('ES')}`
369
376
  >**_Smart-Bot>_** `shortcut added`
370
- >**_Peter>_** `!spanish bank account`
377
+ >**_John>_** `!spanish bank account`
371
378
  >**_Smart-Bot>_** `ES4664553191352006861448`
372
379
  `ES4799209592433480943244`
373
380
  `ES8888795057132445752702`
@@ -41,6 +41,8 @@ class SlackSmartBot
41
41
  config[:simulate] = false unless config.key?(:simulate)
42
42
  config[:stats] = false unless config.key?(:stats)
43
43
  config[:allow_access] = Hash.new unless config.key?(:allow_access)
44
+ config[:on_maintenance] = false unless config.key?(:on_maintenance)
45
+ config[:on_maintenance_message] = "Sorry I'm on maintenance so I cannot attend your request." unless config.key?(:on_maintenance_message)
44
46
 
45
47
  if config.path.to_s!='' and config.file.to_s==''
46
48
  config.file = File.basename($0)
@@ -89,7 +91,7 @@ class SlackSmartBot
89
91
  config.on_master_bot = false
90
92
  end
91
93
 
92
- if !config.key?(:token) or config.token.to_s == ''
94
+ if (!config.key?(:token) or config.token.to_s == '') and !config.simulate
93
95
  abort "You need to supply a valid token key on the settings. key: :token"
94
96
  elsif !config.key?(:masters) or !config.masters.is_a?(Array) or config.masters.size == 0
95
97
  abort "You need to supply a masters array on the settings containing the user names of the master admins. key: :masters"
@@ -104,7 +106,8 @@ class SlackSmartBot
104
106
  logfile = File.basename(config.rules_file.gsub("_rules_", "_logs_"), ".rb") + ".log"
105
107
  config.log_file = logfile
106
108
  @logger = Logger.new("#{config.path}/logs/#{logfile}")
107
-
109
+ @last_respond = Time.now
110
+
108
111
  config_log = config.dup
109
112
  config_log.delete(:token)
110
113
  @logger.info "Initializing bot: #{config_log.inspect}"
@@ -114,15 +117,21 @@ class SlackSmartBot
114
117
 
115
118
  self.config = config
116
119
 
117
- Slack.configure do |conf|
118
- conf.token = config[:token]
120
+ unless config.simulate and config.key?(:client)
121
+ Slack.configure do |conf|
122
+ conf.token = config[:token]
123
+ end
119
124
  end
120
125
  restarts = 0
121
126
  created = false
122
127
  while restarts < 200 and !created
123
128
  begin
124
129
  @logger.info "Connecting #{config_log.inspect}"
125
- self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
130
+ if config.simulate and config.key?(:client)
131
+ self.client = config.client
132
+ else
133
+ self.client = Slack::RealTime::Client.new(start_method: :rtm_connect)
134
+ end
126
135
  created = true
127
136
  rescue Exception => e
128
137
  restarts += 1
@@ -143,6 +152,8 @@ class SlackSmartBot
143
152
  @bots_created = Hash.new()
144
153
  @shortcuts = Hash.new()
145
154
  @shortcuts[:all] = Hash.new()
155
+ @shortcuts_global = Hash.new()
156
+ @shortcuts_global[:all] = Hash.new()
146
157
  @rules_imported = Hash.new()
147
158
  @routines = Hash.new()
148
159
  @repls = Hash.new()
@@ -153,6 +164,12 @@ class SlackSmartBot
153
164
  @shortcuts = eval(file_sc)
154
165
  end
155
166
  end
167
+ if File.exist?("#{config.path}/shortcuts/shortcuts_global.rb")
168
+ file_sc = IO.readlines("#{config.path}/shortcuts/shortcuts_global.rb").join
169
+ unless file_sc.to_s() == ""
170
+ @shortcuts_global = eval(file_sc)
171
+ end
172
+ end
156
173
 
157
174
  get_routines()
158
175
  get_repls()
@@ -181,7 +198,7 @@ class SlackSmartBot
181
198
  @admin_users_id = []
182
199
  @master_admin_users_id = []
183
200
  config.admins.each do |au|
184
- user_info = client.web_client.users_info(user: "@#{au}")
201
+ user_info = get_user_info("@#{au}")
185
202
  @admin_users_id << user_info.user.id
186
203
  if config.masters.include?(au)
187
204
  @master_admin_users_id << user_info.user.id
@@ -189,7 +206,7 @@ class SlackSmartBot
189
206
  sleep 1
190
207
  end
191
208
  (config.masters-config.admins).each do |au|
192
- user_info = client.web_client.users_info(user: "@#{au}")
209
+ user_info = get_user_info("@#{au}")
193
210
  @master_admin_users_id << user_info.user.id
194
211
  sleep 1
195
212
  end
@@ -197,38 +214,21 @@ class SlackSmartBot
197
214
  @logger.fatal "TooManyRequestsError"
198
215
  abort("TooManyRequestsError please re run the bot and be sure of executing first: killall ruby")
199
216
  rescue Exception => stack
217
+ pp stack if config.testing
200
218
  abort("The admin user specified on settings: #{config.admins.join(", ")}, doesn't exist on Slack. Execution aborted")
201
219
  end
202
220
 
203
- client.on :hello do
204
- m = "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
205
- puts m
206
- @logger.info m
207
- config.nick = client.self.name
208
- config.nick_id = client.self.id
209
- @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
210
-
211
- gems_remote = `gem list slack-smart-bot --remote`
212
- version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
213
- version_message = ""
214
- if version_remote != VERSION
215
- version_message = ". There is a new available version: #{version_remote}."
216
- end
217
- if !config[:silent] or ENV['BOT_SILENT'].to_s == 'false'
218
- ENV['BOT_SILENT'] = 'true' if config[:silent] == 'true' and ENV['BOT_SILENT'].to_s != 'true'
219
- respond "Smart Bot started v#{VERSION}#{version_message}\nIf you want to know what I can do for you: `bot help`.\n`bot rules` if you want to display just the specific rules of this channel.\nYou can talk to me privately if you prefer it."
220
- end
221
- @routines.each do |ch, rout|
222
- rout.each do |k, v|
223
- if !v[:running] and v[:channel_name] == config.channel
224
- create_routine_thread(k)
225
- end
226
- end
221
+ if config.simulate and config.key?(:client)
222
+ event_hello()
223
+ else
224
+ client.on :hello do
225
+ event_hello()
227
226
  end
228
227
  end
229
228
 
230
229
  @status = config.status_init
231
230
  @questions = Hash.new()
231
+ @answer = Hash.new()
232
232
  @repl_sessions = Hash.new()
233
233
  @channels_id = Hash.new()
234
234
  @channels_name = Hash.new()
@@ -253,20 +253,19 @@ class SlackSmartBot
253
253
  end
254
254
  end
255
255
  end
256
+ else
257
+ client.on :close do |_data|
258
+ m = "Connection closing, exiting. #{Time.now}"
259
+ @logger.info m
260
+ @logger.info _data
261
+ end
262
+
263
+ client.on :closed do |_data|
264
+ m = "Connection has been disconnected. #{Time.now}"
265
+ @logger.info m
266
+ @logger.info _data
267
+ end
256
268
  end
257
-
258
- client.on :close do |_data|
259
- m = "Connection closing, exiting. #{Time.now}"
260
- @logger.info m
261
- @logger.info _data
262
- end
263
-
264
- client.on :closed do |_data|
265
- m = "Connection has been disconnected. #{Time.now}"
266
- @logger.info m
267
- @logger.info _data
268
- end
269
-
270
269
  self
271
270
  end
272
271
 
@@ -2,7 +2,7 @@
2
2
  #path to the project folder
3
3
  # for example "#{`eval echo ~$USER`.chop}/projects/the_project"
4
4
  def project_folder()
5
- "#{`eval echo ~$USER`.chop}/"
5
+ "#{Dir.pwd}/"
6
6
  end
7
7
 
8
8
  #link to the project
@@ -50,12 +50,12 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
50
50
  # help:
51
51
  when /^go\sto\ssleep/i
52
52
  save_stats :go_to_sleep
53
- unless @questions.keys.include?(from)
53
+ if answer.empty?
54
54
  ask "do you want me to take a siesta?"
55
55
  else
56
- case @questions[from]
56
+ case answer
57
57
  when /yes/i, /yep/i, /sure/i
58
- @questions.delete(from)
58
+ answer_delete
59
59
  respond "I'll be sleeping for 5 secs... just for you"
60
60
  respond "zZzzzzzZZZZZZzzzzzzz!"
61
61
  react :sleeping
@@ -63,11 +63,11 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
63
63
  unreact :sleeping
64
64
  react :sunny
65
65
  when /no/i, /nope/i, /cancel/i
66
- @questions.delete(from)
66
+ answer_delete
67
67
  respond "Thanks, I'm happy to be awake"
68
68
  else
69
69
  respond "I don't understand"
70
- ask "are you sure do you want me to sleep? (yes or no)"
70
+ ask "are you sure you want me to sleep? (yes or no)"
71
71
  end
72
72
  end
73
73
 
@@ -6,4 +6,8 @@ require_relative 'comm/send_file'
6
6
  require_relative 'comm/send_msg_channel'
7
7
  require_relative 'comm/send_msg_user'
8
8
  require_relative 'comm/react'
9
- require_relative 'comm/unreact'
9
+ require_relative 'comm/unreact'
10
+ require_relative 'comm/get_user_info'
11
+ require_relative 'comm/event_hello'
12
+ require_relative 'comm/get_channel_members'
13
+ require_relative 'comm/get_channels'
@@ -16,7 +16,7 @@ class SlackSmartBot
16
16
  if dest.nil?
17
17
  if config[:simulate]
18
18
  open("#{config.path}/buffer_complete.log", "a") { |f|
19
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}~~~"
19
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
20
20
  }
21
21
  else
22
22
  if Thread.current[:on_thread]
@@ -27,13 +27,13 @@ class SlackSmartBot
27
27
  end
28
28
  if config[:testing] and config.on_master_bot
29
29
  open("#{config.path}/buffer.log", "a") { |f|
30
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}"
30
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
31
31
  }
32
32
  end
33
33
  elsif dest[0] == "C" or dest[0] == "G" # channel
34
34
  if config[:simulate]
35
35
  open("#{config.path}/buffer_complete.log", "a") { |f|
36
- f.puts "|#{dest}|#{config[:nick_id]}|#{message}~~~"
36
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
37
37
  }
38
38
  else
39
39
  if Thread.current[:on_thread]
@@ -44,13 +44,20 @@ class SlackSmartBot
44
44
  end
45
45
  if config[:testing] and config.on_master_bot
46
46
  open("#{config.path}/buffer.log", "a") { |f|
47
- f.puts "|#{dest}|#{config[:nick_id]}|#{message}"
47
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
48
48
  }
49
49
  end
50
50
  elsif dest[0] == "D" #private message
51
51
  send_msg_user(dest, message)
52
52
  end
53
- @questions[to] = context
53
+ if Thread.current[:on_thread]
54
+ qdest = Thread.current[:thread_ts]
55
+ else
56
+ qdest = dest
57
+ end
58
+ @answer[to] = {} unless @answer.key?(to)
59
+ @answer[to][qdest] = context
60
+ @questions[to] = context # to be backwards compatible #todo remove it when 2.0
54
61
  end
55
62
 
56
63
  end
@@ -10,7 +10,7 @@ class SlackSmartBot
10
10
  if typem==:on_extended
11
11
  get_bots_created()
12
12
  end
13
- text = get_help(rules_file, dest, user.name, typem==:on_extended)
13
+ text = get_help(rules_file, dest, user.name, typem==:on_extended, true)
14
14
 
15
15
  ff = text.scan(/\s*`\s*([^`]+)\s*`\s*/i).flatten
16
16
  ff.delete("!THE_COMMAND")
@@ -0,0 +1,30 @@
1
+ class SlackSmartBot
2
+ def event_hello()
3
+ unless config.simulate
4
+ m = "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
5
+ puts m
6
+ @logger.info m
7
+ config.nick = client.self.name
8
+ config.nick_id = client.self.id
9
+ end
10
+ @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
11
+
12
+ gems_remote = `gem list slack-smart-bot --remote`
13
+ version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
14
+ version_message = ""
15
+ if Gem::Version.new(version_remote) > Gem::Version.new(VERSION)
16
+ version_message = ". There is a new available version: #{version_remote}."
17
+ end
18
+ if (!config[:silent] or ENV['BOT_SILENT'].to_s == 'false') and !config.simulate
19
+ ENV['BOT_SILENT'] = 'true' if config[:silent] == 'true' and ENV['BOT_SILENT'].to_s != 'true'
20
+ respond "Smart Bot started v#{VERSION}#{version_message}\nIf you want to know what I can do for you: `bot help`.\n`bot rules` if you want to display just the specific rules of this channel.\nYou can talk to me privately if you prefer it."
21
+ end
22
+ @routines.each do |ch, rout|
23
+ rout.each do |k, v|
24
+ if !v[:running] and v[:channel_name] == config.channel
25
+ create_routine_thread(k)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ def get_channel_members(channel_id)
2
+ if config.simulate and config.key?(:client)
3
+ client.web_client.conversations_members[channel_id.to_sym].members
4
+ else
5
+ client.web_client.conversations_members(channel: channel_id).members
6
+ end
7
+
8
+ end
@@ -0,0 +1,20 @@
1
+ def get_channels(bot_is_in: false)
2
+ if config.simulate and config.key?(:client)
3
+ if bot_is_in
4
+ client.web_client.conversations_members.reject {|r,v| !v.members.include?(config.nick_id)}.values
5
+ else
6
+ client.web_client.conversations_members.values
7
+ end
8
+ else
9
+ if bot_is_in
10
+ client.web_client.users_conversations(exclude_archived: true, limit: 100, types: "im, public_channel,private_channel").channels
11
+ else
12
+ #todo: add pagination for case more than 1000 channels on the workspace
13
+ client.web_client.conversations_list(
14
+ types: "private_channel,public_channel",
15
+ limit: "1000",
16
+ exclude_archived: "true",
17
+ ).channels
18
+ end
19
+ end
20
+ end