slack-smart-bot 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +89 -2
  3. data/lib/slack-smart-bot.rb +6 -1
  4. data/lib/slack/smart-bot/commands.rb +5 -0
  5. data/lib/slack/smart-bot/commands/general/bot_help.rb +44 -40
  6. data/lib/slack/smart-bot/commands/general/bot_status.rb +32 -28
  7. data/lib/slack/smart-bot/commands/general/bye_bot.rb +9 -1
  8. data/lib/slack/smart-bot/commands/general/hi_bot.rb +6 -1
  9. data/lib/slack/smart-bot/commands/general/use_rules.rb +33 -29
  10. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +40 -35
  11. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +1 -0
  12. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +32 -0
  13. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +30 -25
  14. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +43 -0
  15. data/lib/slack/smart-bot/commands/on_bot/repl.rb +202 -0
  16. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +33 -29
  17. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +73 -0
  18. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +24 -0
  19. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +23 -18
  20. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +32 -27
  21. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +79 -74
  22. data/lib/slack/smart-bot/listen.rb +2 -0
  23. data/lib/slack/smart-bot/process.rb +61 -9
  24. data/lib/slack/smart-bot/process_first.rb +17 -3
  25. data/lib/slack/smart-bot/treat_message.rb +24 -3
  26. data/lib/slack/smart-bot/utils.rb +3 -0
  27. data/lib/slack/smart-bot/utils/get_help.rb +1 -1
  28. data/lib/slack/smart-bot/utils/get_repls.rb +11 -0
  29. data/lib/slack/smart-bot/utils/update_repls.rb +8 -0
  30. metadata +28 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 031aceba04e6017cd314ba2be33d0e6cee0326e74f2301ef17da4ea5e932f315
4
- data.tar.gz: 3dc24d0bcf047d2cdab12f8d9dde3ee3f2b4817ce9f94264057fce54ea95f00a
3
+ metadata.gz: b243575f1dce8d61e387199037a62b2a1fb7eea2fb578981b1b82c18adb76393
4
+ data.tar.gz: 2890ce0402d1a23b2fb2f8710bd9bedc25412a9b4a9f1dc23f614f06b507f4f3
5
5
  SHA512:
6
- metadata.gz: 9f067e911e6748530944a0ec7534e54bd631c3549404cd3dd8b6d9ab69c004a8af7318916f68a0bc4e74289abc5f51d9b785147fdb275bc627e46abdd714f988
7
- data.tar.gz: 7cac3469e1320b94a4777c48069033b6b0e53d33f1c800b8fb0bed43b93ff4e82a03ce89ee59c158a94ad0964e76544f7a3d4c1af0091787ba6d0dfd241f7d2a
6
+ metadata.gz: 5d3da033e26a6660a976ae408e5620bd63a389feb8d458f68f4e52a4b6e1256be98cb80a386729e01baf269e85ecaa54e150cbb565df37246c6dbb5c8892da10
7
+ data.tar.gz: 4741d4dd84e4542ecf1682117ee6fb5cf2d6547070364e4cb4d882154008180191279b2691b02945bd8e5503fbc5973156a202bec45a0f8875c992dea6f3fa5c
data/README.md CHANGED
@@ -22,9 +22,11 @@ slack-smart-bot can create bots on demand, create shortcuts, run ruby code... ju
22
22
  * [Extending rules to other channels](#extending-rules-to-other-channels)
23
23
  * [Using rules from other channels](#using-rules-from-other-channels)
24
24
  * [Running Ruby code on a conversation](#running-ruby-code-on-a-conversation)
25
+ + [REPL](#repl)
25
26
  * [Sending notifications](#sending-notifications)
26
27
  * [Shortcuts](#shortcuts)
27
28
  * [Routines](#routines)
29
+ * [Limit who has access to a command](#limit-who-has-access-to-a-command)
28
30
  * [Tips](#tips)
29
31
  + [Send a file](#send-a-file)
30
32
  + [Download a file](#download-a-file)
@@ -164,7 +166,7 @@ You can access the bot directly on the MASTER CHANNEL, on a secondary channel wh
164
166
 
165
167
  On a Smart Bot channel you will be able to run some of the commands just by writing a command, for example: **_`bot help`_**
166
168
 
167
- Some commands will be only available when the Smart Bot is listening to you. For the Smart Bot to start listening to you just say: **_`hi bot`_**. When the Smart Bot is listening to you, you can skip a message to be treated by the bot by starting the message with '-', for example: **_`- this message won't be treated`_**. When you want the Smart Bot Stop listening to you: **_`bye bot`_**. If you are on a direct conversation with the Smart Bot then it will be on *listening* mode all the time.
169
+ Some commands will be only available when the Smart Bot is listening to you. For the Smart Bot to start listening to you just say: **_`hi bot`_**. When the Smart Bot is listening to you, you can skip a message to be treated by the bot by starting the message with '-', for example: **_`-this message won't be treated`_**. When you want the Smart Bot Stop listening to you: **_`bye bot`_**. The Smart Bot will automatically stop listening to you after 30 minutes of inactivity. If you are on a direct conversation with the Smart Bot then it will be on *listening* mode all the time.
168
170
 
169
171
  All the specific commands of the bot are specified on your rules file and can be added or changed accordingly. We usually call those commands: *rules*. Those rules are only available when the bot is listening to you.
170
172
 
@@ -285,6 +287,62 @@ Example:
285
287
 
286
288
  Also it is possible to attach a Ruby file and the Smart Bot will run and post the output. You need to select Ruby as file format.
287
289
 
290
+ #### REPL
291
+ Easily starts a REPL session so you will be able to create a script directly from the slack conversation. You will be able to share the REPL so they can run it or see the content.
292
+
293
+ It Will run all we write as a ruby command and will keep the session values until we finish the session sending `quit`, `exit` or `bye`
294
+
295
+ You can specify a SESSION_NAME that admits from a to Z, numbers, - and _. If no SESSION_NAME supplied it will be treated as a temporary REPL.
296
+ If 'private' specified in the command the REPL will be accessible only by you and it will be displayed only to you when `see repls`
297
+
298
+ To avoid a message to be treated when a session started, start the message with '-'.
299
+
300
+ Send puts, print, p or pp if you want to print out something when using `run repl` later.
301
+
302
+ If you declare on your rules file a method called `project_folder` returning the path for the project folder, the code will be executed from that folder.
303
+
304
+ By default it will be automatically loaded the gems: `string_pattern`, `nice_hash` and `nice_http`
305
+
306
+ To pre-execute some ruby when starting the session add the code to `.smart-bot-repl` file on the project root folder defined on `project_folder`
307
+
308
+ If you want to see the methods of a class or module you created use `ls TheModuleOrClass`
309
+
310
+ You can supply the Environmental Variables you need for the Session
311
+
312
+ Examples:
313
+ _repl CreateCustomer LOCATION=spain HOST='https://10.30.40.50:8887'_
314
+ _repl CreateCustomer: "It creates a random customer for testing" LOCATION=spain HOST='https://10.30.40.50:8887'_
315
+ _repl delete\_logs_
316
+ _private repl random-ssn_
317
+ _repl_
318
+
319
+
320
+ Running Example:
321
+ >**_Peter>_** `!repl Create10RandomUsers: "This is just an example"`
322
+ >**_Smart-Bot>_** `Session name: *Create10RandomUsers*`
323
+ >**_Peter>_** `http = NiceHttp.new("https://reqres.in/")`
324
+ >**_Smart-Bot>_** `#<NiceHttp:0x00007fc6e216e328 @host="reqres.in", @port=443...>`
325
+ >**_Peter>_** `request = { path: '/api/users' }`
326
+ >**_Smart-Bot>_** `{ :path => "/api/users" }`
327
+ >**_Peter>_** `request.data = { name: '1-10:L', job: 'leader|worker' }`
328
+ >**_Smart-Bot>_** `{ :name => "1-10:L", :job => "leader|worker" }`
329
+ >**_Peter>_** `request.data.generate`
330
+ >**_Smart-Bot>_** `{ :name => "kLam", :job => "leader" }`
331
+ >**_Peter>_** `10.times { http.post(request.generate) } `
332
+ >**_Smart-Bot>_** `10`
333
+ >**_Peter>_** `puts "10 Random Users Created"`
334
+ >**_Smart-Bot>_** `10 Random Users Created`
335
+ >**_Peter>_** `quit`
336
+ >**_Smart-Bot>_** `REPL session finished: Create10RandomUsers`
337
+
338
+
339
+ >**_Peter>_** `run repl Create10RandomUsers`
340
+ >**_Smart-Bot>_** `Running REPL Create10RandomUsers`
341
+ >**_Smart-Bot>_** `Create10RandomUsers: 10 Random Users Created`
342
+
343
+
344
+ Other REPL commands: `see repls`, `run repl SESSION_NAME ENV_VAR=value`, `get repl SESSION_NAME`, `delete repl SESSION_NAME`
345
+
288
346
  ### Sending notifications
289
347
  You can send notifications from MASTER CHANNEL by using **_`notify MESSAGE`_**. All Bot Channels will be notified.
290
348
 
@@ -340,6 +398,35 @@ Other routine commands:
340
398
  * **_`run routine NAME`_**
341
399
  * **_`see routines`_**
342
400
 
401
+ ### Limit who has access to a command
402
+
403
+ If you want to define who has access to certain commands you can specify it on the settings when starting the Smart Bot:
404
+
405
+ ```ruby
406
+ settings = {
407
+ # the channel that will act like the master channel, main channel
408
+ master_channel: 'my_master_channel',
409
+ masters: ["mario"], #names of the master users
410
+ token: 'xxxxxxxxxxxxxxxxxx', # the API Slack token
411
+ allow_access: {
412
+ repl: [ 'marioruiz', 'peterlondon', 'UMYAAS8E7F'],
413
+ ruby_code: [ 'marioruiz', 'UMYAAS8E7F', 'samcooke']
414
+ }
415
+ }
416
+ ```
417
+ You can use the user name or the user id.
418
+
419
+ If you want to change who has access to a certain command without restarting the Smart Bot you can do it on the rules file:
420
+
421
+ ```ruby
422
+ config.allow_access.repl = ['marioruiz', 'samcooke']
423
+ ```
424
+
425
+ These are the commands that are possible to be limited:
426
+
427
+ `bot_help, bot_rules, bot_status, use_rules, add_shortcut, delete_shortcut, repl, run_repl, get_repl, delete_repl, see_repls, ruby_code, see_shortcuts, create_bot`
428
+
429
+
343
430
  ### Tips
344
431
 
345
432
  #### Send a file
@@ -358,7 +445,7 @@ When uploading a file the message added to 'Add a message about the file' will b
358
445
  when /^do something with my file/i
359
446
  if !files.nil? and files.size == 1 and files[0].filetype == 'yaml'
360
447
  require 'nice_http'
361
- http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config[:token]}" })
448
+ http = NiceHttp.new(host: "https://files.slack.com", headers: { "Authorization" => "Bearer #{config.token}" })
362
449
  res = http.get(files[0].url_private_download, save_data: './tmp/')
363
450
  # if you want to directly access to the content use: `res.data`
364
451
  end
@@ -46,6 +46,7 @@ class SlackSmartBot
46
46
  config[:testing] = false unless config.key?(:testing)
47
47
  config[:simulate] = false unless config.key?(:simulate)
48
48
  config[:stats] = false unless config.key?(:stats)
49
+ config[:allow_access] = Hash.new unless config.key?(:allow_access)
49
50
 
50
51
  if config.path.to_s!='' and config.file.to_s==''
51
52
  config.file = File.basename($0)
@@ -143,13 +144,14 @@ class SlackSmartBot
143
144
  end
144
145
  end
145
146
 
146
- @listening = Array.new
147
+ @listening = Hash.new()
147
148
 
148
149
  @bots_created = Hash.new()
149
150
  @shortcuts = Hash.new()
150
151
  @shortcuts[:all] = Hash.new()
151
152
  @rules_imported = Hash.new()
152
153
  @routines = Hash.new()
154
+ @repls = Hash.new()
153
155
 
154
156
  if File.exist?("#{config.path}/shortcuts/#{config.shortcuts_file}")
155
157
  file_sc = IO.readlines("#{config.path}/shortcuts/#{config.shortcuts_file}").join
@@ -159,6 +161,7 @@ class SlackSmartBot
159
161
  end
160
162
 
161
163
  get_routines()
164
+ get_repls()
162
165
 
163
166
  if config.on_master_bot and File.exist?(config.file_path.gsub(".rb", "_bots.rb"))
164
167
  get_bots_created()
@@ -221,6 +224,7 @@ class SlackSmartBot
221
224
 
222
225
  @status = config.status_init
223
226
  @questions = Hash.new()
227
+ @repl_sessions = Hash.new()
224
228
  @channels_id = Hash.new()
225
229
  @channels_name = Hash.new()
226
230
  get_channels_name_and_id()
@@ -228,6 +232,7 @@ class SlackSmartBot
228
232
  @master_bot_id = @channels_id[config.master_channel].dup
229
233
 
230
234
  get_routines()
235
+ get_repls()
231
236
  if @routines.key?(@channel_id)
232
237
  @routines[@channel_id].each do |k, v|
233
238
  @routines[@channel_id][k][:running] = false
@@ -2,6 +2,11 @@ require_relative "commands/general/hi_bot"
2
2
  require_relative "commands/general/bye_bot"
3
3
  require_relative "commands/general/bot_help"
4
4
  require_relative "commands/on_bot/ruby_code"
5
+ require_relative "commands/on_bot/repl"
6
+ require_relative "commands/on_bot/get_repl"
7
+ require_relative "commands/on_bot/run_repl"
8
+ require_relative "commands/on_bot/delete_repl"
9
+ require_relative "commands/on_bot/see_repls"
5
10
  require_relative "commands/general/use_rules"
6
11
  require_relative "commands/general/stop_using_rules"
7
12
  require_relative "commands/on_master/admin_master/exit_bot"
@@ -12,59 +12,63 @@ class SlackSmartBot
12
12
  # help:
13
13
  def bot_help(user, from, dest, dchannel, specific, help_command, rules_file)
14
14
  save_stats(__method__)
15
- help_found = false
15
+ if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id)
16
+ respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
17
+ else
18
+ help_found = false
16
19
 
17
- message = ""
20
+ message = ""
18
21
 
19
- help_message = get_help(rules_file, dest, from, specific)
22
+ help_message = get_help(rules_file, dest, from, specific)
20
23
 
21
- if help_command.to_s != ""
22
- help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).each do |h|
23
- if h.match?(/[`_]#{help_command}/i)
24
- respond h, dest
25
- help_found = true
24
+ if help_command.to_s != ""
25
+ help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).each do |h|
26
+ if h.match?(/[`_]#{help_command}/i)
27
+ respond h, dest
28
+ help_found = true
29
+ end
26
30
  end
27
- end
28
- else
29
- if Thread.current[:using_channel]!=''
30
- message = "*You are using rules from another channel: <##{Thread.current[:using_channel]}>. These are the specific commands for that channel:*"
31
- end
32
- respond message, dest
33
- end
34
-
35
- if (help_command.to_s == "")
36
- help_message.split(/^\s*=========*$/).each do |h|
37
- respond("#{"=" * 35}\n#{h}", dest) unless h.match?(/\A\s*\z/)
38
- end
39
- else
40
- unless help_found
41
- if specific
42
- respond("I didn't find any rule starting by `#{help_command}`", dest)
43
- else
44
- respond("I didn't find any command starting by `#{help_command}`", dest)
31
+ else
32
+ if Thread.current[:using_channel]!=''
33
+ message = "*You are using rules from another channel: <##{Thread.current[:using_channel]}>. These are the specific commands for that channel:*"
45
34
  end
35
+ respond message, dest
46
36
  end
47
- end
48
37
 
49
- if specific
50
- unless rules_file.empty?
51
- begin
52
- eval(File.new(config.path + rules_file).read) if File.exist?(config.path + rules_file)
38
+ if (help_command.to_s == "")
39
+ help_message.split(/^\s*=========*$/).each do |h|
40
+ respond("#{"=" * 35}\n#{h}", dest) unless h.match?(/\A\s*\z/)
53
41
  end
54
- end
55
- if defined?(git_project) && (git_project.to_s != "") && (help_command.to_s == "")
56
- respond "Git project: #{git_project}", dest
57
42
  else
58
- def git_project
59
- ""
43
+ unless help_found
44
+ if specific
45
+ respond("I didn't find any rule starting by `#{help_command}`", dest)
46
+ else
47
+ respond("I didn't find any command starting by `#{help_command}`", dest)
48
+ end
60
49
  end
50
+ end
51
+
52
+ if specific
53
+ unless rules_file.empty?
54
+ begin
55
+ eval(File.new(config.path + rules_file).read) if File.exist?(config.path + rules_file)
56
+ end
57
+ end
58
+ if defined?(git_project) && (git_project.to_s != "") && (help_command.to_s == "")
59
+ respond "Git project: #{git_project}", dest
60
+ else
61
+ def git_project
62
+ ""
63
+ end
61
64
 
62
- def project_folder
63
- ""
65
+ def project_folder
66
+ ""
67
+ end
64
68
  end
69
+ elsif help_command.to_s == ""
70
+ respond "Slack Smart Bot Github project: https://github.com/MarioRuiz/slack-smart-bot", dest
65
71
  end
66
- elsif help_command.to_s == ""
67
- respond "Slack Smart Bot Github project: https://github.com/MarioRuiz/slack-smart-bot", dest
68
72
  end
69
73
  end
70
74
  end
@@ -4,38 +4,42 @@ class SlackSmartBot
4
4
  # helpadmin: Displays the status of the bot
5
5
  # helpadmin: If on master channel and admin user also it will display info about bots created
6
6
  # helpadmin:
7
- def bot_status(dest, from)
7
+ def bot_status(dest, user)
8
8
  save_stats(__method__)
9
9
  get_bots_created()
10
- gems_remote = `gem list slack-smart-bot --remote`
11
- version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
12
- version_message = ""
13
- if version_remote != VERSION
14
- version_message = " There is a new available version: #{version_remote}."
15
- end
16
- require "socket"
17
- ip_address = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
18
- respond "*#{Socket.gethostname} (#{ip_address})*\n\tStatus: #{@status}.\n\tVersion: #{VERSION}.#{version_message}\n\tRules file: #{File.basename config.rules_file}\n\tExtended: #{@bots_created[@channel_id][:extended] unless config.on_master_bot}\n\tAdmins: #{config.admins}\n\tBot time: #{Time.now}", dest
19
- if @status == :on
20
- respond "I'm listening to [#{@listening.join(", ")}]", dest
21
- if config.on_master_bot and config.admins.include?(from)
22
- sleep 5
23
- @bots_created.each do |k, v|
24
- msg = []
25
- msg << "`#{v[:channel_name]}` (#{k}):"
26
- msg << "\tcreator: #{v[:creator_name]}"
27
- msg << "\tadmins: #{v[:admins]}"
28
- msg << "\tstatus: #{v[:status]} #{" *(not responded)*" unless @pings.include?(v[:channel_name])}"
29
- msg << "\tcreated: #{v[:created]}"
30
- msg << "\trules: #{v[:rules_file]}"
31
- msg << "\textended: #{v[:extended]}"
32
- msg << "\tcloud: #{v[:cloud]}"
33
- if config.on_master_bot and v.key?(:cloud) and v[:cloud]
34
- msg << "\trunner: `ruby #{config.file} \"#{v[:channel_name]}\" \"#{v[:admins]}\" \"#{v[:rules_file]}\" on&`"
10
+ if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id)
11
+ respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
12
+ else
13
+ gems_remote = `gem list slack-smart-bot --remote`
14
+ version_remote = gems_remote.to_s().scan(/slack-smart-bot \((\d+\.\d+\.\d+)/).join
15
+ version_message = ""
16
+ if version_remote != VERSION
17
+ version_message = " There is a new available version: #{version_remote}."
18
+ end
19
+ require "socket"
20
+ ip_address = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
21
+ respond "*#{Socket.gethostname} (#{ip_address})*\n\tStatus: #{@status}.\n\tVersion: #{VERSION}.#{version_message}\n\tRules file: #{File.basename config.rules_file}\n\tExtended: #{@bots_created[@channel_id][:extended] unless config.on_master_bot}\n\tAdmins: #{config.admins}\n\tBot time: #{Time.now}", dest
22
+ if @status == :on
23
+ respond "I'm listening to [#{@listening.keys.join(", ")}]", dest
24
+ if config.on_master_bot and config.admins.include?(user.name)
25
+ sleep 5
26
+ @bots_created.each do |k, v|
27
+ msg = []
28
+ msg << "`#{v[:channel_name]}` (#{k}):"
29
+ msg << "\tcreator: #{v[:creator_name]}"
30
+ msg << "\tadmins: #{v[:admins]}"
31
+ msg << "\tstatus: #{v[:status]} #{" *(not responded)*" unless @pings.include?(v[:channel_name])}"
32
+ msg << "\tcreated: #{v[:created]}"
33
+ msg << "\trules: #{v[:rules_file]}"
34
+ msg << "\textended: #{v[:extended]}"
35
+ msg << "\tcloud: #{v[:cloud]}"
36
+ if config.on_master_bot and v.key?(:cloud) and v[:cloud]
37
+ msg << "\trunner: `ruby #{config.file} \"#{v[:channel_name]}\" \"#{v[:admins]}\" \"#{v[:rules_file]}\" on&`"
38
+ end
39
+ respond msg.join("\n"), dest
35
40
  end
36
- respond msg.join("\n"), dest
41
+ @pings = []
37
42
  end
38
- @pings = []
39
43
  end
40
44
  end
41
45
  end
@@ -12,7 +12,15 @@ class SlackSmartBot
12
12
  save_stats(__method__)
13
13
  bye = ["Bye", "Bæ", "Good Bye", "Adiós", "Ciao", "Bless", "Bless bless", "Adeu"].sample
14
14
  respond "#{bye} #{display_name}", dest
15
- @listening.delete(from)
15
+
16
+ if @listening.key?(from)
17
+ if Thread.current[:on_thread]
18
+ @listening[from].delete(Thread.current[:thread_ts])
19
+ else
20
+ @listening[from].delete(dest)
21
+ end
22
+ @listening.delete(from) if @listening[from].empty?
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -17,7 +17,12 @@ class SlackSmartBot
17
17
  if Thread.current[:using_channel]!=''
18
18
  respond "You are using specific rules for channel: <##{Thread.current[:using_channel]}>", dest
19
19
  end
20
- @listening << from unless @listening.include?(from)
20
+ @listening[from] = {} unless @listening.key?(from)
21
+ if Thread.current[:on_thread]
22
+ @listening[from][Thread.current[:thread_ts]] = Time.now
23
+ else
24
+ @listening[from][dest] = Time.now
25
+ end
21
26
  end
22
27
  end
23
28
  end
@@ -10,39 +10,43 @@ class SlackSmartBot
10
10
  def use_rules(dest, channel, user, dchannel)
11
11
  save_stats(__method__)
12
12
  get_bots_created()
13
- #todo: add pagination for case more than 1000 channels on the workspace
14
- channels = client.web_client.conversations_list(
15
- types: "private_channel,public_channel",
16
- limit: "1000",
17
- exclude_archived: "true",
18
- ).channels
13
+ if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id)
14
+ respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
15
+ else
16
+ #todo: add pagination for case more than 1000 channels on the workspace
17
+ channels = client.web_client.conversations_list(
18
+ types: "private_channel,public_channel",
19
+ limit: "1000",
20
+ exclude_archived: "true",
21
+ ).channels
19
22
 
20
- channel_found = channels.detect { |c| c.name == channel }
21
- members = client.web_client.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
23
+ channel_found = channels.detect { |c| c.name == channel }
24
+ members = client.web_client.conversations_members(channel: @channels_id[channel]).members unless channel_found.nil?
22
25
 
23
- if channel_found.nil?
24
- respond "The channel you are trying to use doesn't exist", dest
25
- elsif channel_found.name == config.master_channel
26
- respond "You cannot use the rules from Master Channel on any other channel.", dest
27
- elsif !@bots_created.key?(@channels_id[channel])
28
- respond "There is no bot running on that channel.", dest
29
- elsif @bots_created.key?(@channels_id[channel]) and @bots_created[@channels_id[channel]][:status] != :on
30
- respond "The bot in that channel is not :on", dest
31
- else
32
- if user.id == channel_found.creator or members.include?(user.id)
33
- @rules_imported[user.id] = {} unless @rules_imported.key?(user.id)
34
- if dest[0] == "C" or dest[0] == "G" #todo: take in consideration bots that are not master
35
- @rules_imported[user.id][dchannel] = channel_found.id
26
+ if channel_found.nil?
27
+ respond "The channel you are trying to use doesn't exist", dest
28
+ elsif channel_found.name == config.master_channel
29
+ respond "You cannot use the rules from Master Channel on any other channel.", dest
30
+ elsif !@bots_created.key?(@channels_id[channel])
31
+ respond "There is no bot running on that channel.", dest
32
+ elsif @bots_created.key?(@channels_id[channel]) and @bots_created[@channels_id[channel]][:status] != :on
33
+ respond "The bot in that channel is not :on", dest
34
+ else
35
+ if user.id == channel_found.creator or members.include?(user.id)
36
+ @rules_imported[user.id] = {} unless @rules_imported.key?(user.id)
37
+ if dest[0] == "C" or dest[0] == "G" #todo: take in consideration bots that are not master
38
+ @rules_imported[user.id][dchannel] = channel_found.id
39
+ else
40
+ @rules_imported[user.id][user.id] = channel_found.id
41
+ end
42
+ update_rules_imported()
43
+ respond "I'm using now the rules from <##{channel_found.id}>", dest
44
+
45
+ def git_project() "" end
46
+ def project_folder() "" end
36
47
  else
37
- @rules_imported[user.id][user.id] = channel_found.id
48
+ respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
38
49
  end
39
- update_rules_imported()
40
- respond "I'm using now the rules from <##{channel_found.id}>", dest
41
-
42
- def git_project() "" end
43
- def project_folder() "" end
44
- else
45
- respond "You need to join the channel <##{channel_found.id}> to be able to use the rules.", dest
46
50
  end
47
51
  end
48
52
  end