slack-smart-bot 1.1.2 → 1.2.0
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 +22 -2
- data/lib/slack-smart-bot.rb +1 -1
- data/lib/slack-smart-bot_rules.rb +2 -1
- data/lib/slack/smart-bot/comm.rb +2 -2
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +10 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +0 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +1 -0
- data/lib/slack/smart-bot/process.rb +9 -8
- data/lib/slack/smart-bot/treat_message.rb +5 -4
- data/lib/slack/smart-bot/utils.rb +15 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b75a6cea93322f420ba6e0bf6938609a600d889c4788f0e51e4929a075578d15
|
4
|
+
data.tar.gz: 8d3c0476510dd29d2dfac41eabfceb77f9d604100704815c775c3888002ef35c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 946fbf6bca9a5a704b0b7d1d46e12faeb25e6f7f44e99d867d5a28b07cc2441bac0d93e17d3cdae3f081b4acc8b59092b89b2903fcc9eec6282b84b383d6fb8f
|
7
|
+
data.tar.gz: c976933c3b0bbb67e9ba86778b2068ff75dd42a7470a1ba48bb08f49ae70415907f560a5454cb3835526732d6a8d3e47b80e68c404d017577428d6f6a791d4ff
|
data/README.md
CHANGED
@@ -204,6 +204,23 @@ Example:
|
|
204
204
|
>**_Smart-Bot>_** `echo SOMETHING`
|
205
205
|
`repeats SOMETHING`
|
206
206
|
|
207
|
+
When you call a command that is not recognized, you will get suggestions from the Smart Bot.
|
208
|
+
|
209
|
+
Remember when you add code to your rules you need to specify the help that will be displayed when using `bot help`, `bot rules`
|
210
|
+
|
211
|
+
For the examples use _ and for the rules `. This is a good example of a Help supplied on rules source code:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
# help: `run TYPE tests on LOCATION`
|
215
|
+
# help: `execute TYPE tests on LOCATION`
|
216
|
+
# help: run the specified tests on the indicated location
|
217
|
+
# help: TYPE: api, ui, smoke, load
|
218
|
+
# help: LOCATION: customers, db1..db10, global
|
219
|
+
# help: Examples:
|
220
|
+
# help: _run api tests on customers_
|
221
|
+
# help: _run ui tests on customers_
|
222
|
+
# help: _execute smoke tests on db1_
|
223
|
+
```
|
207
224
|
|
208
225
|
### Bot Management
|
209
226
|
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.
|
@@ -272,9 +289,12 @@ To see available shortcuts: **_`see shortcuts`_** and to delete a particular sho
|
|
272
289
|
### Routines
|
273
290
|
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`_**
|
274
291
|
|
292
|
+
If you want to hide the routine executions use `add silent routine`. It won't show the routine name when executing.
|
293
|
+
|
275
294
|
Examples:
|
276
|
-
>**_`add routine run_tests every 3h run tests on customers`_**
|
277
|
-
>**_`add routine clean_db at 17:05 clean customers temp db`_**
|
295
|
+
>**_`add routine run_tests every 3h !run tests on customers`_**
|
296
|
+
>**_`add routine clean_db at 17:05 !clean customers temp db`_**
|
297
|
+
>**_`add silent routine clean_db at 17:05 !clean customers temp db`_**
|
278
298
|
|
279
299
|
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.
|
280
300
|
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -8,6 +8,7 @@ require "fileutils"
|
|
8
8
|
require "open3"
|
9
9
|
require "nice_http"
|
10
10
|
require "nice_hash"
|
11
|
+
require 'cgi'
|
11
12
|
|
12
13
|
require_relative "slack/smart-bot/comm"
|
13
14
|
require_relative "slack/smart-bot/listen"
|
@@ -94,7 +95,6 @@ class SlackSmartBot
|
|
94
95
|
|
95
96
|
logfile = File.basename(config.rules_file.gsub("_rules_", "_logs_"), ".rb") + ".log"
|
96
97
|
@logger = Logger.new("#{config.path}/logs/#{logfile}")
|
97
|
-
@logger.info ARGV.inspect #Jal
|
98
98
|
|
99
99
|
config_log = config.dup
|
100
100
|
config_log.delete(:token)
|
@@ -41,7 +41,8 @@ def rules(user, command, processed, dest, files = [], rules_file = "")
|
|
41
41
|
# help: ----------------------------------------------
|
42
42
|
# help: `echo SOMETHING`
|
43
43
|
# help: repeats SOMETHING
|
44
|
-
# help:
|
44
|
+
# help: Examples:
|
45
|
+
# help: _echo I am the Smart Bot_
|
45
46
|
when /^echo\s(.+)/i
|
46
47
|
respond $1
|
47
48
|
|
data/lib/slack/smart-bot/comm.rb
CHANGED
@@ -113,14 +113,14 @@ class SlackSmartBot
|
|
113
113
|
end
|
114
114
|
if config[:simulate]
|
115
115
|
open("#{config.path}/buffer_complete.log", "a") { |f|
|
116
|
-
f.puts "|#{
|
116
|
+
f.puts "|#{channel_id}|#{config[:nick_id]}|#{msg}$$$"
|
117
117
|
}
|
118
118
|
else
|
119
119
|
client.message(channel: channel_id, text: msg, as_user: true)
|
120
120
|
end
|
121
121
|
if config[:testing] and config.on_master_bot
|
122
122
|
open("#{config.path}/buffer.log", "a") { |f|
|
123
|
-
f.puts "|#{
|
123
|
+
f.puts "|#{channel_id}|#{config[:nick_id]}|#{msg}"
|
124
124
|
}
|
125
125
|
end
|
126
126
|
end
|
@@ -2,12 +2,15 @@ class SlackSmartBot
|
|
2
2
|
# helpadmin: ----------------------------------------------
|
3
3
|
# helpadmin: `add routine NAME every NUMBER PERIOD COMMAND`
|
4
4
|
# helpadmin: `add routine NAME every NUMBER PERIOD`
|
5
|
+
# helpadmin: `add silent routine NAME every NUMBER PERIOD`
|
5
6
|
# helpadmin: `create routine NAME every NUMBER PERIOD`
|
6
7
|
# helpadmin: `add routine NAME at TIME COMMAND`
|
7
8
|
# helpadmin: `add routine NAME at TIME`
|
9
|
+
# helpadmin: `add silent routine NAME at TIME`
|
8
10
|
# helpadmin: `create routine NAME at TIME`
|
9
|
-
# helpadmin: It will execute the command supplied. Only for Admin and Master Admins.
|
11
|
+
# helpadmin: It will execute the command/rule supplied. Only for Admin and Master Admins.
|
10
12
|
# helpadmin: If no COMMAND supplied, then it will be necessary to attach a file with the code to be run and add this command as message to the file. ONLY for MASTER ADMINS.
|
13
|
+
# helpadmin: In case *silent* provided then when executed will be only displayed if the routine returns a message
|
11
14
|
# helpadmin: NAME: one word to identify the routine
|
12
15
|
# helpadmin: NUMBER: Integer
|
13
16
|
# helpadmin: PERIOD: days, d, hours, h, minutes, mins, min, m, seconds, secs, sec, s
|
@@ -17,8 +20,9 @@ class SlackSmartBot
|
|
17
20
|
# helpadmin: _add routine example every 30s ruby puts 'a'_
|
18
21
|
# helpadmin: _add routine example every 3 days ruby puts 'a'_
|
19
22
|
# helpadmin: _add routine example at 17:05 ruby puts 'a'_
|
23
|
+
# helpadmin: _create silent routine every 12 hours !Run customer tests_
|
20
24
|
# helpadmin:
|
21
|
-
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files)
|
25
|
+
def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent)
|
22
26
|
if files.nil? or files.size == 0 or (files.size > 0 and config.masters.include?(from))
|
23
27
|
if config.admins.include?(from)
|
24
28
|
if @routines.key?(@channel_id) && @routines[@channel_id].key?(name)
|
@@ -70,8 +74,10 @@ class SlackSmartBot
|
|
70
74
|
|
71
75
|
@routines[@channel_id] = {} unless @routines.key?(@channel_id)
|
72
76
|
@routines[@channel_id][name] = { channel_name: config.channel, creator: from, creator_id: user.id, status: :on,
|
73
|
-
every: every, every_in_seconds: every_in_seconds, at: at, file_path: file_path,
|
74
|
-
|
77
|
+
every: every, every_in_seconds: every_in_seconds, at: at, file_path: file_path,
|
78
|
+
command: command_to_run.to_s.strip, silent: silent,
|
79
|
+
next_run: next_run.to_s, dest: dest, last_run: "", last_elapsed: "",
|
80
|
+
running: false }
|
75
81
|
update_routines
|
76
82
|
respond "Added routine *`#{name}`* to the channel", dest
|
77
83
|
create_routine_thread(name)
|
@@ -11,15 +11,12 @@ class SlackSmartBot
|
|
11
11
|
# helpadmin: _kill routine example_
|
12
12
|
# helpadmin:
|
13
13
|
def remove_routine(dest, from, name)
|
14
|
-
@logger.info "Start:#{Time.now}"
|
15
14
|
if config.admins.include?(from) #admin user
|
16
15
|
if !config.on_master_bot and dest[0] == "D"
|
17
16
|
respond "It's only possible to remove routines from MASTER channel from a direct message with the bot.", dest
|
18
17
|
elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
|
19
18
|
@routines[@channel_id].delete(name)
|
20
|
-
@logger.info "Cont:#{Time.now}"
|
21
19
|
update_routines()
|
22
|
-
@logger.info "end:#{Time.now}"
|
23
20
|
respond "The routine *`#{name}`* has been removed.", dest
|
24
21
|
else
|
25
22
|
respond "There isn't a routine with that name: *`#{name}`*.\nCall `see routines` to see added routines", dest
|
@@ -27,6 +24,5 @@ class SlackSmartBot
|
|
27
24
|
else
|
28
25
|
respond "Only admin users can delete routines", dest
|
29
26
|
end
|
30
|
-
@logger.info "fin:#{Time.now}"
|
31
27
|
end
|
32
28
|
end
|
@@ -48,6 +48,7 @@ class SlackSmartBot
|
|
48
48
|
msg << "\tTime consumed on last run: #{v[:last_elapsed]}" unless v[:command] !=''
|
49
49
|
msg << "\tCommand: #{v[:command]}" unless v[:command].to_s.strip == ''
|
50
50
|
msg << "\tFile: #{v[:file_path]}" unless v[:file_path] == ''
|
51
|
+
msg << "\tSilent: #{v[:silent]}" unless !v[:silent]
|
51
52
|
respond msg.join("\n"), dest
|
52
53
|
end
|
53
54
|
end
|
@@ -86,14 +86,15 @@ class SlackSmartBot
|
|
86
86
|
when /^\s*kill\sbot\son\s<#C\w+\|(.+)>\s*$/i, /^kill\sbot\son\s(.+)\s*$/i
|
87
87
|
channel = $1
|
88
88
|
kill_bot_on_channel(dest, from, channel)
|
89
|
-
when /^\s*(add|create)\s+routine\s+(\w+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s.+)?\s*$/i,
|
90
|
-
/^\s*(add|create)\s+routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s.+)?\s*$/i
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
when /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(every)\s+(\d+)\s*(days|hours|minutes|seconds|mins|min|secs|sec|d|h|m|s)\s*(\s.+)?\s*$/i,
|
90
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s.+)?\s*$/i
|
91
|
+
silent = $2.to_s!=''
|
92
|
+
name = $3.downcase
|
93
|
+
type = $4
|
94
|
+
number_time = $5
|
95
|
+
period = $6
|
96
|
+
command_to_run = $7
|
97
|
+
add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent)
|
97
98
|
when /^\s*(kill|delete|remove)\s+routine\s+(\w+)\s*$/i
|
98
99
|
name = $2.downcase
|
99
100
|
remove_routine(dest, from, name)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
def treat_message(data)
|
3
|
+
data.text = CGI.unescapeHTML(data.text)
|
3
4
|
if config[:testing] and config.on_master_bot
|
4
5
|
open("#{config.path}/buffer.log", "a") { |f|
|
5
6
|
f.puts "|#{data.channel}|#{data.user}|#{data.text}"
|
@@ -109,21 +110,21 @@ class SlackSmartBot
|
|
109
110
|
elsif @status != :on
|
110
111
|
respond "The bot in that channel is not :on", dest
|
111
112
|
elsif data.user == channel_found.creator or members.include?(data.user)
|
112
|
-
|
113
|
+
process_first(user_info.user, command, dest, channel_rules, typem, data.files)
|
113
114
|
else
|
114
115
|
respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
|
115
116
|
end
|
116
117
|
elsif config.on_master_bot and typem == :on_extended and
|
117
118
|
command.size > 0 and command[0] != "-"
|
118
119
|
# to run ruby only from the master bot for the case more than one extended
|
119
|
-
|
120
|
+
process_first(user_info.user, command, dest, @channel_id, typem, data.files)
|
120
121
|
elsif !config.on_master_bot and @bots_created[@channel_id].key?(:extended) and
|
121
122
|
@bots_created[@channel_id][:extended].include?(@channels_name[data.channel]) and
|
122
123
|
command.size > 0 and command[0] != "-"
|
123
|
-
|
124
|
+
process_first(user_info.user, command, dest, @channel_id, typem, data.files)
|
124
125
|
elsif (dest[0] == "D" or @channel_id == data.channel or data.user == config[:nick_id]) and
|
125
126
|
command.size > 0 and command[0] != "-"
|
126
|
-
|
127
|
+
process_first(user_info.user, command, dest, data.channel, typem, data.files)
|
127
128
|
# if @botname on #channel_rules: do something
|
128
129
|
end
|
129
130
|
rescue Exception => stack
|
@@ -83,6 +83,8 @@ class SlackSmartBot
|
|
83
83
|
else
|
84
84
|
ruby = ""
|
85
85
|
end
|
86
|
+
@routines[@channel_id][name][:silent] = false if !@routines[@channel_id][name].key?(:silent)
|
87
|
+
|
86
88
|
if @routines[@channel_id][name][:at] == "" or
|
87
89
|
(@routines[@channel_id][name][:at] != "" and @routines[@channel_id][name][:running] and
|
88
90
|
@routines[@channel_id][name][:next_run] != "" and Time.now.to_s >= @routines[@channel_id][name][:next_run])
|
@@ -91,20 +93,26 @@ class SlackSmartBot
|
|
91
93
|
process_to_run = ("cd #{project_folder} &&" + process_to_run) if defined?(project_folder)
|
92
94
|
|
93
95
|
stdout, stderr, status = Open3.capture3(process_to_run)
|
96
|
+
if !@routines[@channel_id][name][:silent] or (@routines[@channel_id][name][:silent] and (stderr!='' or stdout!=''))
|
97
|
+
respond "routine *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
|
98
|
+
end
|
94
99
|
if stderr == ""
|
95
100
|
unless stdout.match?(/\A\s*\z/)
|
96
|
-
respond
|
101
|
+
respond stdout, @routines[@channel_id][name][:dest]
|
97
102
|
end
|
98
103
|
else
|
99
|
-
respond "
|
104
|
+
respond "#{stdout} #{stderr}", @routines[@channel_id][name][:dest]
|
100
105
|
end
|
101
106
|
else #command
|
102
|
-
|
107
|
+
if !@routines[@channel_id][name][:silent]
|
108
|
+
respond "routine *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
|
109
|
+
end
|
103
110
|
started = Time.now
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
111
|
+
data = { channel: @routines[@channel_id][name][:dest],
|
112
|
+
user: @routines[@channel_id][name][:creator_id],
|
113
|
+
text: @routines[@channel_id][name][:command],
|
114
|
+
files: nil }
|
115
|
+
treat_message(data)
|
108
116
|
end
|
109
117
|
# in case the routine was deleted while running the process
|
110
118
|
if !@routines.key?(@channel_id) or !@routines[@channel_id].key?(name)
|
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.
|
4
|
+
version: 1.2.0
|
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-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|