slack-smart-bot 1.9.2 → 1.10.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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +109 -11
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -49
  4. data/lib/slack/smart-bot/comm/dont_understand.rb +1 -1
  5. data/lib/slack/smart-bot/comm/event_hello.rb +7 -3
  6. data/lib/slack/smart-bot/comm/get_channel_members.rb +9 -4
  7. data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
  8. data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
  9. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  10. data/lib/slack/smart-bot/comm/react.rb +19 -2
  11. data/lib/slack/smart-bot/comm/respond.rb +217 -72
  12. data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
  13. data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
  14. data/lib/slack/smart-bot/comm/send_file.rb +38 -34
  15. data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
  16. data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
  17. data/lib/slack/smart-bot/comm/unreact.rb +22 -18
  18. data/lib/slack/smart-bot/comm.rb +2 -0
  19. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  20. data/lib/slack/smart-bot/commands/general/bot_help.rb +59 -32
  21. data/lib/slack/smart-bot/commands/general/bot_stats.rb +10 -9
  22. data/lib/slack/smart-bot/commands/general/bot_status.rb +2 -4
  23. data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
  24. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
  25. data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
  26. data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
  27. data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
  28. data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
  29. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
  30. data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
  31. data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
  32. data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
  33. data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
  34. data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
  35. data/lib/slack/smart-bot/commands/general/use_rules.rb +7 -7
  36. data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
  37. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -5
  38. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +32 -11
  39. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -0
  40. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -2
  41. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
  42. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
  43. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
  44. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
  45. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +4 -2
  46. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -2
  47. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
  48. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
  49. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
  50. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
  51. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -4
  52. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +2 -4
  53. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -4
  54. data/lib/slack/smart-bot/commands/on_bot/repl.rb +5 -7
  55. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +2 -4
  56. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +4 -5
  57. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +3 -5
  58. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +2 -4
  59. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
  60. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
  61. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +2 -0
  62. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +1 -0
  63. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
  64. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
  65. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +8 -0
  66. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +27 -14
  67. data/lib/slack/smart-bot/commands.rb +16 -0
  68. data/lib/slack/smart-bot/listen.rb +1 -3
  69. data/lib/slack/smart-bot/process.rb +212 -74
  70. data/lib/slack/smart-bot/process_first.rb +118 -37
  71. data/lib/slack/smart-bot/treat_message.rb +313 -248
  72. data/lib/slack/smart-bot/utils/build_help.rb +3 -3
  73. data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
  74. data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
  75. data/lib/slack/smart-bot/utils/get_help.rb +58 -68
  76. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  77. data/lib/slack/smart-bot/utils/has_access.rb +12 -0
  78. data/lib/slack/smart-bot/utils/save_stats.rb +2 -0
  79. data/lib/slack/smart-bot/utils/save_status.rb +52 -0
  80. data/lib/slack/smart-bot/utils.rb +3 -0
  81. data/lib/slack-smart-bot.rb +45 -4
  82. data/lib/slack-smart-bot_general_commands.rb +46 -0
  83. data/lib/slack-smart-bot_general_rules.rb +5 -2
  84. data/lib/slack-smart-bot_rules.rb +43 -17
  85. data/whats_new.txt +32 -20
  86. metadata +24 -2
@@ -5,14 +5,12 @@ class SlackSmartBot
5
5
  # help: runs the code supplied and returns the output. Also you can send a Ruby file instead. Examples:
6
6
  # help: _code puts (34344/99)*(34+14)_
7
7
  # help: _ruby require 'json'; res=[]; 20.times {res<<rand(100)}; my_json={result: res}; puts my_json.to_json_
8
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#running-ruby-code-on-a-conversation|more info>
8
9
  # help:
9
10
 
10
11
  def ruby_code(dest, user, code, rules_file)
11
12
  save_stats(__method__)
12
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
13
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_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
13
+ if has_access?(__method__, user)
16
14
  unless code.match?(/System/i) or code.match?(/Kernel/i) or code.include?("File.") or
17
15
  code.include?("`") or code.include?("exec") or code.include?("spawn") or code.include?("IO.") or
18
16
  code.match?(/open3/i) or code.match?(/bundle/i) or code.match?(/gemfile/i) or code.include?("%x") or
@@ -9,14 +9,12 @@ class SlackSmartBot
9
9
  # help: It will return only the values that were print out on the repl with puts, print, p or pp
10
10
  # help: Example:
11
11
  # help: _run repl CreateCustomer LOCATION=spain HOST='https://10.30.40.50:8887'_
12
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
12
13
  # help:
13
14
  def run_repl(dest, user, session_name, env_vars, rules_file)
14
15
  #todo: add tests
15
16
  from = user.name
16
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
17
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
18
- respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
19
- else
17
+ if has_access?(__method__, user)
20
18
  save_stats(__method__)
21
19
  Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
22
20
  Dir.mkdir("#{config.path}/repl/#{@channel_id}") unless Dir.exist?("#{config.path}/repl/#{@channel_id}")
@@ -43,7 +41,8 @@ class SlackSmartBot
43
41
  eval(File.new(config.path+rules_file).read) if File.exist?(config.path+rules_file)
44
42
  end
45
43
  end
46
- if File.exist?("#{project_folder}/.smart-bot-repl") and @repls[session_name][:type] != :private_clean and @repls[session_name][:type] != :public_clean
44
+ if File.exist?("#{project_folder}/.smart-bot-repl") and
45
+ ((@repls.key?(session_name) and @repls[session_name][:type] != :private_clean and @repls[session_name][:type] != :public_clean) or !@repls.key?(session_name))
47
46
  content += File.read("#{project_folder}/.smart-bot-repl")
48
47
  content += "\n"
49
48
  end
@@ -2,16 +2,14 @@ class SlackSmartBot
2
2
  # help: ----------------------------------------------
3
3
  # help: `see repls`
4
4
  # help: `see irbs`
5
- # help: It will display the repls
5
+ # help: It will display the repls
6
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
6
7
  # help:
7
8
  def see_repls(dest, user, typem)
8
9
  #todo: add tests
9
10
  save_stats(__method__)
10
11
  from = user.name
11
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
12
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
13
- respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
14
- else
12
+ if has_access?(__method__, user)
15
13
  message = ""
16
14
  @repls.sort.to_h.each do |session_name, repl|
17
15
  if (repl.creator_name == user.name or repl.type == :public or repl.type == :public_clean) or (config.admins.include?(user.name) and typem == :on_dm)
@@ -3,14 +3,12 @@ class SlackSmartBot
3
3
  # help: `see shortcuts`
4
4
  # help: `see sc`
5
5
  # help: It will display the shortcuts stored for the user and for :all
6
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#shortcuts|more info>
6
7
  # help:
7
8
  def see_shortcuts(dest, user, typem)
8
9
  save_stats(__method__)
9
10
  from = user.name
10
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
11
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
12
- respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
13
- else
11
+ if has_access?(__method__, user)
14
12
  unless typem == :on_extended
15
13
  msg = ""
16
14
  if @shortcuts[:all].keys.size > 0 or @shortcuts_global[:all].keys.size > 0
@@ -2,12 +2,9 @@ class SlackSmartBot
2
2
  def bot_rules(dest, help_command, typem, rules_file, user)
3
3
  save_stats(__method__)
4
4
  from = user.name
5
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
6
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
7
- respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
8
- else
5
+ if has_access?(__method__, user)
9
6
  if typem == :on_extended or typem == :on_call #for the other cases above.
10
-
7
+ output = []
11
8
  if help_command.to_s != ''
12
9
  help_command = '' if help_command.to_s.match?(/^\s*expanded\s*$/i) or help_command.to_s.match?(/^\s*extended\s*$/i)
13
10
  expanded = true
@@ -17,22 +14,47 @@ class SlackSmartBot
17
14
 
18
15
  help_filtered = get_help(rules_file, dest, from, true, expanded)
19
16
 
17
+ commands = []
18
+ commands_search = []
20
19
  if help_command.to_s != ""
21
20
  help_found = false
22
21
  help_filtered.split(/^\s*-------*$/).each do |h|
23
22
  if h.match?(/[`_]#{help_command}/i)
24
- respond "*#{config.channel}*:#{h}", dest
23
+ output << "*#{config.channel}*:#{h}"
25
24
  help_found = true
25
+ commands << h
26
+ elsif !h.match?(/\A\s*\*/) and !h.match?(/\A\s*=+/) #to avoid general messages for bot help *General rules...*
27
+ all_found = true
28
+ help_command.to_s.split(' ') do |hc|
29
+ unless hc.match?(/^\s*\z/)
30
+ if !h.match?(/#{hc}/i)
31
+ all_found = false
32
+ end
33
+ end
34
+ end
35
+ commands_search << h if all_found
36
+ end
37
+ end
38
+ if commands.size < 10 and help_command.to_s!='' and commands_search.size > 0
39
+ commands_search.shuffle!
40
+ (10-commands.size).times do |n|
41
+ unless commands_search[n].nil?
42
+ output << commands_search[n]
43
+ help_found = true
44
+ end
26
45
  end
27
46
  end
28
- respond("*#{config.channel}*: I didn't find any command starting by `#{help_command}`", dest) unless help_found
47
+ unless help_found
48
+ output << "*#{config.channel}*: I didn't find any command with `#{help_command}`"
49
+ end
50
+
29
51
  else
30
52
  message = "-\n\n\n===================================\n*Rules from channel #{config.channel}*\n"
31
53
  if typem == :on_extended
32
54
  message += "To run the commands on this extended channel, add `!`, `!!` or `^` before the command.\n"
33
55
  end
34
56
  message += help_filtered
35
- respond message, dest
57
+ output << message
36
58
  end
37
59
 
38
60
  unless rules_file.empty?
@@ -41,16 +63,27 @@ class SlackSmartBot
41
63
  end
42
64
  end
43
65
  if defined?(git_project) and git_project.to_s != "" and help_command.to_s == ""
44
- respond "Git project: #{git_project}", dest
66
+ output << "Git project: #{git_project}"
45
67
  else
46
68
  def git_project() "" end
47
69
  def project_folder() "" end
48
70
  end
49
71
  unless expanded
50
- message_not_expanded = "*If you want to see the expanded version of `bot rules`, please call `bot rules expanded`*\n"
51
- message_not_expanded += "*Also to get specific expanded help for a specific command or rule call `bot rules COMMAND`*\n"
52
- respond message_not_expanded
72
+ message_not_expanded = "If you want to see the *expanded* version of *`bot rules`*, please call *`bot rules expanded`*\n"
73
+ message_not_expanded += "Also to get specific *expanded* help for a specific command or rule call *`bot rules COMMAND`*\n"
74
+ output << message_not_expanded
75
+ end
76
+ if output.join("\n").lines.count > 50 and dest[0]!='D'
77
+ dest = :on_thread
78
+ output.unshift('Since there are many lines returned the results are returned on a thread by default.')
79
+ end
80
+ output.each do |h|
81
+ msg = h.gsub(/^\s*command_id:\s+:\w+\s*$/,'')
82
+ unless msg.match?(/\A\s*\z/)
83
+ respond msg, dest, unfurl_links: false, unfurl_media: false
84
+ end
53
85
  end
86
+
54
87
  end
55
88
  end
56
89
  end
@@ -3,6 +3,7 @@ class SlackSmartBot
3
3
  # helpmaster: `kill bot on CHANNEL_NAME`
4
4
  # helpmaster: kills the bot on the specified channel
5
5
  # helpmaster: Only works if you are on Master channel and you created that bot or you are an admin user
6
+ # helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
6
7
  # helpmaster:
7
8
  def kill_bot_on_channel(dest, from, channel)
8
9
  save_stats(__method__)
@@ -18,7 +19,8 @@ class SlackSmartBot
18
19
  if channel_id.nil?
19
20
  respond "There is no channel with that name: #{channel}, please be sure is written exactly the same", dest
20
21
  elsif @bots_created.keys.include?(channel_id)
21
- if @bots_created[channel_id][:admins].split(",").include?(from)
22
+ @bots_created[channel_id] ||= {}
23
+ if @bots_created[channel_id][:admins].to_s.split(",").include?(from)
22
24
  if @bots_created[channel_id][:thread].kind_of?(Thread) and @bots_created[channel_id][:thread].alive?
23
25
  @bots_created[channel_id][:thread].kill
24
26
  end
@@ -26,6 +28,7 @@ class SlackSmartBot
26
28
  update_bots_file()
27
29
  respond "Bot on channel: #{channel}, has been killed and deleted.", dest
28
30
  send_msg_channel(channel, "Bot has been killed by #{from}")
31
+ save_status :off, :killed, "The admin killed SmartBot on *<##{channel_id}|#{@channels_name[channel_id]}>*"
29
32
  else
30
33
  respond "You need to be the creator or an admin of that bot channel", dest
31
34
  end
@@ -6,6 +6,7 @@ class SlackSmartBot
6
6
  # helpadmin: `close bot`
7
7
  # helpadmin: The bot stops running and also stops all the bots created from this master channel
8
8
  # helpadmin: You can use this command only if you are an admin user and you are on the master channel
9
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
9
10
  # helpadmin:
10
11
  def exit_bot(command, from, dest, display_name)
11
12
  save_stats(__method__)
@@ -21,6 +22,7 @@ class SlackSmartBot
21
22
  @bots_created.each { |key, value|
22
23
  value[:thread] = ""
23
24
  send_msg_channel(key, "Bot has been closed by #{from}")
25
+ save_status :off, :exited, "The admin closed SmartBot on *<##{key}|#{value.channel_name}>*"
24
26
  sleep 0.5
25
27
  }
26
28
  update_bots_file()
@@ -7,6 +7,7 @@ class SlackSmartBot
7
7
  # helpmaster: It will send a notification message to all channels the bot joined and private conversations with the bot
8
8
  # helpmaster: It will send a notification message to the specified channel and to its extended channels
9
9
  # helpmaster: Only works if you are on Master channel and you are a master admin user
10
+ # helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#sending-notifications|more info>
10
11
  # helpmaster:
11
12
  def notify_message(dest, from, where, message)
12
13
  save_stats(__method__)
@@ -0,0 +1,32 @@
1
+ class SlackSmartBot
2
+ # helpmaster: ----------------------------------------------
3
+ # helpmaster: `publish announcements`
4
+ # helpmaster: It will publish on all channels the announcements added by using 'add announcement' command.
5
+ # helpmaster: Only works if you are on Master channel and you are a master admin user
6
+ # helpmaster: The messages stored on a DM won't be published.
7
+ # helpmaster: This is very convenient to be called from a *Routine* for example every weekday at 09:00.
8
+ # helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
9
+ # helpmaster:
10
+ def publish_announcements(user)
11
+ save_stats(__method__)
12
+ if config.on_master_bot
13
+ if config.admins.include?(user.name) #admin user
14
+ channels = Dir.entries("#{config.path}/announcements/")
15
+ channels.select! {|i| i[/\.csv$/]}
16
+ channels.each do |channel|
17
+ channel.gsub!('.csv','')
18
+ unless channel[0]== 'D'
19
+ see_announcements(user, '', channel, true, true)
20
+ sleep 0.5 # to avoid reach ratelimit
21
+ end
22
+ end
23
+ react :heavy_check_mark
24
+
25
+ else
26
+ respond 'Only master admins on master channel can use this command.'
27
+ end
28
+ else
29
+ respond 'Only master admins on master channel can use this command.'
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ class SlackSmartBot
2
+ # helpmaster: ----------------------------------------------
3
+ # helpmaster: `set general message MESSAGE`
4
+ # helpmaster: `set general message off`
5
+ # helpmaster: The SmartBot will display the specified message after treating every command
6
+ # helpmaster: Only works if you are on Master channel and you are a master admin user
7
+ # helpmaster: You can add interpolation to the message you are adding
8
+ # helpmaster: Examples:
9
+ # helpmaster: _set general message We will be on maintenance at 12:00_
10
+ # helpmaster: _set general message We will be on maintenance in #{((Time.new(2021,6,18,13,30,0)-Time.now)/60).to_i} minutes_
11
+ # helpmaster: _set general message `We will be on *maintenance* at *12:00*`_
12
+ # helpmaster: _set general message `:information_source: Pay attention: We will be on *maintenance* in *#{((Time.new(2021,6,18,13,30,0)-Time.now)/60).to_i} minutes*`_
13
+ # helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
14
+ # helpmaster:
15
+ def set_general_message(from, status, message)
16
+ save_stats(__method__)
17
+ if config.on_master_bot
18
+ if config.admins.include?(from) #admin user
19
+ if status == 'on'
20
+ config.general_message = message
21
+ respond "General message has been set."
22
+ else
23
+ config.general_message = ''
24
+ respond "General message won't be displayed anymore."
25
+ end
26
+
27
+ file = File.open("#{config.path}/config_tmp.status", "w")
28
+ file.write config.inspect
29
+ file.close
30
+
31
+ else
32
+ respond 'Only master admins on master channel can use this command.'
33
+ end
34
+ else
35
+ respond 'Only master admins on master channel can use this command.'
36
+ end
37
+ end
38
+ end
@@ -8,6 +8,12 @@ class SlackSmartBot
8
8
  # helpmaster: `turn maintenance off`
9
9
  # helpmaster: The SmartBot will be on maintenance and responding with a generic message
10
10
  # helpmaster: Only works if you are on Master channel and you are a master admin user
11
+ # helpmaster: You can add interpolation to the message you are adding
12
+ # helpmaster: Examples:
13
+ # helpmaster: _set maintenance on_
14
+ # helpmaster: _set maintenance on We are on maintenance. We'll be available again in #{((Time.new(2021,6,18,13,30,0)-Time.now)/60).to_i} minutes_
15
+ # helpmaster: _turn maintenance on `We are on *maintenance* until *12:00*`_
16
+ # helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
11
17
  # helpmaster:
12
18
  def set_maintenance(from, status, message)
13
19
  save_stats(__method__)
@@ -22,9 +28,11 @@ class SlackSmartBot
22
28
  if status == 'on'
23
29
  config.on_maintenance = true
24
30
  respond "From now on I'll be on maintenance status so I won't be responding accordingly."
31
+ save_status :off, :maintenance_on, config.on_maintenance_message
25
32
  else
26
33
  config.on_maintenance = false
27
34
  respond "From now on I won't be on maintenance. Everything is back to normal!"
35
+ save_status :on, :maintenance_off, config.on_maintenance_message
28
36
  end
29
37
 
30
38
  file = File.open("#{config.path}/config_tmp.status", "w")
@@ -2,18 +2,20 @@ class SlackSmartBot
2
2
  # helpmaster: ----------------------------------------------
3
3
  # helpmaster: `create bot on CHANNEL_NAME`
4
4
  # helpmaster: `create cloud bot on CHANNEL_NAME`
5
- # helpmaster: creates a new bot on the channel specified
6
- # helpmaster: it will work only if you are on Master channel
7
- # helpmaster: the admins will be the master admins, the creator of the bot and the creator of the channel
8
- # helpmaster: follow the instructions in case creating cloud bots
5
+ # helpmaster: `create silent bot on CHANNEL_NAME`
6
+ # helpmaster: Creates a new bot on the channel specified
7
+ # helpmaster: It will work only if you are on Master channel
8
+ # helpmaster: The admins will be the master admins, the creator of the bot and the creator of the channel
9
+ # helpmaster: Follow the instructions in case creating cloud bots
10
+ # helpmaster: In case 'silent' won't display the Bot initialization message on the CHANNEL_NAME
11
+ # helpmaster: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
9
12
  # helpmaster:
10
- def create_bot(dest, user, cloud, channel)
13
+ def create_bot(dest, user, type, channel)
14
+ cloud = type.include?('cloud')
15
+ silent = type.include?('silent')
11
16
  save_stats(__method__)
12
17
  from = user.name
13
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
14
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_user].id)))
15
- respond "You don't have access to use this command, please contact an Admin to be able to use it: <@#{config.admins.join(">, <@")}>"
16
- else
18
+ if has_access?(__method__, user)
17
19
  if config.on_master_bot
18
20
  get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
19
21
  channel_id = nil
@@ -25,6 +27,7 @@ class SlackSmartBot
25
27
  end
26
28
  #todo: add pagination for case more than 1000 channels on the workspace
27
29
  channels = get_channels()
30
+ channel = @channels_name[channel] if @channels_name.key?(channel)
28
31
  channel_found = channels.detect { |c| c.name == channel }
29
32
  members = get_channel_members(@channels_id[channel]) unless channel_found.nil?
30
33
 
@@ -40,32 +43,40 @@ class SlackSmartBot
40
43
  if channel_id != config[:channel]
41
44
  begin
42
45
  rules_file = "slack-smart-bot_rules_#{channel_id}_#{from.gsub(" ", "_")}.rb"
43
- if defined?(RULES_FOLDER)
46
+ if defined?(RULES_FOLDER) # consider removing RULES_FOLDER since we are not using it anywhere else
44
47
  rules_file = RULES_FOLDER + rules_file
45
48
  general_rules_file = RULES_FOLDER + 'general_rules.rb'
49
+ general_commands_file = RULES_FOLDER + 'general_commands.rb'
46
50
  else
47
51
  Dir.mkdir("#{config.path}/rules") unless Dir.exist?("#{config.path}/rules")
48
52
  Dir.mkdir("#{config.path}/rules/#{channel_id}") unless Dir.exist?("#{config.path}/rules/#{channel_id}")
49
53
  rules_file = "/rules/#{channel_id}/" + rules_file
50
54
  general_rules_file = "/rules/general_rules.rb"
55
+ general_commands_file = "/rules/general_commands.rb"
51
56
  end
52
57
  default_rules = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_rules.rb")
53
58
  default_general_rules = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_general_rules.rb")
59
+ default_general_commands = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_general_commands.rb")
54
60
 
55
61
  File.delete(config.path + rules_file) if File.exist?(config.path + rules_file)
56
62
  FileUtils.copy_file(default_rules, config.path + rules_file) unless File.exist?(config.path + rules_file)
57
63
  FileUtils.copy_file(default_general_rules, config.path + general_rules_file) unless File.exist?(config.path + general_rules_file)
64
+ FileUtils.copy_file(default_general_commands, config.path + general_commands_file) unless File.exist?(config.path + general_commands_file)
58
65
  admin_users = Array.new()
59
- creator_info = get_user_info(channel_found.creator)
60
- admin_users = [from, creator_info.user.name] + config.masters
66
+ creator_info = @users.select{|u| u.id == channel_found.creator or (u.key?(:enterprise_user) and u.enterprise_user.id == channel_found.creator)}[-1]
67
+ if creator_info.nil? or creator_info.empty? or creator_info.user.nil?
68
+ admin_users = [from] + config.masters
69
+ else
70
+ admin_users = [from, creator_info.user.name] + config.masters
71
+ end
61
72
  admin_users.uniq!
62
- @logger.info "ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on"
73
+ @logger.info "BOT_SILENT=#{silent} ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on"
63
74
 
64
75
  if cloud
65
76
  respond "Copy the bot folder to your cloud location and run `ruby #{config.file} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on&`", dest
66
77
  else
67
78
  t = Thread.new do
68
- `BOT_SILENT=false ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on`
79
+ `BOT_SILENT=#{silent} ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on`
69
80
  end
70
81
  end
71
82
  @bots_created[channel_id] = {
@@ -80,6 +91,8 @@ class SlackSmartBot
80
91
  cloud: cloud,
81
92
  thread: t,
82
93
  }
94
+ @bots_created[channel_id].silent = true if silent
95
+
83
96
  respond "The bot has been created on channel: #{channel}. Rules file: #{File.basename rules_file}. Admins: #{admin_users.join(", ")}", dest
84
97
  update_bots_file()
85
98
  rescue Exception => stack
@@ -2,6 +2,7 @@ require_relative "commands/general/whats_new"
2
2
  require_relative "commands/general/hi_bot"
3
3
  require_relative "commands/general/bye_bot"
4
4
  require_relative "commands/general/bot_help"
5
+ require_relative "commands/general/suggest_command"
5
6
  require_relative "commands/on_bot/ruby_code"
6
7
  require_relative "commands/on_bot/repl"
7
8
  require_relative "commands/on_bot/get_repl"
@@ -18,6 +19,7 @@ require_relative "commands/on_bot/admin/add_routine"
18
19
  require_relative "commands/on_bot/admin/start_bot"
19
20
  require_relative "commands/on_bot/admin/pause_bot"
20
21
  require_relative "commands/on_bot/admin/remove_routine"
22
+ require_relative "commands/on_bot/admin/see_result_routine"
21
23
  require_relative "commands/on_bot/admin/run_routine"
22
24
  require_relative "commands/on_bot/admin/pause_routine"
23
25
  require_relative "commands/on_bot/admin/start_routine"
@@ -30,5 +32,19 @@ require_relative "commands/on_bot/delete_shortcut"
30
32
  require_relative "commands/on_bot/see_shortcuts"
31
33
  require_relative "commands/on_extended/bot_rules"
32
34
  require_relative "commands/on_bot/admin_master/get_bot_logs"
35
+ require_relative "commands/on_bot/admin_master/send_message"
36
+ require_relative "commands/on_bot/admin_master/react_to"
33
37
  require_relative "commands/general/bot_stats"
38
+ require_relative "commands/general/leaderboard"
39
+ require_relative "commands/general/add_announcement"
40
+ require_relative "commands/general/delete_announcement"
41
+ require_relative "commands/general/see_announcements"
42
+ require_relative "commands/general/see_statuses"
43
+ require_relative "commands/general/see_favorite_commands"
44
+ require_relative "commands/on_master/admin_master/publish_announcements"
34
45
  require_relative "commands/on_master/admin_master/set_maintenance"
46
+ require_relative "commands/on_master/admin_master/set_general_message"
47
+ require_relative "commands/general_bot_commands"
48
+ require_relative "commands/general/share_messages"
49
+ require_relative "commands/general/see_shares"
50
+ require_relative "commands/general/delete_share"