slack-smart-bot 1.8.1 → 1.8.2

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: 19ab121009af799ef4d1338e6b274c3212aa3fb9eed9098ab32b4d445e620a14
4
- data.tar.gz: d9d16f6eb8de9fe372865e56f4f4e22ae2b10acdd55918f2d17a38a25f7111d7
3
+ metadata.gz: d35053e4911d77ae985b29fbd1564636eb0d078b38106601c2e126a401a03d5b
4
+ data.tar.gz: d5aadeedbdbe0c7a6528cbeac1f1bb0990d88cf93fdb9f0a085cf9be9ec17c2d
5
5
  SHA512:
6
- metadata.gz: d94f2a3b0f5f26c1ece8f9d9241b89e26714e6565104a1591c2f0ab0bac0bb9273d2e64e5a988fde4c18cdea0e89a8bcb98d5ee1f36ab22756b30d2b3cf61fff
7
- data.tar.gz: 2dadb23423038f6141e0f8fdf540b15ec5da160058eb7d286e7fee9b6b7672c58d348f33221848b472997a42818283ea76cb67748ad1d2437784ac0a61f41b3d
6
+ metadata.gz: 19ed3708f96befda1f755358eb847facba2afaa62f6a92e08e7f68143e51659ef75ab7ef925c0d07e9a2b02072dcd02ddeda89697855363e50e84dc3f1970af6
7
+ data.tar.gz: d40d1ac18d32074994c2c4ed3b835b74ada4e9ff46bbb5a7122df0f18f1b44eb777a6351ddaad3dd00b8bc129dbb62aee75572b9f3fe625e4fa972add2083107
data/README.md CHANGED
@@ -386,7 +386,7 @@ Example:
386
386
  To see available shortcuts: **_`see shortcuts`_** and to delete a particular shortcut: **_`delete shortcut NAME`_**
387
387
 
388
388
  ### 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`_**
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`_**. 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.
390
390
 
391
391
  If you want to hide the routine executions use `add silent routine`. It won't show the routine name when executing.
392
392
 
@@ -395,6 +395,7 @@ Examples:
395
395
  >**_`add routine clean_db at 17:05 !clean customers temp db`_**
396
396
  >**_`add silent routine clean_db at 17:05 !clean customers temp db`_**
397
397
  >**_`add routine clean_custdb on Mondays at 05:00 !clean customers db`_**
398
+ >**_`add routine clean_custdb on Tuesdays at 09:00 #SREChannel !clean customers db`_**
398
399
 
399
400
  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.
400
401
 
@@ -1,11 +1,14 @@
1
1
  class SlackSmartBot
2
2
  # helpadmin: ----------------------------------------------
3
3
  # helpadmin: `add routine NAME every NUMBER PERIOD COMMAND`
4
+ # helpadmin: `add routine NAME every NUMBER PERIOD #CHANNEL COMMAND`
4
5
  # helpadmin: `add routine NAME every NUMBER PERIOD`
5
6
  # helpadmin: `add silent routine NAME every NUMBER PERIOD`
6
7
  # helpadmin: `create routine NAME every NUMBER PERIOD`
7
8
  # helpadmin: `add routine NAME at TIME COMMAND`
9
+ # helpadmin: `add routine NAME at TIME #CHANNEL COMMAND`
8
10
  # helpadmin: `add routine NAME on DAYWEEK at TIME COMMAND`
11
+ # helpadmin: `add routine NAME on DAYWEEK at TIME #CHANNEL COMMAND`
9
12
  # helpadmin: `add routine NAME at TIME`
10
13
  # helpadmin: `add silent routine NAME at TIME`
11
14
  # helpadmin: `create routine NAME at TIME`
@@ -17,15 +20,17 @@ class SlackSmartBot
17
20
  # helpadmin: PERIOD: days, d, hours, h, minutes, mins, min, m, seconds, secs, sec, s
18
21
  # helpadmin: TIME: time at format HH:MM:SS
19
22
  # helpadmin: DAYWEEK: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. And their plurals.
23
+ # helpadmin: #CHANNEL: the destination channel where the results will be published. If not supplied then the bot channel by default or a DM if the command is run from a DM.
20
24
  # helpadmin: COMMAND: any valid smart bot command or rule
21
25
  # helpadmin: Examples:
22
26
  # helpadmin: _add routine example every 30s ruby puts 'a'_
23
27
  # helpadmin: _add routine example every 3 days ruby puts 'a'_
24
28
  # helpadmin: _add routine example at 17:05 ruby puts 'a'_
25
- # helpadmin: _create silent routine every 12 hours !Run customer tests_
29
+ # helpadmin: _create silent routine Example every 12 hours !Run customer tests_
26
30
  # helpadmin: _add routine example on Mondays at 05:00 !run customer tests_
31
+ # helpadmin: _add routine example on Tuesdays at 09:00 #SREChannel !run db cleanup_
27
32
  # helpadmin:
28
- def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent)
33
+ def add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
29
34
  save_stats(__method__)
30
35
  if files.nil? or files.size == 0 or (files.size > 0 and config.masters.include?(from))
31
36
  if config.admins.include?(from)
@@ -94,12 +99,12 @@ class SlackSmartBot
94
99
  http.get(files[0].url_private_download, save_data: file_path)
95
100
  system("chmod +x #{file_path}")
96
101
  end
97
-
102
+ channel = dest if channel.to_s == ''
98
103
  @routines[@channel_id] = {} unless @routines.key?(@channel_id)
99
104
  @routines[@channel_id][name] = { channel_name: config.channel, creator: from, creator_id: user.id, status: :on,
100
105
  every: every, every_in_seconds: every_in_seconds, at: at, dayweek: dayweek, file_path: file_path,
101
106
  command: command_to_run.to_s.strip, silent: silent,
102
- next_run: next_run.to_s, dest: dest, last_run: "", last_elapsed: "",
107
+ next_run: next_run.to_s, dest: channel, last_run: "", last_elapsed: "",
103
108
  running: false }
104
109
  update_routines
105
110
  respond "Added routine *`#{name}`* to the channel", dest
@@ -69,16 +69,17 @@ class SlackSmartBot
69
69
  when /^\s*kill\sbot\son\s<#C\w+\|(.+)>\s*$/i, /^kill\sbot\son\s(.+)\s*$/i
70
70
  channel = $1
71
71
  kill_bot_on_channel(dest, from, channel)
72
- 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,
73
- /^\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.+)?\s*$/i,
74
- /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s.+)?\s*$/i
72
+ 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<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i,
73
+ /^\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,
74
+ /^\s*(add|create)\s+(silent\s+)?routine\s+(\w+)\s+(at)\s+(\d+:\d+:?\d+?)\s*()(\s<#(C\w+)\|.+>\s*)?(\s.+)?\s*$/i
75
75
  silent = $2.to_s!=''
76
76
  name = $3.downcase
77
77
  type = $4
78
78
  number_time = $5
79
79
  period = $6
80
- command_to_run = $7
81
- add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent)
80
+ channel = $8
81
+ command_to_run = $9
82
+ add_routine(dest, from, user, name, type, number_time, period, command_to_run, files, silent, channel)
82
83
  when /^\s*(kill|delete|remove)\s+routine\s+(\w+)\s*$/i
83
84
  name = $2.downcase
84
85
  remove_routine(dest, from, name)
@@ -42,7 +42,9 @@ class SlackSmartBot
42
42
  f.puts "|#{data.channel}|#{data.user}|#{data.text}"
43
43
  }
44
44
  end
45
- if data.channel[0] == "D" or data.channel[0] == "C" or data.channel[0] == "G" #Direct message or Channel or Private Channel
45
+ if data.key?(:dest) and data.dest.to_s!='' # for run routines and publish on different channels
46
+ dest = data.dest
47
+ elsif data.channel[0] == "D" or data.channel[0] == "C" or data.channel[0] == "G" #Direct message or Channel or Private Channel
46
48
  dest = data.channel
47
49
  else # not treated
48
50
  dest = nil
@@ -65,15 +67,15 @@ class SlackSmartBot
65
67
  data.text = $4
66
68
  typem = :on_call
67
69
  end
68
- elsif dest == @master_bot_id
70
+ elsif data.channel == @master_bot_id
69
71
  if config.on_master_bot #only to be treated on master bot channel
70
72
  typem = :on_master
71
73
  end
72
- elsif @bots_created.key?(dest)
73
- if @channel_id == dest #only to be treated by the bot on the channel
74
+ elsif @bots_created.key?(data.channel)
75
+ if @channel_id == data.channel #only to be treated by the bot on the channel
74
76
  typem = :on_bot
75
77
  end
76
- elsif dest[0] == "D" #Direct message
78
+ elsif data.channel[0] == "D" #Direct message
77
79
  get_rules_imported()
78
80
  if @rules_imported.key?(data.user) && @rules_imported[data.user].key?(data.user) and
79
81
  @bots_created.key?(@rules_imported[data.user][data.user])
@@ -85,21 +87,21 @@ class SlackSmartBot
85
87
  #only to be treated by master bot
86
88
  typem = :on_dm
87
89
  end
88
- elsif dest[0] == "C" or dest[0] == "G"
90
+ elsif data.channel[0] == "C" or data.channel[0] == "G"
89
91
  #only to be treated on the channel of the bot. excluding running ruby
90
- if !config.on_master_bot and @bots_created.key?(@channel_id) and @bots_created[@channel_id][:extended].include?(@channels_name[dest]) and
92
+ if !config.on_master_bot and @bots_created.key?(@channel_id) and @bots_created[@channel_id][:extended].include?(@channels_name[data.channel]) and
91
93
  !data.text.match?(/^!?\s*(ruby|code)\s+/) and !data.text.match?(/^!?!?\s*(ruby|code)\s+/) and !data.text.match?(/^\^?\s*(ruby|code)\s+/)
92
94
  typem = :on_extended
93
95
  elsif config.on_master_bot and (data.text.match?(/^!?\s*(ruby|code)\s+/) or data.text.match?(/^!?!?\s*(ruby|code)\s+/) or data.text.match?(/^\^?\s*(ruby|code)\s+/) )
94
96
  #or in case of running ruby, the master bot
95
97
  @bots_created.each do |k, v|
96
- if v.key?(:extended) and v[:extended].include?(@channels_name[dest])
98
+ if v.key?(:extended) and v[:extended].include?(@channels_name[data.channel])
97
99
  typem = :on_extended
98
100
  break
99
101
  end
100
102
  end
101
103
  end
102
- if dest[0] == "G" and config.on_master_bot and typem != :on_extended #private group
104
+ if data.channel[0] == "G" and config.on_master_bot and typem != :on_extended #private group
103
105
  typem = :on_pg
104
106
  end
105
107
  end
@@ -127,7 +129,7 @@ class SlackSmartBot
127
129
  command = @questions[user_info.user.name]
128
130
  @questions[user_info.user.name] = data.text
129
131
  end
130
- elsif @repl_sessions.key?(user_info.user.name) and dest==@repl_sessions[user_info.user.name][:dest] and
132
+ elsif @repl_sessions.key?(user_info.user.name) and data.channel==@repl_sessions[user_info.user.name][:dest] and
131
133
  ((@repl_sessions[user_info.user.name][:on_thread] and data.thread_ts == @repl_sessions[user_info.user.name][:thread_ts]) or
132
134
  (!@repl_sessions[user_info.user.name][:on_thread] and data.thread_ts.to_s == '' ))
133
135
 
@@ -172,13 +174,13 @@ class SlackSmartBot
172
174
  if channel_found.nil?
173
175
  @logger.fatal "Not possible to find the channel #{channel_rules_name}"
174
176
  elsif channel_found.name == config.master_channel
175
- respond "You cannot use the rules from Master Channel on any other channel.", dest
177
+ respond "You cannot use the rules from Master Channel on any other channel.", data.channel
176
178
  elsif @status != :on
177
- respond "The bot in that channel is not :on", dest
179
+ respond "The bot in that channel is not :on", data.channel
178
180
  elsif data.user == channel_found.creator or members.include?(data.user)
179
181
  process_first(user_info.user, command, dest, channel_rules, typem, data.files, data.ts, data.thread_ts)
180
182
  else
181
- respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
183
+ respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", data.channel
182
184
  end
183
185
  elsif config.on_master_bot and typem == :on_extended and
184
186
  command.size > 0 and command[0] != "-"
@@ -197,7 +199,7 @@ class SlackSmartBot
197
199
  @logger.fatal stack
198
200
  end
199
201
  else
200
- if !config.on_master_bot and !dest.nil? and (dest == @master_bot_id or dest[0] == "D") and
202
+ if !config.on_master_bot and !dest.nil? and (data.channel == @master_bot_id or dest[0] == "D") and
201
203
  data.text.match?(/^\s*bot\s+status\s*$/i) and @admin_users_id.include?(data.user)
202
204
  respond "ping from #{config.channel}", dest
203
205
  elsif !config.on_master_bot and !dest.nil? and data.user == config[:nick_id] and dest == @master_bot_id
@@ -23,7 +23,11 @@ class SlackSmartBot
23
23
  stdout, stderr, status = Open3.capture3(process_to_run)
24
24
  if !@routines[@channel_id][name][:silent] or (@routines[@channel_id][name][:silent] and
25
25
  (!stderr.match?(/\A\s*\z/) or !stdout.match?(/\A\s*\z/)))
26
- respond "routine *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
26
+ if @routines[@channel_id][name][:dest]!=@channel_id
27
+ respond "routine from <##{@channel_id}> *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
28
+ else
29
+ respond "routine *`#{name}`*: #{@routines[@channel_id][name][:file_path]}", @routines[@channel_id][name][:dest]
30
+ end
27
31
  end
28
32
  if stderr == ""
29
33
  unless stdout.match?(/\A\s*\z/)
@@ -34,10 +38,15 @@ class SlackSmartBot
34
38
  end
35
39
  else #command
36
40
  if !@routines[@channel_id][name][:silent]
37
- respond "routine *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
41
+ if @routines[@channel_id][name][:dest]!=@channel_id
42
+ respond "routine from <##{@channel_id}> *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
43
+ else
44
+ respond "routine *`#{name}`*: #{@routines[@channel_id][name][:command]}", @routines[@channel_id][name][:dest]
45
+ end
38
46
  end
39
47
  started = Time.now
40
- data = { channel: @routines[@channel_id][name][:dest],
48
+ data = { channel: @channel_id,
49
+ dest: @routines[@channel_id][name][:dest],
41
50
  user: @routines[@channel_id][name][:creator_id],
42
51
  text: @routines[@channel_id][name][:command],
43
52
  files: nil }
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.8.1
4
+ version: 1.8.2
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-10-13 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-client