slack-smart-bot 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/slack-smart-bot.rb +21 -10
- data/lib/slack-smart-bot_rules.rb +8 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce07df2e804e969dd1b1b290444c144e4ebcc753eb438584f2106a21080db797
|
4
|
+
data.tar.gz: cd7ed3bc70ed721a7e8661a664c8875ff148a643fedf5e594f5bb624273d7645
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65f819cb1c85ef79445d096db1964b8986acb3d227b0ba1aa01d0af9af89d665b48e054a770af47f14bb61aac26e4cf5cf1dd32295d0f650181c0027af0a89fd
|
7
|
+
data.tar.gz: 01ba1e3085060d40267a492170d099739f61f61a64ad2ef2868c502366ca1d10c07c7059cd86da0addd71fc9c07f028087c852a7cf2d086363ee0eb41084e3b5
|
data/README.md
CHANGED
@@ -8,6 +8,23 @@ The main scope of this ruby gem is to be used internally in your company so team
|
|
8
8
|
|
9
9
|
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.
|
10
10
|
|
11
|
+
# Table of Contents
|
12
|
+
|
13
|
+
- [Installation and configuration](#installation-and-configuration)
|
14
|
+
- [Usage](#usage)
|
15
|
+
* [creating the MASTER BOT](#creating-the-master-bot)
|
16
|
+
* [How to access the smart bot](#how-to-access-the-smart-bot)
|
17
|
+
* [Available commands even when the bot is not listening to you](#available-commands-even-when-the-bot-is-not-listening-to-you)
|
18
|
+
* [Available commands only when listening to you or on demand or in a private conversation with the Smart Bot](#available-commands-only-when-listening-to-you-or-on-demand-or-in-a-private-conversation-with-the-smart-bot)
|
19
|
+
* [Available commands from channels without a Smart Bot](#available-commands-from-channels-without-a-smart-bot)
|
20
|
+
* [Creating cloud bots](#creating-cloud-bots)
|
21
|
+
* [Tips](#tips)
|
22
|
+
+ [Send a file](#send-a-file)
|
23
|
+
+ [Download a file](#download-a-file)
|
24
|
+
- [Contributing](#contributing)
|
25
|
+
- [License](#license)
|
26
|
+
|
27
|
+
|
11
28
|
## Installation and configuration
|
12
29
|
|
13
30
|
$ gem install slack-smart-bot
|
@@ -330,6 +347,30 @@ The new cloud bot will be managed by your Master Bot like the others, closing, p
|
|
330
347
|
|
331
348
|
This is very useful when you need to run certain processes on a different environment for example on a Windows machine while your Master Bot is on Ubuntu.
|
332
349
|
|
350
|
+
### Tips
|
351
|
+
|
352
|
+
#### Send a file
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
send_file(to, msg, filepath, title, format, type = "text")
|
356
|
+
send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", 'title', 'text/plain', "text")
|
357
|
+
send_file(dest, 'the message', "#{project_folder}/temp/example.jpeg", 'title', 'image/jpeg', "jpg")
|
358
|
+
```
|
359
|
+
|
360
|
+
#### Download a file
|
361
|
+
|
362
|
+
When uploading a file the message added to 'Add a message about the file' will be the command treated by the bot rule. Then in your rules file:
|
363
|
+
|
364
|
+
```ruby
|
365
|
+
when /^do something with my file/i
|
366
|
+
if !files.nil? and files.size == 1 and files[0].filetype == 'yaml'
|
367
|
+
require 'nice_http'
|
368
|
+
http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" })
|
369
|
+
res = http.get(files[0].url_private_download, save_data: './tmp/')
|
370
|
+
# if you want to directly access to the content use: `res.data`
|
371
|
+
end
|
372
|
+
```
|
373
|
+
|
333
374
|
## Contributing
|
334
375
|
|
335
376
|
Bug reports and pull requests are welcome on GitHub at https://github.com/marioruiz/slack-smart-bot.
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -209,7 +209,9 @@ class SlackSmartBot
|
|
209
209
|
end
|
210
210
|
#todo: sometimes data.user is nil, check the problem.
|
211
211
|
@logger.warn "!dest is nil. user: #{data.user}, channel: #{data.channel}, message: #{data.text}" if dest.nil?
|
212
|
-
|
212
|
+
if !data.files.nil? and data.files.size == 1 and data.text.to_s == '' and data.files[0].filetype == "ruby"
|
213
|
+
data.text = 'ruby'
|
214
|
+
end
|
213
215
|
typem = :dont_treat
|
214
216
|
if !dest.nil? and !data.text.nil? and !data.text.to_s.match?(/^\s*$/)
|
215
217
|
if data.text.match(/^<@#{config[:nick_id]}>\s(on\s)?<#(\w+)\|(.+)>\s*:?\s*(.*)/im)
|
@@ -252,7 +254,6 @@ class SlackSmartBot
|
|
252
254
|
end
|
253
255
|
end
|
254
256
|
end
|
255
|
-
|
256
257
|
unless typem == :dont_treat
|
257
258
|
begin
|
258
259
|
command = data.text
|
@@ -271,7 +272,8 @@ class SlackSmartBot
|
|
271
272
|
(command.match?(/^(ruby|code)\s*$/) or (command.match?(/^\s*$/) and data.files[0].filetype == "ruby") or
|
272
273
|
(typem==:on_call and data.files[0].filetype == "ruby"))
|
273
274
|
res = Faraday.new("https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" }).get(data.files[0].url_private)
|
274
|
-
command
|
275
|
+
command += " ruby" if command!='ruby'
|
276
|
+
command = "#{command} #{res.body.to_s.force_encoding("UTF-8")}"
|
275
277
|
end
|
276
278
|
|
277
279
|
if typem == :on_call
|
@@ -291,7 +293,7 @@ class SlackSmartBot
|
|
291
293
|
elsif @status != :on
|
292
294
|
respond "The bot in that channel is not :on", dest
|
293
295
|
elsif data.user == channel_found.creator or members.include?(data.user)
|
294
|
-
res = process_first(user_info.user, command, dest, channel_rules, typem)
|
296
|
+
res = process_first(user_info.user, command, dest, channel_rules, typem, data.files)
|
295
297
|
else
|
296
298
|
respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
|
297
299
|
end
|
@@ -299,20 +301,20 @@ class SlackSmartBot
|
|
299
301
|
elsif @questions.keys.include?(user_info.user.name)
|
300
302
|
#todo: @questions key should be the id not the name. change it everywhere
|
301
303
|
dest = data.channel
|
302
|
-
res = process_first(user_info.user, command, dest, @channel_id, typem)
|
304
|
+
res = process_first(user_info.user, command, dest, @channel_id, typem, data.files)
|
303
305
|
|
304
306
|
elsif ON_MASTER_BOT and typem ==:on_extended and
|
305
307
|
command.size > 0 and command[0] != "-"
|
306
308
|
# to run ruby only from the master bot for the case more than one extended
|
307
|
-
res = process_first(user_info.user, command, dest, @channel_id, typem)
|
309
|
+
res = process_first(user_info.user, command, dest, @channel_id, typem, data.files)
|
308
310
|
|
309
311
|
elsif !ON_MASTER_BOT and @bots_created[@channel_id].key?(:extended) and
|
310
312
|
@bots_created[@channel_id][:extended].include?(@channels_name[data.channel]) and
|
311
313
|
command.size > 0 and command[0] != "-"
|
312
|
-
res = process_first(user_info.user, command, dest, @channel_id, typem)
|
314
|
+
res = process_first(user_info.user, command, dest, @channel_id, typem, data.files)
|
313
315
|
elsif (dest[0] == "D" or @channel_id == data.channel or data.user == config[:nick_id]) and
|
314
316
|
command.size > 0 and command[0] != "-"
|
315
|
-
res = process_first(user_info.user, command, dest, data.channel, typem)
|
317
|
+
res = process_first(user_info.user, command, dest, data.channel, typem, data.files)
|
316
318
|
# if @botname on #channel_rules: do something
|
317
319
|
end
|
318
320
|
rescue Exception => stack
|
@@ -325,7 +327,7 @@ class SlackSmartBot
|
|
325
327
|
client.start!
|
326
328
|
end
|
327
329
|
|
328
|
-
def process_first(user, text, dest, dchannel, typem)
|
330
|
+
def process_first(user, text, dest, dchannel, typem, files)
|
329
331
|
nick = user.name
|
330
332
|
rules_file = ""
|
331
333
|
|
@@ -467,7 +469,11 @@ class SlackSmartBot
|
|
467
469
|
if defined?(rules)
|
468
470
|
command[0] = "" if command[0] == "!"
|
469
471
|
command.gsub!(/^@\w+:*\s*/, "")
|
470
|
-
rules
|
472
|
+
if method(:rules).arity == 4
|
473
|
+
rules(user, command, processed, dest)
|
474
|
+
else
|
475
|
+
rules(user, command, processed, dest, files)
|
476
|
+
end
|
471
477
|
else
|
472
478
|
@logger.warn "It seems like rules method is not defined"
|
473
479
|
end
|
@@ -492,6 +498,11 @@ class SlackSmartBot
|
|
492
498
|
command[0] = "" if command[0] == "!"
|
493
499
|
command.gsub!(/^@\w+:*\s*/, "")
|
494
500
|
rules(user, command, processed, dest)
|
501
|
+
if method(:rules).arity == 4
|
502
|
+
rules(user, command, processed, dest)
|
503
|
+
else
|
504
|
+
rules(user, command, processed, dest, files)
|
505
|
+
end
|
495
506
|
else
|
496
507
|
@logger.warn "It seems like rules method is not defined"
|
497
508
|
end
|
@@ -42,7 +42,7 @@ end
|
|
42
42
|
# help: `@NAME_OF_BOT THE_COMMAND`
|
43
43
|
# help: `NAME_OF_BOT THE_COMMAND`
|
44
44
|
# help:
|
45
|
-
def rules(user, command, processed, dest)
|
45
|
+
def rules(user, command, processed, dest, files=[])
|
46
46
|
from = user.name
|
47
47
|
display_name = user.profile.display_name
|
48
48
|
|
@@ -107,6 +107,13 @@ def rules(user, command, processed, dest)
|
|
107
107
|
respond "#{display_name}: #{stderr}", dest
|
108
108
|
end
|
109
109
|
|
110
|
+
# Example downloading a file from slack
|
111
|
+
# if !files.nil? and files.size == 1 and files[0].filetype == 'yaml'
|
112
|
+
# require 'nice_http'
|
113
|
+
# http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" })
|
114
|
+
# http.get(files[0].url_private_download, save_data: './tmp/')
|
115
|
+
# end
|
116
|
+
|
110
117
|
# Examples sending a file to slack:
|
111
118
|
# send_file(to, msg, filepath, title, format, type = "text")
|
112
119
|
# send_file(dest, 'the message', "#{project_folder}/temp/logs_ptBI.log", 'title', 'text/plain', "text")
|
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: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.14.4
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: nice_http
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.7'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.7.19
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.7'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.7.19
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: async-websocket
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|