slack-smart-bot 1.9.1 → 1.9.2
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/lib/slack-smart-bot.rb +1 -0
- data/lib/slack/smart-bot/comm/event_hello.rb +1 -1
- data/lib/slack/smart-bot/comm/respond.rb +28 -7
- data/lib/slack/smart-bot/commands/general/use_rules.rb +5 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +11 -2
- data/lib/slack/smart-bot/process.rb +5 -2
- data/lib/slack/smart-bot/treat_message.rb +15 -3
- data/whats_new.txt +7 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 974b9b2da39dd58e4e404572932ace72c5b9d1136956543ac890cf7bc91ab61e
|
4
|
+
data.tar.gz: a304bbeeecc5177c5014c86902c20d9682e6addfc00ab3f5ee33aeca4dba2215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85e6d1e343b0523b25c5c630d37fcda402a8529d2ae8a1f5473694a65e9311293b4d628bc0e9a18e3910bd68123276b30039e1a50115c97bd029db19a2a9738a
|
7
|
+
data.tar.gz: 90c2441764b9faceeb74d1281c19fccc84c960d4344f5822c5d50293d1de55d300d10373a60e0cf876270aced23f20686844e2cb0503dfb0a30004adeec8e27c
|
data/lib/slack-smart-bot.rb
CHANGED
@@ -61,6 +61,7 @@ class SlackSmartBot
|
|
61
61
|
Dir.mkdir("#{config.path}/logs") unless Dir.exist?("#{config.path}/logs")
|
62
62
|
Dir.mkdir("#{config.path}/shortcuts") unless Dir.exist?("#{config.path}/shortcuts")
|
63
63
|
Dir.mkdir("#{config.path}/routines") unless Dir.exist?("#{config.path}/routines")
|
64
|
+
File.delete("#{config.path}/config_tmp.status") if File.exist?("#{config.path}/config_tmp.status")
|
64
65
|
|
65
66
|
config.masters = MASTER_USERS if config.masters.to_s=='' and defined?(MASTER_USERS)
|
66
67
|
config.master_channel = MASTER_CHANNEL if config.master_channel.to_s=='' and defined?(MASTER_CHANNEL)
|
@@ -16,7 +16,7 @@ class SlackSmartBot
|
|
16
16
|
version_message = ". There is a new available version: #{version_remote}."
|
17
17
|
end
|
18
18
|
if (!config[:silent] or ENV['BOT_SILENT'].to_s == 'false') and !config.simulate
|
19
|
-
ENV['BOT_SILENT'] = 'true' if config[:silent]
|
19
|
+
ENV['BOT_SILENT'] = 'true' if config[:silent] and ENV['BOT_SILENT'].to_s != 'true'
|
20
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
21
|
end
|
22
22
|
@routines.each do |ch, rout|
|
@@ -6,8 +6,11 @@ class SlackSmartBot
|
|
6
6
|
dest = @channels_id[dest] if @channels_id.key?(dest) #it is a name of channel
|
7
7
|
if !config.simulate #https://api.slack.com/docs/rate-limits
|
8
8
|
msg.to_s.size > 500 ? wait = 0.5 : wait = 0.1
|
9
|
-
sleep wait if Time.now <= (@last_respond+wait)
|
9
|
+
sleep wait if Time.now <= (@last_respond+wait)
|
10
|
+
else
|
11
|
+
wait = 0
|
10
12
|
end
|
13
|
+
msgs = msg.chars.each_slice(4000).map(&:join) # max of 4000 characters per message
|
11
14
|
if dest.nil?
|
12
15
|
if config[:simulate]
|
13
16
|
open("#{config.path}/buffer_complete.log", "a") { |f|
|
@@ -15,9 +18,15 @@ class SlackSmartBot
|
|
15
18
|
}
|
16
19
|
else
|
17
20
|
if Thread.current[:on_thread]
|
18
|
-
|
21
|
+
msgs.each do |msg|
|
22
|
+
client.message(channel: @channel_id, text: msg, as_user: true, thread_ts: Thread.current[:thread_ts])
|
23
|
+
sleep wait
|
24
|
+
end
|
19
25
|
else
|
20
|
-
|
26
|
+
msgs.each do |msg|
|
27
|
+
client.message(channel: @channel_id, text: msg, as_user: true)
|
28
|
+
sleep wait
|
29
|
+
end
|
21
30
|
end
|
22
31
|
end
|
23
32
|
if config[:testing] and config.on_master_bot
|
@@ -32,9 +41,15 @@ class SlackSmartBot
|
|
32
41
|
}
|
33
42
|
else
|
34
43
|
if Thread.current[:on_thread]
|
35
|
-
|
44
|
+
msgs.each do |msg|
|
45
|
+
client.message(channel: dest, text: msg, as_user: true, thread_ts: Thread.current[:thread_ts])
|
46
|
+
sleep wait
|
47
|
+
end
|
36
48
|
else
|
37
|
-
|
49
|
+
msgs.each do |msg|
|
50
|
+
client.message(channel: dest, text: msg, as_user: true)
|
51
|
+
sleep wait
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
40
55
|
if config[:testing] and config.on_master_bot
|
@@ -43,11 +58,17 @@ class SlackSmartBot
|
|
43
58
|
}
|
44
59
|
end
|
45
60
|
elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
|
46
|
-
|
61
|
+
msgs.each do |msg|
|
62
|
+
send_msg_user(dest, msg)
|
63
|
+
sleep wait
|
64
|
+
end
|
47
65
|
elsif dest[0] == "@"
|
48
66
|
begin
|
49
67
|
user_info = get_user_info(dest)
|
50
|
-
|
68
|
+
msgs.each do |msg|
|
69
|
+
send_msg_user(user_info.user.id, msg)
|
70
|
+
sleep wait
|
71
|
+
end
|
51
72
|
rescue Exception => stack
|
52
73
|
@logger.warn("user #{dest} not found.")
|
53
74
|
@logger.warn stack
|
@@ -16,12 +16,13 @@ class SlackSmartBot
|
|
16
16
|
else
|
17
17
|
#todo: add pagination for case more than 1000 channels on the workspace
|
18
18
|
channels = get_channels()
|
19
|
-
|
19
|
+
channel.gsub!('#','') # for the case the channel name is in plain text including #
|
20
20
|
channel_found = channels.detect { |c| c.name == channel }
|
21
|
-
|
21
|
+
get_channels_name_and_id() unless @channels_id.key?(channel)
|
22
|
+
members = get_channel_members(@channels_id[channel]) unless channel_found.nil? or !@channels_id.key?(channel)
|
22
23
|
|
23
|
-
if channel_found.nil?
|
24
|
-
respond "The channel you are trying to use doesn't exist", dest
|
24
|
+
if channel_found.nil? or !@channels_id.key?(channel)
|
25
|
+
respond "The channel you are trying to use doesn't exist or cannot be found.", dest
|
25
26
|
elsif channel_found.name == config.master_channel
|
26
27
|
respond "You cannot use the rules from Master Channel on any other channel.", dest
|
27
28
|
elsif !@bots_created.key?(@channels_id[channel])
|
@@ -99,12 +99,21 @@ class SlackSmartBot
|
|
99
99
|
http.get(files[0].url_private_download, save_data: file_path)
|
100
100
|
system("chmod +x #{file_path}")
|
101
101
|
end
|
102
|
-
|
102
|
+
get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
|
103
|
+
channel_id = nil
|
104
|
+
if @channels_name.key?(channel) #it is an id
|
105
|
+
channel_id = channel
|
106
|
+
channel = @channels_name[channel_id]
|
107
|
+
elsif @channels_id.key?(channel) #it is a channel name
|
108
|
+
channel_id = @channels_id[channel]
|
109
|
+
end
|
110
|
+
|
111
|
+
channel_id = dest if channel_id.to_s == ''
|
103
112
|
@routines[@channel_id] = {} unless @routines.key?(@channel_id)
|
104
113
|
@routines[@channel_id][name] = { channel_name: config.channel, creator: from, creator_id: user.id, status: :on,
|
105
114
|
every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, file_path: file_path,
|
106
115
|
command: command_to_run.to_s.strip, silent: silent,
|
107
|
-
next_run: next_run.to_s, dest:
|
116
|
+
next_run: next_run.to_s, dest: channel_id, last_run: "", last_elapsed: "",
|
108
117
|
running: false }
|
109
118
|
update_routines
|
110
119
|
respond "Added routine *`#{name}`* to the channel", dest
|
@@ -27,7 +27,7 @@ class SlackSmartBot
|
|
27
27
|
command = command2
|
28
28
|
on_demand = true
|
29
29
|
end
|
30
|
-
if (on_demand or
|
30
|
+
if (on_demand or typem == :on_dm or
|
31
31
|
(@listening.key?(from) and (@listening[from].key?(dest) or @listening[from].key?(Thread.current[:thread_ts])) )) and
|
32
32
|
config.on_maintenance and !command.match?(/\A(set|turn)\s+maintenance\s+off\s*\z/)
|
33
33
|
respond config.on_maintenance_message, dest
|
@@ -83,8 +83,11 @@ class SlackSmartBot
|
|
83
83
|
when /^\s*kill\s+bot\s+on\s+<#C\w+\|(.+)>\s*$/i, /^kill\s+bot\s+on\s+(.+)\s*$/i
|
84
84
|
channel = $1
|
85
85
|
kill_bot_on_channel(dest, from, channel)
|
86
|
-
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
|
86
|
+
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#(\w+)\s*)(\s.+)?\s*$/i,
|
87
|
+
/^\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<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i,
|
88
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*$/i,
|
87
89
|
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+on\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)s?\s+at\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i,
|
90
|
+
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s#(\w+)\s*)(\s.+)?\s*$/i,
|
88
91
|
/^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i
|
89
92
|
silent = $2.to_s!=''
|
90
93
|
name = $3.downcase
|
@@ -69,14 +69,24 @@ class SlackSmartBot
|
|
69
69
|
end
|
70
70
|
typem = :dont_treat
|
71
71
|
if !dest.nil? and !data.text.nil? and !data.text.to_s.match?(/\A\s*\z/)
|
72
|
-
#
|
73
|
-
if data.text.match(/^\s*<@#{config[:nick_id]}>\s+(on\s+)?((<#\w+\|[^>]+>\s*)+)\s*:?\s*(.*)/im)
|
72
|
+
#todo: we need to add mixed channels: @smart-bot on private1 #bot1cm <#CXDDFRDDF|bot2cu>: echo A
|
73
|
+
if data.text.match(/^\s*<@#{config[:nick_id]}>\s+(on\s+)?((<#\w+\|[^>]+>\s*)+)\s*:?\s*(.*)/im) or
|
74
|
+
data.text.match(/^\s*<@#{config[:nick_id]}>\s+(on\s+)?((#[a-zA-Z0-9]+\s*)+)\s*:?\s*(.*)/im) or
|
75
|
+
data.text.match(/^\s*<@#{config[:nick_id]}>\s+(on\s+)?(([a-zA-Z0-9]+\s*)+)\s*:\s*(.*)/im)
|
74
76
|
channels_rules = $2 #multiple channels @smart-bot on #channel1 #channel2 echo AAA
|
75
77
|
data_text = $4
|
76
78
|
channel_rules_name = ''
|
77
79
|
channel_rules = ''
|
80
|
+
channels_arr = channels_rules.scan(/<#(\w+)\|([^>]+)>/)
|
81
|
+
if channels_arr.size == 0
|
82
|
+
channels_arr = []
|
83
|
+
channels_rules.scan(/([^\s]+)/).each do |cn|
|
84
|
+
cna = cn.join.gsub('#','')
|
85
|
+
channels_arr << [@channels_id[cna], cna]
|
86
|
+
end
|
87
|
+
end
|
78
88
|
# to be treated only on the bots of the requested channels
|
79
|
-
|
89
|
+
channels_arr.each do |tcid, tcname|
|
80
90
|
if @channel_id == tcid
|
81
91
|
data.text = data_text
|
82
92
|
typem = :on_call
|
@@ -234,6 +244,7 @@ class SlackSmartBot
|
|
234
244
|
file_cts = eval(file_cts)
|
235
245
|
if file_cts.is_a?(Hash) and file_cts.key?(:on_maintenance)
|
236
246
|
config.on_maintenance = file_cts.on_maintenance
|
247
|
+
config.on_maintenance_message = file_cts.on_maintenance_message
|
237
248
|
end
|
238
249
|
end
|
239
250
|
end
|
@@ -245,6 +256,7 @@ class SlackSmartBot
|
|
245
256
|
file_cts = eval(file_cts)
|
246
257
|
if file_cts.is_a?(Hash) and file_cts.key?(:on_maintenance)
|
247
258
|
config.on_maintenance = file_cts.on_maintenance
|
259
|
+
config.on_maintenance_message = file_cts.on_maintenance_message
|
248
260
|
end
|
249
261
|
end
|
250
262
|
end
|
data/whats_new.txt
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
*Version 1.9.
|
1
|
+
*Version 1.9.2* Released 2021-Apr-27
|
2
|
+
|
3
|
+
- Bugfixing and small improvements
|
4
|
+
|
5
|
+
------------------------------
|
6
|
+
|
7
|
+
*Version 1.9.0* Released 2021-Mar-18
|
2
8
|
|
3
9
|
*For General users*
|
4
10
|
- Added command `what's new` that will show this.
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-smart-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slack-ruby-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.17'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 0.17.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.17'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.17'
|
30
27
|
- - ">="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: 0.17.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.17'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: nice_http
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,8 +218,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
- !ruby/object:Gem::Version
|
219
219
|
version: '0'
|
220
220
|
requirements: []
|
221
|
-
rubygems_version: 3.
|
222
|
-
signing_key:
|
221
|
+
rubygems_version: 3.0.3
|
222
|
+
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Create a Slack bot that is smart and so easy to expand, create new bots on
|
225
225
|
demand, run ruby code on chat, create shortcuts...
|