slack-smart-bot 1.8.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +127 -21
- data/lib/slack/smart-bot/comm/ask.rb +55 -42
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +38 -8
- data/lib/slack/smart-bot/comm/respond.rb +219 -48
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +24 -7
- data/lib/slack/smart-bot/comm.rb +7 -1
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +13 -16
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +12 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +5 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +49 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
- data/lib/slack/smart-bot/commands.rb +19 -1
- data/lib/slack/smart-bot/listen.rb +7 -8
- data/lib/slack/smart-bot/process.rb +373 -192
- data/lib/slack/smart-bot/process_first.rb +202 -104
- data/lib/slack/smart-bot/treat_message.rb +325 -186
- 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 +83 -30
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +87 -35
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +23 -8
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/lib/slack/smart-bot/utils.rb +5 -0
- data/lib/slack-smart-bot.rb +88 -47
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +49 -23
- data/whats_new.txt +36 -0
- metadata +44 -13
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 258161d536cc6c07a7cdbf6e42a91069bc5715fb3b5807f635f4be4754ec6a36
|
4
|
+
data.tar.gz: 72361374be67be8b22f3dff0465fc03aa9383045d75cc68385ffa401fff8edbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bdaabba591af2ef6690d71212a61a170a454f58eeb8424504d743d17f1d5062db808279bd29d6719791ecac141c9c23f29964349f0c8c94fa6a738b09cac4aa
|
7
|
+
data.tar.gz: 50b5827289fb31fe757a6269eea9d89ee00fb8d2f81f1ed7bbcab0ccdff9114a7a7ff703e97c31fec259e2f65bde93f4b1780765a72d704966ece7d2b251c3c0
|
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)
|
@@ -25,8 +27,12 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
|
|
25
27
|
+ [REPL](#repl)
|
26
28
|
* [Sending notifications](#sending-notifications)
|
27
29
|
* [Shortcuts](#shortcuts)
|
30
|
+
* [Announcements](#announcements)
|
31
|
+
* [Share Messages](#share-messages)
|
32
|
+
* [See Statuses](#see-statuses)
|
28
33
|
* [Routines](#routines)
|
29
34
|
* [Limit who has access to a command](#limit-who-has-access-to-a-command)
|
35
|
+
* [See favorite commands](#see-favorite-commands)
|
30
36
|
* [Tips](#tips)
|
31
37
|
+ [Send a file](#send-a-file)
|
32
38
|
+ [Download a file](#download-a-file)
|
@@ -79,7 +85,9 @@ You can get one by any of these options:
|
|
79
85
|
- *[Legacy API Token](https://api.slack.com/custom-integrations/legacy-tokens)*.
|
80
86
|
|
81
87
|
|
82
|
-
*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
|
83
91
|
|
84
92
|
## Usage
|
85
93
|
|
@@ -114,12 +122,12 @@ def rules(user, command, processed, dest)
|
|
114
122
|
# help: it will sleep the bot for 10 seconds
|
115
123
|
# help:
|
116
124
|
when /^go\sto\ssleep/i
|
117
|
-
|
125
|
+
if answer.empty?
|
118
126
|
ask "do you want me to take a siesta?"
|
119
127
|
else
|
120
|
-
case
|
128
|
+
case answer
|
121
129
|
when /yes/i, /yep/i, /sure/i
|
122
|
-
|
130
|
+
answer_delete
|
123
131
|
respond "I'll be sleeping for 10 secs... just for you"
|
124
132
|
respond "zZzzzzzZZZZZZzzzzzzz!"
|
125
133
|
react :sleeping
|
@@ -127,11 +135,11 @@ def rules(user, command, processed, dest)
|
|
127
135
|
unreact :sleeping
|
128
136
|
react :sunny
|
129
137
|
when /no/i, /nope/i, /cancel/i
|
130
|
-
|
138
|
+
answer_delete
|
131
139
|
respond "Thanks, I'm happy to be awake"
|
132
140
|
else
|
133
141
|
respond "I don't understand"
|
134
|
-
ask "are you sure
|
142
|
+
ask "are you sure you want me to sleep? (yes or no)"
|
135
143
|
end
|
136
144
|
end
|
137
145
|
|
@@ -156,6 +164,21 @@ def rules(user, command, processed, dest)
|
|
156
164
|
|
157
165
|
unreact :runner
|
158
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
|
+
|
159
182
|
else
|
160
183
|
unless processed
|
161
184
|
dont_understand()
|
@@ -166,6 +189,7 @@ end
|
|
166
189
|
|
167
190
|
Also you can add general rules that will be available on all Smart Bot channels to `./rules/general_rules.rb`
|
168
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`.
|
169
193
|
|
170
194
|
### How to access the Smart Bot
|
171
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.
|
@@ -182,7 +206,7 @@ To run a command on demand:
|
|
182
206
|
**_`!THE_COMMAND`_**
|
183
207
|
**_`@NAME_OF_BOT THE_COMMAND`_**
|
184
208
|
**_`NAME_OF_BOT THE_COMMAND`_**
|
185
|
-
To run a command on demand and add the
|
209
|
+
To run a command on demand and add the response on a thread:
|
186
210
|
**_`^THE_COMMAND`_**
|
187
211
|
**_`!!THE_COMMAND`_**
|
188
212
|
|
@@ -201,14 +225,18 @@ Examples run a command on demand:
|
|
201
225
|
>**_Peter>_** `^echo Example`
|
202
226
|
>. . . . . . . . .**_Smart-Bot>_** `Example`
|
203
227
|
|
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.
|
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`_**
|
205
229
|
|
206
|
-
|
230
|
+
Examples:
|
207
231
|
>**_Peter>_** `@smart-bot on #the_channel ruby puts Time.now`
|
208
232
|
>**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
209
233
|
>**_Peter>_** `@smart-bot on #the_channel ^ruby puts Time.now`
|
210
234
|
>. . . . . . . . .**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
211
235
|
|
236
|
+
Examples on DM:
|
237
|
+
>**_Peter>_** `#sales show report from India`
|
238
|
+
>**_Peter>_** `on #sales notify clients`
|
239
|
+
|
212
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 '-^'
|
213
241
|
|
214
242
|
Examples:
|
@@ -220,13 +248,22 @@ Examples:
|
|
220
248
|
>. . . . . . . . .**_Smart-Bot>_** `a`
|
221
249
|
>. . . . . . . . .**_Smart-Bot>_** `b`
|
222
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
|
+
|
223
258
|
### 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.
|
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.
|
225
260
|
|
226
|
-
If you want to search just for a specific command: **_`bot help COMMAND`_**
|
261
|
+
If you want to search just for a specific command: **_`bot help COMMAND`_** It will display expanded explanations for the command.
|
227
262
|
|
228
263
|
To show only the specific rules of the Smart Bot defined on the rules file: **_`bot rules`_** or **_`bot rules COMMAND`_**
|
229
264
|
|
265
|
+
Also you can call `suggest command` or `random command` and SmartBot will return the help content for a random command.
|
266
|
+
|
230
267
|
Example:
|
231
268
|
>**_Peter>_** `bot help echo`
|
232
269
|
>**_Smart-Bot>_** `echo SOMETHING`
|
@@ -239,6 +276,7 @@ Remember when you add code to your rules you need to specify the help that will
|
|
239
276
|
For the examples use _ and for the rules `. This is a good example of a Help supplied on rules source code:
|
240
277
|
|
241
278
|
```ruby
|
279
|
+
# help: ----------------------------------------------
|
242
280
|
# help: `run TYPE tests on LOCATION`
|
243
281
|
# help: `execute TYPE tests on LOCATION`
|
244
282
|
# help: run the specified tests on the indicated location
|
@@ -250,6 +288,8 @@ For the examples use _ and for the rules `. This is a good example of a Help sup
|
|
250
288
|
# help: _execute smoke tests on db1_
|
251
289
|
```
|
252
290
|
|
291
|
+
To see what's new just call `What's new`
|
292
|
+
|
253
293
|
### Bot Management
|
254
294
|
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
295
|
|
@@ -259,9 +299,13 @@ If you want to pause a bot, from the channel of the bot: **_`pause bot`_**. To s
|
|
259
299
|
|
260
300
|
To see the status of the bots, on the MASTER CHANNEL: **_`bot status`_**
|
261
301
|
|
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.
|
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
|
+
|
262
306
|
To close the Master Bot, run on MASTER CHANNEL: **_`exit bot`_**
|
263
307
|
|
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.
|
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.
|
265
309
|
|
266
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.
|
267
311
|
|
@@ -291,7 +335,7 @@ Example:
|
|
291
335
|
>**_Peter>_** `!ruby require 'json'; res=[]; 20.times {res.push rand(100)}; my_json={result: res}; puts my_json.to_json`
|
292
336
|
>**_Smart-Bot>_** `{"result":[63,66,35,83,44,40,72,25,59,73,75,54,56,91,19,6,68,1,25,3]}`
|
293
337
|
|
294
|
-
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.
|
295
339
|
|
296
340
|
#### REPL
|
297
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.
|
@@ -309,7 +353,7 @@ If you declare on your rules file a method called `project_folder` returning the
|
|
309
353
|
|
310
354
|
By default it will be automatically loaded the gems: `string_pattern`, `nice_hash` and `nice_http`
|
311
355
|
|
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`
|
356
|
+
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
357
|
|
314
358
|
If you want to see the methods of a class or module you created use `ls TheModuleOrClass`
|
315
359
|
|
@@ -367,7 +411,7 @@ That shortcut will be available for you, in case you want to make it available f
|
|
367
411
|
Example:
|
368
412
|
>**_Peter>_** `!add shortcut for all spanish bank account: ruby require 'iso/iban'; 3.times {puts ISO::IBAN.random('ES')}`
|
369
413
|
>**_Smart-Bot>_** `shortcut added`
|
370
|
-
>**
|
414
|
+
>**_John>_** `!spanish bank account`
|
371
415
|
>**_Smart-Bot>_** `ES4664553191352006861448`
|
372
416
|
`ES4799209592433480943244`
|
373
417
|
`ES8888795057132445752702`
|
@@ -385,18 +429,63 @@ Example:
|
|
385
429
|
|
386
430
|
To see available shortcuts: **_`see shortcuts`_** and to delete a particular shortcut: **_`delete shortcut NAME`_**
|
387
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
|
+
|
388
471
|
### Routines
|
389
|
-
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`_
|
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.
|
473
|
+
|
474
|
+
In case you create a *bgroutine* instead of a normal *routine* then the results of the run won't be published.
|
390
475
|
|
391
476
|
If you want to hide the routine executions use `add silent routine`. It won't show the routine name when executing.
|
392
477
|
|
478
|
+
To see the last result of the execution you can call `see result routine NAME`
|
479
|
+
|
393
480
|
Examples:
|
394
481
|
>**_`add routine run_tests every 3h !run tests on customers`_**
|
395
|
-
>**_`add
|
396
|
-
>**_`add silent
|
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`_**
|
397
484
|
>**_`add routine clean_custdb on Mondays at 05:00 !clean customers db`_**
|
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`_**
|
398
487
|
|
399
|
-
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
|
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.
|
400
489
|
|
401
490
|
Other routine commands:
|
402
491
|
* **_`pause routine NAME`_**
|
@@ -404,6 +493,7 @@ Other routine commands:
|
|
404
493
|
* **_`remove routine NAME`_**
|
405
494
|
* **_`run routine NAME`_**
|
406
495
|
* **_`see routines`_**
|
496
|
+
* **_`see result routine NAME`_**
|
407
497
|
|
408
498
|
### Limit who has access to a command
|
409
499
|
|
@@ -429,10 +519,26 @@ If you want to change who has access to a certain command without restarting the
|
|
429
519
|
config.allow_access.repl = ['marioruiz', 'samcooke']
|
430
520
|
```
|
431
521
|
|
432
|
-
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`
|
525
|
+
|
526
|
+
To check from a rule if the user has access to it:
|
527
|
+
|
528
|
+
```ruby
|
529
|
+
if has_access?(:your_command_id)
|
530
|
+
end
|
531
|
+
```
|
532
|
+
|
533
|
+
### See favorite commands
|
433
534
|
|
434
|
-
|
535
|
+
It will display the favorite commands in that channel.
|
435
536
|
|
537
|
+
Examples:
|
538
|
+
>**_`see favorite commands`_**
|
539
|
+
>**_`favorite commands`_**
|
540
|
+
>**_`my favourite commands`_**
|
541
|
+
>**_`most used commands`_**
|
436
542
|
|
437
543
|
### Tips
|
438
544
|
|
@@ -3,54 +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
|
-
|
7
|
-
dest
|
8
|
-
|
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]}|#{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]
|
27
9
|
end
|
28
|
-
if
|
29
|
-
|
30
|
-
f.puts "|#{@channel_id}|#{config[:nick_id]}|#{message}"
|
31
|
-
}
|
10
|
+
if to.nil?
|
11
|
+
to = Thread.current[:user].name
|
32
12
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
13
|
+
if context.nil?
|
14
|
+
context = Thread.current[:command]
|
15
|
+
end
|
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
|
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
|
+
}
|
43
52
|
end
|
53
|
+
elsif dest[0] == "D" #private message
|
54
|
+
send_msg_user(dest, message)
|
44
55
|
end
|
45
|
-
if
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
if Thread.current[:on_thread]
|
57
|
+
qdest = Thread.current[:thread_ts]
|
58
|
+
else
|
59
|
+
qdest = dest
|
49
60
|
end
|
50
|
-
|
51
|
-
|
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
|
52
66
|
end
|
53
|
-
@questions[to] = context
|
54
67
|
end
|
55
68
|
|
56
69
|
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")
|
@@ -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
|
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
|
@@ -0,0 +1,34 @@
|
|
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
|
+
save_status :on, :connected, m
|
7
|
+
|
8
|
+
@logger.info m
|
9
|
+
config.nick = client.self.name
|
10
|
+
config.nick_id = client.self.id
|
11
|
+
end
|
12
|
+
@salutations = [config[:nick], "<@#{config[:nick_id]}>", "@#{config[:nick]}", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
|
13
|
+
|
14
|
+
gems_remote = `gem list slack-smart-bot --remote`
|
15
|
+
version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
|
16
|
+
version_message = ""
|
17
|
+
if Gem::Version.new(version_remote) > Gem::Version.new(VERSION)
|
18
|
+
version_message = ". There is a new available version: #{version_remote}."
|
19
|
+
end
|
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
|
24
|
+
ENV['BOT_SILENT'] = 'true' if config[:silent] and ENV['BOT_SILENT'].to_s != 'true'
|
25
|
+
end
|
26
|
+
@routines.each do |ch, rout|
|
27
|
+
rout.each do |k, v|
|
28
|
+
if !v[:running] and v[:channel_name] == config.channel
|
29
|
+
create_routine_thread(k, v)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|