slack-smart-bot 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 031aceba04e6017cd314ba2be33d0e6cee0326e74f2301ef17da4ea5e932f315
|
4
|
+
data.tar.gz: 3dc24d0bcf047d2cdab12f8d9dde3ee3f2b4817ce9f94264057fce54ea95f00a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f067e911e6748530944a0ec7534e54bd631c3549404cd3dd8b6d9ab69c004a8af7318916f68a0bc4e74289abc5f51d9b785147fdb275bc627e46abdd714f988
|
7
|
+
data.tar.gz: 7cac3469e1320b94a4777c48069033b6b0e53d33f1c800b8fb0bed43b93ff4e82a03ce89ee59c158a94ad0964e76544f7a3d4c1af0091787ba6d0dfd241f7d2a
|
data/README.md
CHANGED
@@ -174,8 +174,8 @@ To run a command on demand:
|
|
174
174
|
**_`!THE_COMMAND`_**
|
175
175
|
**_`@NAME_OF_BOT THE_COMMAND`_**
|
176
176
|
**_`NAME_OF_BOT THE_COMMAND`_**
|
177
|
-
To run a command on demand and add the respond on a thread:
|
178
|
-
**_`^THE_COMMAND`_**
|
177
|
+
To run a command on demand and add the respond on a thread:
|
178
|
+
**_`^THE_COMMAND`_**
|
179
179
|
**_`!!THE_COMMAND`_**
|
180
180
|
|
181
181
|
Examples run a command on demand:
|
@@ -187,21 +187,30 @@ Examples run a command on demand:
|
|
187
187
|
|
188
188
|
>**_Peter>_** `smart-bot see shortcuts`
|
189
189
|
>**_Smart-Bot>_** `Available shortcuts for Peter:`
|
190
|
-
>`Spanish account: ruby require 'iso/iban'; 10.times {puts ISO::IBAN.random('ES')}`
|
191
|
-
>**_Peter>_** `!!echo Example`
|
192
|
-
|
193
|
-
>**_Peter>_** `^echo Example`
|
194
|
-
|
190
|
+
>`Spanish account: ruby require 'iso/iban'; 10.times {puts ISO::IBAN.random('ES')}`
|
191
|
+
>**_Peter>_** `!!echo Example`
|
192
|
+
>. . . . . . . . .**_Smart-Bot>_** `Example`
|
193
|
+
>**_Peter>_** `^echo Example`
|
194
|
+
>. . . . . . . . .**_Smart-Bot>_** `Example`
|
195
195
|
|
196
196
|
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.
|
197
197
|
|
198
198
|
Example:
|
199
199
|
>**_Peter>_** `@smart-bot on #the_channel ruby puts Time.now`
|
200
|
-
>**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
200
|
+
>**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
201
201
|
>**_Peter>_** `@smart-bot on #the_channel ^ruby puts Time.now`
|
202
|
-
|
202
|
+
>. . . . . . . . .**_Smart-Bot>_** `2019-10-23 12:43:42 +0000`
|
203
|
+
|
204
|
+
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 '-^'
|
203
205
|
|
206
|
+
Examples:
|
207
|
+
>**_Peter>_** ``-!This text won't be treated but this one yes `ruby puts 'a'` and also this one `ruby puts 'b'` ``
|
208
|
+
>**_Smart-Bot>_** `a`
|
209
|
+
>**_Smart-Bot>_** `b`
|
204
210
|
|
211
|
+
>**_Peter>_** ``-^This text won't be treated but this one yes `ruby puts 'a'` and also this one `ruby puts 'b'` ``
|
212
|
+
>. . . . . . . . .**_Smart-Bot>_** `a`
|
213
|
+
>. . . . . . . . .**_Smart-Bot>_** `b`
|
205
214
|
|
206
215
|
### Bot Help
|
207
216
|
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.
|
@@ -244,7 +253,7 @@ To see the status of the bots, on the MASTER CHANNEL: **_`bot status`_**
|
|
244
253
|
|
245
254
|
To close the Master Bot, run on MASTER CHANNEL: **_`exit bot`_**
|
246
255
|
|
247
|
-
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
|
256
|
+
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.
|
248
257
|
|
249
258
|
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.
|
250
259
|
|
@@ -4,28 +4,31 @@ class SlackSmartBot
|
|
4
4
|
#send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", 'message to be sent', 'text/plain', "text")
|
5
5
|
#send_file(dest, 'the message', "#{project_folder}/temp/example.jpeg", 'message to be sent', 'image/jpeg', "jpg")
|
6
6
|
def send_file(to, msg, file, title, format, type = "text")
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
ts = Thread.current[:thread_ts]
|
15
|
-
else
|
16
|
-
ts = nil
|
17
|
-
end
|
7
|
+
unless config[:simulate]
|
8
|
+
if to[0] == "U" #user
|
9
|
+
im = client.web_client.im_open(user: to)
|
10
|
+
channel = im["channel"]["id"]
|
11
|
+
else
|
12
|
+
channel = to
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
if Thread.current[:on_thread]
|
16
|
+
ts = Thread.current[:thread_ts]
|
17
|
+
else
|
18
|
+
ts = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
client.web_client.files_upload(
|
22
|
+
channels: channel,
|
23
|
+
as_user: true,
|
24
|
+
file: Faraday::UploadIO.new(file, format),
|
25
|
+
title: title,
|
26
|
+
filename: file,
|
27
|
+
filetype: type,
|
28
|
+
initial_comment: msg,
|
29
|
+
thread_ts: ts
|
30
|
+
)
|
31
|
+
end
|
29
32
|
end
|
30
33
|
|
31
34
|
end
|
@@ -44,7 +44,7 @@ class SlackSmartBot
|
|
44
44
|
to+= " 23:59:59 +0000"
|
45
45
|
rows = []
|
46
46
|
|
47
|
-
Dir["#{config.stats_path}.*.log"].each do |file|
|
47
|
+
Dir["#{config.stats_path}.*.log"].sort.each do |file|
|
48
48
|
if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
|
49
49
|
CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
|
50
50
|
row[:date] = row[:date].to_s
|
@@ -14,9 +14,27 @@ class SlackSmartBot
|
|
14
14
|
channel = message[0].strip
|
15
15
|
user = message[1].strip
|
16
16
|
command = message[2].to_s.strip
|
17
|
-
# take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
|
17
|
+
# take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
|
18
18
|
@logger.info "treat message: #{message}" if config.testing
|
19
|
-
|
19
|
+
|
20
|
+
|
21
|
+
if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
|
22
|
+
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
23
|
+
if cmd.to_s!=''
|
24
|
+
cmd = "^#{cmd}"
|
25
|
+
treat_message({channel: channel, user: user, text: cmd}, false)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
elsif command.match?(/^\s*\-!/)
|
29
|
+
command.scan(/`([^`]+)`/).flatten.each do |cmd|
|
30
|
+
if cmd.to_s!=''
|
31
|
+
cmd = "!#{cmd}"
|
32
|
+
treat_message({channel: channel, user: user, text: cmd}, false)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
treat_message({channel: channel, user: user, text: command})
|
37
|
+
end
|
20
38
|
end
|
21
39
|
end
|
22
40
|
end
|
@@ -26,8 +44,26 @@ class SlackSmartBot
|
|
26
44
|
get_bots_created()
|
27
45
|
|
28
46
|
client.on :message do |data|
|
29
|
-
unless data.user == "USLACKBOT"
|
30
|
-
|
47
|
+
unless data.user == "USLACKBOT" or data.text.nil?
|
48
|
+
if data.text.match?(/^\s*\-!!/) or data.text.match?(/^\s*\-\^/)
|
49
|
+
data.text.scan(/`([^`]+)`/).flatten.each do |cmd|
|
50
|
+
if cmd.to_s!=''
|
51
|
+
datao = data.dup
|
52
|
+
datao.text = "^#{cmd}"
|
53
|
+
treat_message(datao, false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
elsif data.text.match?(/^\s*\-!/)
|
57
|
+
data.text.scan(/`([^`]+)`/).flatten.each do |cmd|
|
58
|
+
if cmd.to_s!=''
|
59
|
+
datao = data.dup
|
60
|
+
datao.text = "!#{cmd}"
|
61
|
+
treat_message(datao, false)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
else
|
65
|
+
treat_message(data)
|
66
|
+
end
|
31
67
|
end
|
32
68
|
end
|
33
69
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class SlackSmartBot
|
2
|
-
def treat_message(data)
|
2
|
+
def treat_message(data, remove_blocks = true)
|
3
3
|
begin
|
4
4
|
unless data.text.to_s.match(/\A\s*\z/)
|
5
5
|
#to remove italic, bold... from data.text since there is no method on slack api
|
6
6
|
#only works when no @user or #channel mentioned
|
7
|
-
if !data.blocks.nil? and data.blocks.size > 0
|
7
|
+
if remove_blocks and !data.blocks.nil? and data.blocks.size > 0
|
8
8
|
data.blocks.each do |b|
|
9
9
|
if b.type == 'rich_text'
|
10
10
|
if b.elements.size > 0
|
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.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|