slack-smart-bot 1.9.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +109 -11
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -49
  4. data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
  5. data/lib/slack/smart-bot/comm/event_hello.rb +7 -3
  6. data/lib/slack/smart-bot/comm/get_channel_members.rb +9 -4
  7. data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
  8. data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
  9. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  10. data/lib/slack/smart-bot/comm/react.rb +19 -2
  11. data/lib/slack/smart-bot/comm/respond.rb +217 -72
  12. data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
  13. data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
  14. data/lib/slack/smart-bot/comm/send_file.rb +38 -34
  15. data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
  16. data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
  17. data/lib/slack/smart-bot/comm/unreact.rb +22 -18
  18. data/lib/slack/smart-bot/comm.rb +2 -0
  19. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  20. data/lib/slack/smart-bot/commands/general/bot_help.rb +59 -32
  21. data/lib/slack/smart-bot/commands/general/bot_stats.rb +10 -9
  22. data/lib/slack/smart-bot/commands/general/bot_status.rb +2 -4
  23. data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
  24. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
  25. data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
  26. data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
  27. data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
  28. data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
  29. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
  30. data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
  31. data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
  32. data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
  33. data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
  34. data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
  35. data/lib/slack/smart-bot/commands/general/use_rules.rb +7 -7
  36. data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
  37. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -5
  38. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +32 -11
  39. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -0
  40. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -2
  41. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
  42. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
  43. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
  44. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
  45. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +4 -2
  46. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -2
  47. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
  48. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
  49. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
  50. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
  51. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -4
  52. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +2 -4
  53. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -4
  54. data/lib/slack/smart-bot/commands/on_bot/repl.rb +5 -7
  55. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +2 -4
  56. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +4 -5
  57. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +3 -5
  58. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +2 -4
  59. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
  60. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
  61. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +2 -0
  62. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -0
  63. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
  64. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
  65. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +8 -0
  66. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +27 -14
  67. data/lib/slack/smart-bot/commands.rb +16 -0
  68. data/lib/slack/smart-bot/listen.rb +1 -3
  69. data/lib/slack/smart-bot/process.rb +212 -74
  70. data/lib/slack/smart-bot/process_first.rb +118 -37
  71. data/lib/slack/smart-bot/treat_message.rb +313 -248
  72. data/lib/slack/smart-bot/utils/build_help.rb +3 -3
  73. data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
  74. data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
  75. data/lib/slack/smart-bot/utils/get_help.rb +58 -68
  76. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  77. data/lib/slack/smart-bot/utils/has_access.rb +12 -0
  78. data/lib/slack/smart-bot/utils/save_stats.rb +2 -0
  79. data/lib/slack/smart-bot/utils/save_status.rb +52 -0
  80. data/lib/slack/smart-bot/utils.rb +3 -0
  81. data/lib/slack-smart-bot.rb +45 -4
  82. data/lib/slack-smart-bot_general_commands.rb +46 -0
  83. data/lib/slack-smart-bot_general_rules.rb +5 -2
  84. data/lib/slack-smart-bot_rules.rb +43 -17
  85. data/whats_new.txt +32 -20
  86. metadata +24 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 974b9b2da39dd58e4e404572932ace72c5b9d1136956543ac890cf7bc91ab61e
4
- data.tar.gz: a304bbeeecc5177c5014c86902c20d9682e6addfc00ab3f5ee33aeca4dba2215
3
+ metadata.gz: 258161d536cc6c07a7cdbf6e42a91069bc5715fb3b5807f635f4be4754ec6a36
4
+ data.tar.gz: 72361374be67be8b22f3dff0465fc03aa9383045d75cc68385ffa401fff8edbd
5
5
  SHA512:
6
- metadata.gz: 85e6d1e343b0523b25c5c630d37fcda402a8529d2ae8a1f5473694a65e9311293b4d628bc0e9a18e3910bd68123276b30039e1a50115c97bd029db19a2a9738a
7
- data.tar.gz: 90c2441764b9faceeb74d1281c19fccc84c960d4344f5822c5d50293d1de55d300d10373a60e0cf876270aced23f20686844e2cb0503dfb0a30004adeec8e27c
6
+ metadata.gz: 0bdaabba591af2ef6690d71212a61a170a454f58eeb8424504d743d17f1d5062db808279bd29d6719791ecac141c9c23f29964349f0c8c94fa6a738b09cac4aa
7
+ data.tar.gz: 50b5827289fb31fe757a6269eea9d89ee00fb8d2f81f1ed7bbcab0ccdff9114a7a7ff703e97c31fec259e2f65bde93f4b1780765a72d704966ece7d2b251c3c0
data/README.md CHANGED
@@ -27,8 +27,12 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
27
27
  + [REPL](#repl)
28
28
  * [Sending notifications](#sending-notifications)
29
29
  * [Shortcuts](#shortcuts)
30
+ * [Announcements](#announcements)
31
+ * [Share Messages](#share-messages)
32
+ * [See Statuses](#see-statuses)
30
33
  * [Routines](#routines)
31
34
  * [Limit who has access to a command](#limit-who-has-access-to-a-command)
35
+ * [See favorite commands](#see-favorite-commands)
32
36
  * [Tips](#tips)
33
37
  + [Send a file](#send-a-file)
34
38
  + [Download a file](#download-a-file)
@@ -81,7 +85,9 @@ You can get one by any of these options:
81
85
  - *[Legacy API Token](https://api.slack.com/custom-integrations/legacy-tokens)*.
82
86
 
83
87
 
84
- *Remember to invite the smart bot to the channels where they will be accessible before creating the bot*
88
+ *Remember to invite the smart bot to the channels where they will be accessible before creating the bot*
89
+
90
+ SmartBot will notify about SmartBot status changes or any SmartBot incident if defined the status_channel in settings file and the channel exists. By default: smartbot-status
85
91
 
86
92
  ## Usage
87
93
 
@@ -158,6 +164,21 @@ def rules(user, command, processed, dest)
158
164
 
159
165
  unreact :runner
160
166
 
167
+ # Example sending blocks. More info: https://api.slack.com/block-kit
168
+ # help: It will return the info about who is the admin
169
+ when /\AWho is the admin\?\z/i
170
+ my_blocks = [
171
+ { type: "context",
172
+ elements:
173
+ [
174
+ { type: "plain_text", :text=>"\tAdmin: " },
175
+ { type: "image", image_url: "https://avatars.slack-edge.com/2021-03-23/182815_e54abb1dd_24.jpg", alt_text: "mario" },
176
+ { type: "mrkdwn", text: " *Mario Ruiz* (marior) " }
177
+ ]
178
+ }
179
+ ]
180
+ respond blocks: my_blocks
181
+
161
182
  else
162
183
  unless processed
163
184
  dont_understand()
@@ -168,6 +189,7 @@ end
168
189
 
169
190
  Also you can add general rules that will be available on all Smart Bot channels to `./rules/general_rules.rb`
170
191
 
192
+ If you have commands that want to make them available everywhere the Smart Bot is a member then add those commands to `./rules/general_commands.rb`.
171
193
 
172
194
  ### How to access the Smart Bot
173
195
  You can access the bot directly on the MASTER CHANNEL, on a secondary channel where the bot is running and directly by opening a private chat with the bot, in this case the conversation will be just between you and the bot.
@@ -184,7 +206,7 @@ To run a command on demand:
184
206
  **_`!THE_COMMAND`_**
185
207
  **_`@NAME_OF_BOT THE_COMMAND`_**
186
208
  **_`NAME_OF_BOT THE_COMMAND`_**
187
- To run a command on demand and add the respond on a thread:
209
+ To run a command on demand and add the response on a thread:
188
210
  **_`^THE_COMMAND`_**
189
211
  **_`!!THE_COMMAND`_**
190
212
 
@@ -203,14 +225,18 @@ Examples run a command on demand:
203
225
  >**_Peter>_** `^echo Example`
204
226
  >. . . . . . . . .**_Smart-Bot>_** `Example`
205
227
 
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.
228
+ 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. In case you are in a private conversation with the Smart Bot (DM) then you can use directly: **_`#CHANNEL_NAME COMMAND`_** or **_`on #CHANNEL_NAME COMMAND`_**
207
229
 
208
- Example:
230
+ Examples:
209
231
  >**_Peter>_** `@smart-bot on #the_channel ruby puts Time.now`
210
232
  >**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
211
233
  >**_Peter>_** `@smart-bot on #the_channel ^ruby puts Time.now`
212
234
  >. . . . . . . . .**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
213
235
 
236
+ Examples on DM:
237
+ >**_Peter>_** `#sales show report from India`
238
+ >**_Peter>_** `on #sales notify clients`
239
+
214
240
  If you want the Smart Bot just listen to part of the message you send, add the commands you want using '`' and start the line with '-!', '-!!' or '-^'
215
241
 
216
242
  Examples:
@@ -222,6 +248,13 @@ Examples:
222
248
  >. . . . . . . . .**_Smart-Bot>_** `a`
223
249
  >. . . . . . . . .**_Smart-Bot>_** `b`
224
250
 
251
+
252
+ All the commands specified on `./rules/general_commands.rb` will be accessible from any channel where the Smart Bot is present, without the necessity to call it with !, !!, ^ or on demand.
253
+
254
+ Examples:
255
+ >**_Peter>_** `Thanks smartbot`
256
+ >**_Smart-Bot>_** `You're very welcome`
257
+
225
258
  ### Bot Help
226
259
  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.
227
260
 
@@ -229,6 +262,8 @@ If you want to search just for a specific command: **_`bot help COMMAND`_** It w
229
262
 
230
263
  To show only the specific rules of the Smart Bot defined on the rules file: **_`bot rules`_** or **_`bot rules COMMAND`_**
231
264
 
265
+ Also you can call `suggest command` or `random command` and SmartBot will return the help content for a random command.
266
+
232
267
  Example:
233
268
  >**_Peter>_** `bot help echo`
234
269
  >**_Smart-Bot>_** `echo SOMETHING`
@@ -266,9 +301,11 @@ To see the status of the bots, on the MASTER CHANNEL: **_`bot status`_**
266
301
 
267
302
  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
303
 
304
+ To display a general message after every command use: `set general message MESSAGE`. Use `set general message off` to stop displaying it.
305
+
269
306
  To close the Master Bot, run on MASTER CHANNEL: **_`exit bot`_**
270
307
 
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.
308
+ 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. Also you can call **_`leaderboard`_** to get some useful information about the use of the SmartBot.
272
309
 
273
310
  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.
274
311
 
@@ -298,7 +335,7 @@ Example:
298
335
  >**_Peter>_** `!ruby require 'json'; res=[]; 20.times {res.push rand(100)}; my_json={result: res}; puts my_json.to_json`
299
336
  >**_Smart-Bot>_** `{"result":[63,66,35,83,44,40,72,25,59,73,75,54,56,91,19,6,68,1,25,3]}`
300
337
 
301
- Also it is possible to attach a Ruby file and the Smart Bot will run and post the output. You need to select Ruby as file format.
338
+ Also it is possible to attach a Ruby file and the Smart Bot will run and post the output. You need to select Ruby as file format. Or if you prefer it you can call the `ruby` command and on the same message supply a code block.
302
339
 
303
340
  #### REPL
304
341
  Easily starts a REPL session so you will be able to create a script directly from the slack conversation. You will be able to share the REPL so they can run it or see the content.
@@ -392,19 +429,63 @@ Example:
392
429
 
393
430
  To see available shortcuts: **_`see shortcuts`_** and to delete a particular shortcut: **_`delete shortcut NAME`_**
394
431
 
432
+ ### Announcements
433
+ You can add any announcement on any channel where the SmartBot is a member by using **_`add COLOR announcement MESSAGE`_** or **_`add EMOJI announcement MESSAGE`_**.
434
+
435
+ It will store the message on the announcement list labeled with the color/emoji specified, white by default. Possible colors white, green, yellow and red. Aliases for announcement: statement, declaration, message.
436
+
437
+ Examples:
438
+ >**_Peter>_** `add green announcement :heavy_check_mark: All customer services are *up* and running`
439
+ >**_Peter>_** `add red message Customers db is down :x:`
440
+ >**_Peter>_** `add yellow statement Don't access the linux server without VPN`
441
+ >**_Peter>_** `add announcement Party will start at 20:00 :tada:`
442
+ >**_Peter>_** `add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT`
443
+
444
+ To see the announcements of the channel: **_`see announcements`_**, **_`see COLOR announcements`_**, **_`see EMOJI announcements`_** and to delete a particular announcement: **_`delete announcement ID`_**
445
+
446
+ If you are a master admin and you are on master channel then you can call **_`publish announcements`_** that will publish the announcements on all channels. The messages stored on a DM won't be published. This is very convenient to be called from a *Routine* for example every weekday at 09:00.
447
+
448
+ ### Share messages
449
+ You can automatically share any new message that is posted on the channel and meet the specified criteria by using **_`share messages /REGEXP/ on #CHANNEL`_** or **_`share messages "TEXT" on #CHANNEL`_**.
450
+
451
+ This command is only available in public channels. The user adding the Share and the SmartBot need to be a member of both channels.
452
+
453
+ Examples:
454
+ >**_Peter>_** `share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales`
455
+ >**_Peter>_** `share messages "share post" on #announcements`
456
+
457
+ To see the shares of the channel: **_`see shares`_** and to delete a particular share: **_`delete share ID`_**
458
+
459
+ ### See statuses
460
+ To see a list of statuses of the members in the channel you can call `see statuses`, `who is on vacation?`, `who is not on vacation?`, `who is on EMOJI`, `who is on EMOJI #CHANNEL`
461
+
462
+ You need to be a member of the channel to be able to get this info.
463
+
464
+ Examples:
465
+ >**_Peter>_** `see statuses`
466
+ >**_Peter>_** `who is on vacation?`
467
+ >**_Peter>_** `who is not on vacation?`
468
+ >**_Peter>_** `who is on vacation? #SalesChannel`
469
+ >**_Peter>_** `who is on :working-from-home:`
470
+
395
471
  ### Routines
396
472
  To add specific commands to be run automatically every certain amount of time or a specific time: **_`add routine NAME every NUMBER PERIOD COMMAND`_** or **_`add routine NAME at TIME COMMAND`_**. Also just before the command you can supply the channel where you want to publish the results, if not channel supplied then it would be the SmartBot Channel or on the DM if the command is run from there. Remember the SmartBot needs to have access to the channel where you want to publish.
397
473
 
474
+ In case you create a *bgroutine* instead of a normal *routine* then the results of the run won't be published.
475
+
398
476
  If you want to hide the routine executions use `add silent routine`. It won't show the routine name when executing.
399
477
 
478
+ To see the last result of the execution you can call `see result routine NAME`
479
+
400
480
  Examples:
401
481
  >**_`add routine run_tests every 3h !run tests on customers`_**
402
- >**_`add routine clean_db at 17:05 !clean customers temp db`_**
403
- >**_`add silent routine clean_db at 17:05 !clean customers temp db`_**
482
+ >**_`add bgroutine clean_db at 17:05 !clean customers temp db`_**
483
+ >**_`add silent bgroutine clean_db at 17:05 !clean customers temp db`_**
404
484
  >**_`add routine clean_custdb on Mondays at 05:00 !clean customers db`_**
405
485
  >**_`add routine clean_custdb on Tuesdays at 09:00 #SREChannel !clean customers db`_**
486
+ >**_`add silent routine suggestions on weekdays at 09:00 suggest command`_**
406
487
 
407
- Also instead of adding a Command to be executed, you can attach a file, then the routine will be created and the attached file will be executed on the criteria specified. Only Master Admins are allowed to use it this way.
488
+ Also instead of adding a Command to be executed, you can attach a file, then the routine will be created and the attached file will be executed on the criteria specified. Also you can supply a script adding \`\`\`the code\`\`\` and specifying on the routine name the extension that will have. Only Master Admins are allowed to add files or scripts.
408
489
 
409
490
  Other routine commands:
410
491
  * **_`pause routine NAME`_**
@@ -412,6 +493,7 @@ Other routine commands:
412
493
  * **_`remove routine NAME`_**
413
494
  * **_`run routine NAME`_**
414
495
  * **_`see routines`_**
496
+ * **_`see result routine NAME`_**
415
497
 
416
498
  ### Limit who has access to a command
417
499
 
@@ -437,10 +519,26 @@ If you want to change who has access to a certain command without restarting the
437
519
  config.allow_access.repl = ['marioruiz', 'samcooke']
438
520
  ```
439
521
 
440
- These are the commands that are possible to be limited:
522
+ These are the commands that are possible to be limited plus all your SmartBot rules:
523
+
524
+ `bot_help, bot_rules, bot_status, use_rules, add_shortcut, delete_shortcut, repl, run_repl, get_repl, delete_repl, see_repls, ruby_code, see_shortcuts, create_bot, add_announcement, delete_announcement, see_announcements`
441
525
 
442
- `bot_help, bot_rules, bot_status, use_rules, add_shortcut, delete_shortcut, repl, run_repl, get_repl, delete_repl, see_repls, ruby_code, see_shortcuts, create_bot`
526
+ To check from a rule if the user has access to it:
443
527
 
528
+ ```ruby
529
+ if has_access?(:your_command_id)
530
+ end
531
+ ```
532
+
533
+ ### See favorite commands
534
+
535
+ It will display the favorite commands in that channel.
536
+
537
+ Examples:
538
+ >**_`see favorite commands`_**
539
+ >**_`favorite commands`_**
540
+ >**_`my favourite commands`_**
541
+ >**_`most used commands`_**
444
542
 
445
543
  ### Tips
446
544
 
@@ -3,61 +3,67 @@ class SlackSmartBot
3
3
  #context: previous message
4
4
  #to: user that should answer
5
5
  def ask(question, context = nil, to = nil, dest = nil)
6
- if dest.nil? and Thread.current.key?(:dest)
7
- dest = Thread.current[:dest]
8
- end
9
- if to.nil?
10
- to = Thread.current[:user].name
11
- end
12
- if context.nil?
13
- context = Thread.current[:command]
14
- end
15
- message = "#{to}: #{question}"
16
- if dest.nil?
17
- if config[:simulate]
18
- open("#{config.path}/buffer_complete.log", "a") { |f|
19
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
20
- }
21
- else
22
- if Thread.current[:on_thread]
23
- client.message(channel: @channel_id, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
24
- else
25
- client.message(channel: @channel_id, text: message, as_user: true)
26
- end
6
+ begin
7
+ if dest.nil? and Thread.current.key?(:dest)
8
+ dest = Thread.current[:dest]
9
+ end
10
+ if to.nil?
11
+ to = Thread.current[:user].name
27
12
  end
28
- if config[:testing] and config.on_master_bot
29
- open("#{config.path}/buffer.log", "a") { |f|
30
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
31
- }
13
+ if context.nil?
14
+ context = Thread.current[:command]
32
15
  end
33
- elsif dest[0] == "C" or dest[0] == "G" # channel
34
- if config[:simulate]
35
- open("#{config.path}/buffer_complete.log", "a") { |f|
36
- f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
37
- }
38
- else
39
- if Thread.current[:on_thread]
40
- client.message(channel: dest, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
41
- else
42
- client.message(channel: dest, text: message, as_user: true)
16
+ message = "#{to}: #{question}"
17
+ if dest.nil?
18
+ if config[:simulate]
19
+ open("#{config.path}/buffer_complete.log", "a") { |f|
20
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
21
+ }
22
+ else
23
+ if Thread.current[:on_thread]
24
+ client.message(channel: @channel_id, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
25
+ else
26
+ client.message(channel: @channel_id, text: message, as_user: true)
27
+ end
43
28
  end
29
+ if config[:testing] and config.on_master_bot and !@buffered
30
+ @buffered = true
31
+ open("#{config.path}/buffer.log", "a") { |f|
32
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
33
+ }
34
+ end
35
+ elsif dest[0] == "C" or dest[0] == "G" # channel
36
+ if config[:simulate]
37
+ open("#{config.path}/buffer_complete.log", "a") { |f|
38
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}~~~"
39
+ }
40
+ else
41
+ if Thread.current[:on_thread]
42
+ client.message(channel: dest, text: message, as_user: true, thread_ts: Thread.current[:thread_ts])
43
+ else
44
+ client.message(channel: dest, text: message, as_user: true)
45
+ end
46
+ end
47
+ if config[:testing] and config.on_master_bot and !@buffered
48
+ @buffered = true
49
+ open("#{config.path}/buffer.log", "a") { |f|
50
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
51
+ }
52
+ end
53
+ elsif dest[0] == "D" #private message
54
+ send_msg_user(dest, message)
44
55
  end
45
- if config[:testing] and config.on_master_bot
46
- open("#{config.path}/buffer.log", "a") { |f|
47
- f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{message}"
48
- }
56
+ if Thread.current[:on_thread]
57
+ qdest = Thread.current[:thread_ts]
58
+ else
59
+ qdest = dest
49
60
  end
50
- elsif dest[0] == "D" #private message
51
- send_msg_user(dest, message)
52
- end
53
- if Thread.current[:on_thread]
54
- qdest = Thread.current[:thread_ts]
55
- else
56
- qdest = dest
61
+ @answer[to] = {} unless @answer.key?(to)
62
+ @answer[to][qdest] = context
63
+ @questions[to] = context # to be backwards compatible #todo remove it when 2.0
64
+ rescue Exception => stack
65
+ @logger.warn stack
57
66
  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
61
67
  end
62
68
 
63
69
  end
@@ -50,7 +50,7 @@ class SlackSmartBot
50
50
  end
51
51
  else
52
52
  message = ''
53
- message = "\nTake in consideration when on external calls, not all the commands are availalbe." if typem==:on_call
53
+ message = "\nTake in consideration when on external calls, not all the commands are available." if typem==:on_call
54
54
  if res_final.empty?
55
55
  resp = answer.sample
56
56
  respond "#{user.profile.display_name}, #{resp}#{message}", dest
@@ -3,11 +3,13 @@ class SlackSmartBot
3
3
  unless config.simulate
4
4
  m = "Successfully connected, welcome '#{client.self.name}' to the '#{client.team.name}' team at https://#{client.team.domain}.slack.com."
5
5
  puts m
6
+ save_status :on, :connected, m
7
+
6
8
  @logger.info m
7
9
  config.nick = client.self.name
8
10
  config.nick_id = client.self.id
9
11
  end
10
- @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
12
+ @salutations = [config[:nick], "<@#{config[:nick_id]}>", "@#{config[:nick]}", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
11
13
 
12
14
  gems_remote = `gem list slack-smart-bot --remote`
13
15
  version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
@@ -16,13 +18,15 @@ class SlackSmartBot
16
18
  version_message = ". There is a new available version: #{version_remote}."
17
19
  end
18
20
  if (!config[:silent] or ENV['BOT_SILENT'].to_s == 'false') and !config.simulate
21
+ unless ENV['BOT_SILENT']=='true'
22
+ 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."
23
+ end
19
24
  ENV['BOT_SILENT'] = 'true' if config[:silent] 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
25
  end
22
26
  @routines.each do |ch, rout|
23
27
  rout.each do |k, v|
24
28
  if !v[:running] and v[:channel_name] == config.channel
25
- create_routine_thread(k)
29
+ create_routine_thread(k, v)
26
30
  end
27
31
  end
28
32
  end
@@ -1,8 +1,13 @@
1
+ #todo: add pagination for case more than 1000 members in the channel
1
2
  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
3
+ begin
4
+ if config.simulate and config.key?(:client)
5
+ client.web_client.conversations_members[channel_id.to_sym].members
6
+ else
7
+ client.web_client.conversations_members(channel: channel_id, limit: 1000).members
8
+ end
9
+ rescue Exception => stack
10
+ @logger.warn stack
6
11
  end
7
12
 
8
13
  end
@@ -1,20 +1,35 @@
1
- def get_channels(bot_is_in: false)
1
+ def get_channels(bot_is_in: false, types: 'private_channel,public_channel')
2
+ begin
2
3
  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
4
+ if bot_is_in
5
+ client.web_client.conversations_members.reject { |r, v| !v.members.include?(config.nick_id) }.values
6
+ else
7
+ client.web_client.conversations_members.values
8
+ end
8
9
  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
10
+ if bot_is_in
11
+ client.web_client.users_conversations(exclude_archived: true, limit: 1000, types: "im, public_channel,private_channel").channels
12
+ else
13
+ resp = client.web_client.conversations_list(types: types, limit: "600", exclude_archived: "true")
14
+ channels = resp.channels
15
+ begin
16
+ while resp.response_metadata.next_cursor.to_s != ""
17
+ resp = client.web_client.conversations_list(
18
+ cursor: resp.response_metadata.next_cursor.to_s,
19
+ types: types,
20
+ limit: "600",
21
+ exclude_archived: "true",
22
+ )
23
+ channels += resp.channels
24
+ end
25
+ rescue Exception => stack
26
+ @logger.warn stack
18
27
  end
28
+ return channels
29
+ end
19
30
  end
20
- end
31
+ rescue Exception => stack
32
+ @logger.warn stack
33
+ return []
34
+ end
35
+ end