slack-smart-bot 1.9.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +184 -16
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -49
  4. data/lib/slack/smart-bot/comm/delete.rb +13 -0
  5. data/lib/slack/smart-bot/comm/dont_understand.rb +3 -3
  6. data/lib/slack/smart-bot/comm/event_hello.rb +8 -4
  7. data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -4
  8. data/lib/slack/smart-bot/comm/get_channels.rb +31 -16
  9. data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
  10. data/lib/slack/smart-bot/comm/get_user_info.rb +12 -8
  11. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  12. data/lib/slack/smart-bot/comm/react.rb +19 -2
  13. data/lib/slack/smart-bot/comm/respond.rb +224 -53
  14. data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
  15. data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
  16. data/lib/slack/smart-bot/comm/send_file.rb +38 -34
  17. data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
  18. data/lib/slack/smart-bot/comm/send_msg_user.rb +59 -33
  19. data/lib/slack/smart-bot/comm/unreact.rb +22 -18
  20. data/lib/slack/smart-bot/comm.rb +4 -0
  21. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  22. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  23. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  24. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  25. data/lib/slack/smart-bot/commands/general/bot_help.rb +69 -33
  26. data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
  27. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
  28. data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
  29. data/lib/slack/smart-bot/commands/general/delete_team.rb +34 -0
  30. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  31. data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
  32. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  33. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  34. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  35. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  36. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  37. data/lib/slack/smart-bot/commands/general/see_announcements.rb +115 -0
  38. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  39. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +53 -0
  40. data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
  41. data/lib/slack/smart-bot/commands/general/see_statuses.rb +91 -0
  42. data/lib/slack/smart-bot/commands/general/see_teams.rb +252 -0
  43. data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
  44. data/lib/slack/smart-bot/commands/general/update_team.rb +109 -0
  45. data/lib/slack/smart-bot/commands/general_bot_commands.rb +504 -0
  46. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +4 -6
  47. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +45 -14
  48. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +4 -1
  49. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +6 -3
  50. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +3 -1
  51. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +4 -4
  52. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +8 -2
  53. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +33 -0
  54. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +13 -10
  55. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +6 -3
  56. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +3 -1
  57. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +4 -1
  58. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  59. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  60. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +34 -0
  61. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +37 -0
  62. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +4 -5
  63. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +7 -8
  64. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +400 -0
  65. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +3 -4
  66. data/lib/slack/smart-bot/commands/on_bot/general/leaderboard.rb +201 -0
  67. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +12 -6
  68. data/lib/slack/smart-bot/commands/on_bot/general/suggest_command.rb +36 -0
  69. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +13 -11
  70. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  71. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +4 -5
  72. data/lib/slack/smart-bot/commands/on_bot/repl.rb +76 -21
  73. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +3 -4
  74. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +15 -7
  75. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +5 -6
  76. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +5 -6
  77. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +45 -12
  78. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +7 -3
  79. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +4 -1
  80. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +3 -1
  81. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +33 -0
  82. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +39 -0
  83. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +10 -1
  84. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +28 -14
  85. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  86. data/lib/slack/smart-bot/commands.rb +36 -5
  87. data/lib/slack/smart-bot/listen.rb +31 -33
  88. data/lib/slack/smart-bot/process.rb +234 -73
  89. data/lib/slack/smart-bot/process_first.rb +119 -38
  90. data/lib/slack/smart-bot/treat_message.rb +310 -237
  91. data/lib/slack/smart-bot/utils/build_help.rb +2 -2
  92. data/lib/slack/smart-bot/utils/create_routine_thread.rb +81 -46
  93. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  94. data/lib/slack/smart-bot/utils/get_admins_channels.rb +13 -0
  95. data/lib/slack/smart-bot/utils/get_bots_created.rb +28 -8
  96. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  97. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  98. data/lib/slack/smart-bot/utils/get_help.rb +79 -73
  99. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  100. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  101. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  102. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  103. data/lib/slack/smart-bot/utils/has_access.rb +28 -0
  104. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  105. data/lib/slack/smart-bot/utils/save_stats.rb +46 -41
  106. data/lib/slack/smart-bot/utils/save_status.rb +67 -0
  107. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  108. data/lib/slack/smart-bot/utils/update_admins_channels.rb +8 -0
  109. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  110. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  111. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  112. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  113. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  114. data/lib/slack/smart-bot/utils.rb +11 -0
  115. data/lib/slack-smart-bot.rb +72 -12
  116. data/lib/slack-smart-bot_general_commands.rb +61 -0
  117. data/lib/slack-smart-bot_general_rules.rb +5 -2
  118. data/lib/slack-smart-bot_rules.rb +43 -17
  119. data/whats_new.txt +20 -15
  120. metadata +76 -9
  121. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -313
@@ -4,17 +4,20 @@ class SlackSmartBot
4
4
  # helpadmin: `extend rules to CHANNEL_NAME`
5
5
  # helpadmin: `use rules on CHANNEL_NAME`
6
6
  # helpadmin: It will allow to use the specific rules from this channel on the CHANNEL_NAME
7
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#extending-rules-to-other-channels|more info>
8
+ # helpadmin: command_id: :extend_rules
7
9
  # helpadmin:
8
10
  def extend_rules(dest, user, from, channel, typem)
9
11
  save_stats(__method__)
10
12
  unless typem == :on_extended
11
13
  if config.on_master_bot
12
14
  respond "You cannot use the rules from Master Channel on any other channel.", dest
13
- elsif !config.admins.include?(from) #not admin
15
+ elsif !is_admin? #not admin
14
16
  respond "Only admins can extend the rules. Admins on this channel: #{config.admins}", dest
15
17
  else
16
18
  #todo: add pagination for case more than 1000 channels on the workspace
17
19
  channels = get_channels()
20
+ channel = @channels_name[channel] if @channels_name.key?(channel)
18
21
 
19
22
  channel_found = channels.detect { |c| c.name == channel }
20
23
  get_channels_name_and_id()
@@ -5,18 +5,21 @@ class SlackSmartBot
5
5
  # helpadmin: `pause this bot`
6
6
  # helpadmin: the bot will pause so it will listen only to admin commands
7
7
  # helpadmin: You can use this command only if you are an admin user
8
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
9
+ # helpadmin: command_id: :pause_bot
8
10
  # helpadmin:
9
11
  def pause_bot(dest, from)
10
12
  save_stats(__method__)
11
- if config.admins.include?(from) #admin user
13
+ if is_admin?
12
14
  respond "This bot is paused from now on. You can start it again: start this bot", dest
13
15
  respond "zZzzzzZzzzzZZZZZZzzzzzzzz", dest
14
16
  @status = :paused
15
- @bots_created[@channel_id][:status] = :paused
16
- update_bots_file()
17
17
  unless config.on_master_bot
18
+ @bots_created[@channel_id][:status] = :paused
19
+ update_bots_file()
18
20
  send_msg_channel config.master_channel, "Changed status on #{config.channel} to :paused"
19
21
  end
22
+ save_status :off, :paused, 'The admin paused this bot'
20
23
  else
21
24
  respond "Only admin users can put me on pause", dest
22
25
  end
@@ -6,10 +6,12 @@ class SlackSmartBot
6
6
  # helpadmin: NAME: one word to identify the routine
7
7
  # helpadmin: Examples:
8
8
  # helpadmin: _pause routine example_
9
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
10
+ # helpadmin: command_id: :pause_routine
9
11
  # helpadmin:
10
12
  def pause_routine(dest, from, name)
11
13
  save_stats(__method__)
12
- if config.admins.include?(from) #admin user
14
+ if is_admin?
13
15
  if !config.on_master_bot and dest[0] == "D"
14
16
  respond "It's only possible to pause routines from MASTER channel from a direct message with the bot.", dest
15
17
  elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
@@ -9,13 +9,13 @@ class SlackSmartBot
9
9
  # helpadmin: NAME: one word to identify the routine
10
10
  # helpadmin: Examples:
11
11
  # helpadmin: _kill routine example_
12
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
13
+ # helpadmin: command_id: :remove_routine
12
14
  # helpadmin:
13
15
  def remove_routine(dest, from, name)
14
16
  save_stats(__method__)
15
- if config.admins.include?(from) #admin user
16
- if !config.on_master_bot and dest[0] == "D"
17
- respond "It's only possible to remove routines from MASTER channel from a direct message with the bot.", dest
18
- elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
17
+ if is_admin?
18
+ if @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
19
19
  @routines[@channel_id][name][:thread].exit
20
20
  @routines[@channel_id].delete(name)
21
21
  update_routines()
@@ -8,14 +8,17 @@ class SlackSmartBot
8
8
  # helpadmin: NAME: one word to identify the routine
9
9
  # helpadmin: Examples:
10
10
  # helpadmin: _run routine example_
11
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
12
+ # helpadmin: command_id: :run_routine
11
13
  # helpadmin:
12
14
 
13
15
  def run_routine(dest, from, name)
14
16
  save_stats(__method__)
15
- if config.admins.include?(from) #admin user
17
+ if is_admin?
16
18
  if !config.on_master_bot and dest[0] == "D"
17
19
  respond "It's only possible to run routines from MASTER channel from a direct message with the bot.", dest
18
20
  elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
21
+ File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.exist?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
19
22
  if @routines[@channel_id][name][:file_path] != ""
20
23
  if @routines[@channel_id][name][:file_path].match?(/\.rb$/i)
21
24
  ruby = "ruby "
@@ -40,7 +43,10 @@ class SlackSmartBot
40
43
  treat_message({ channel: @routines[@channel_id][name][:dest],
41
44
  user: @routines[@channel_id][name][:creator_id],
42
45
  text: @routines[@channel_id][name][:command],
43
- files: nil })
46
+ files: nil,
47
+ routine_name: name,
48
+ routine_type: @routines[@channel_id][name][:routine_type],
49
+ routine: true })
44
50
  end
45
51
  @routines[@channel_id][name][:last_elapsed] = (Time.now - started)
46
52
  @routines[@channel_id][name][:last_run] = started.to_s
@@ -0,0 +1,33 @@
1
+ class SlackSmartBot
2
+
3
+ # helpadmin: ----------------------------------------------
4
+ # helpadmin: `see routine result NAME`
5
+ # helpadmin: `see result routine NAME`
6
+ # helpadmin: `result routine NAME`
7
+ # helpadmin: It will display the last result of the routine run.
8
+ # helpadmin: You can use this command only if you are an admin user
9
+ # helpadmin: NAME: one word to identify the routine
10
+ # helpadmin: Examples:
11
+ # helpadmin: _see routine result example_
12
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
13
+ # helpadmin: command_id: :see_result_routine
14
+ # helpadmin:
15
+ def see_result_routine(dest, from, name)
16
+ save_stats(__method__)
17
+ if is_admin?
18
+ if @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
19
+ if File.exist?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
20
+ msg = "*Results from routine run #{File.mtime("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")}*\n"
21
+ msg += File.read("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
22
+ respond msg, dest
23
+ else
24
+ respond "The routine *`#{name}`* doesn't have any result yet.", dest
25
+ end
26
+ else
27
+ respond "There isn't a routine with that name: *`#{name}`*.\nCall `see routines` to see added routines", dest
28
+ end
29
+ else
30
+ respond "Only admin users can see the routines results", dest
31
+ end
32
+ end
33
+ end
@@ -5,29 +5,31 @@ class SlackSmartBot
5
5
  # helpadmin: It will show the routines of the channel
6
6
  # helpadmin: In case of `all` and on the master channel, it will show all the routines from all channels
7
7
  # helpadmin: You can use this command only if you are an admin user
8
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
9
+ # helpadmin: command_id: :see_routines
8
10
  # helpadmin:
9
11
  def see_routines(dest, from, user, all)
10
12
  save_stats(__method__)
11
- if config.admins.include?(from) #admin user
13
+ if is_admin?
12
14
  if all
13
15
  routines = {}
14
16
  if config.on_master_bot
15
- Dir["#{config.path}/routines/routines_*.rb"].each do |rout|
16
- file_conf = IO.readlines(rout).join
17
- unless file_conf.to_s() == ""
18
- routines.merge!(eval(file_conf))
17
+ Dir["#{config.path}/routines/routines_*.yaml"].each do |rout|
18
+ routine = YAML.load(File.read(rout))
19
+ unless routine.is_a?(FalseClass)
20
+ routines.merge!(routine)
19
21
  end
20
22
  end
21
23
  else
22
24
  respond "To see all routines on all channels you need to run the command on the master channel.\nI'll display only the routines on this channel.", dest
23
- routines = @routines.dup
25
+ routines = @routines
24
26
  end
25
27
  else
26
- if @rules_imported.key?(user.id) and @rules_imported[user.id].key?(user.id) and dest[0] == "D"
27
- file_conf = IO.readlines("#{config.path}/routines/routines_#{@rules_imported[user.id][user.id]}.rb").join
28
- routines = eval(file_conf)
28
+ if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name) and dest[0] == "D"
29
+ routines = YAML.load(File.read("#{config.path}/routines/routines_#{@rules_imported[user.name][user.name]}.yaml"))
30
+ routines = {} if routines.is_a?(FalseClass)
29
31
  else
30
- routines = @routines.dup
32
+ routines = @routines
31
33
  end
32
34
  end
33
35
 
@@ -57,6 +59,7 @@ class SlackSmartBot
57
59
  msg << "\tCommand: #{v[:command]}" unless v[:command].to_s.strip == ''
58
60
  msg << "\tFile: #{v[:file_path]}" unless v[:file_path] == ''
59
61
  msg << "\tSilent: #{v[:silent]}" unless !v[:silent]
62
+ msg << "\tType: #{v[:routine_type]}" if v[:routine_type].to_s == 'bgroutine'
60
63
  respond msg.join("\n"), dest
61
64
  end
62
65
  end
@@ -5,17 +5,20 @@ class SlackSmartBot
5
5
  # helpadmin: `start this bot`
6
6
  # helpadmin: the bot will start to listen
7
7
  # helpadmin: You can use this command only if you are an admin user
8
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
9
+ # helpadmin: command_id: :start_bot
8
10
  # helpadmin:
9
11
  def start_bot(dest, from)
10
12
  save_stats(__method__)
11
- if config.admins.include?(from) #admin user
13
+ if is_admin?
12
14
  respond "This bot is running and listening from now on. You can pause again: pause this bot", dest
13
15
  @status = :on
14
- @bots_created[@channel_id][:status] = :on
15
- update_bots_file()
16
16
  unless config.on_master_bot
17
+ @bots_created[@channel_id][:status] = :on
18
+ update_bots_file()
17
19
  send_msg_channel config.master_channel, "Changed status on #{config.channel} to :on"
18
20
  end
21
+ save_status :on, :started, 'The admin started this bot'
19
22
  else
20
23
  respond "Only admin users can change my status", dest
21
24
  end
@@ -7,11 +7,13 @@ class SlackSmartBot
7
7
  # helpadmin: NAME: one word to identify the routine
8
8
  # helpadmin: Examples:
9
9
  # helpadmin: _start routine example_
10
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
11
+ # helpadmin: command_id: :start_routine
10
12
  # helpadmin:
11
13
 
12
14
  def start_routine(dest, from, name)
13
15
  save_stats(__method__)
14
- if config.admins.include?(from) #admin user
16
+ if is_admin?
15
17
  if !config.on_master_bot and dest[0] == "D"
16
18
  respond "It's only possible to start routines from MASTER channel from a direct message with the bot.", dest
17
19
  elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
@@ -3,15 +3,18 @@ class SlackSmartBot
3
3
  # helpadmin: ----------------------------------------------
4
4
  # helpadmin: `stop using rules on CHANNEL_NAME`
5
5
  # helpadmin: it will stop using the extended rules on the specified channel.
6
+ # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#extending-rules-to-other-channels|more info>
7
+ # helpadmin: command_id: :stop_using_rules_on
6
8
  # helpadmin:
7
9
 
8
10
  def stop_using_rules_on(dest, user, from, channel, typem)
9
11
  save_stats(__method__)
10
12
  unless typem == :on_extended
11
- if !config.admins.include?(from) #not admin
13
+ if !is_admin?
12
14
  respond "Only admins can extend or stop using the rules. Admins on this channel: #{config.admins}", dest
13
15
  else
14
16
  get_bots_created()
17
+ channel = @channels_name[channel] if @channels_name.key?(channel)
15
18
  if @bots_created[@channel_id][:extended].include?(channel)
16
19
  @bots_created[@channel_id][:extended].delete(channel)
17
20
  update_bots_file()
@@ -0,0 +1,25 @@
1
+ class SlackSmartBot
2
+
3
+ # helpadmin: ----------------------------------------------
4
+ # helpadmin: `delete message URL`
5
+ # helpadmin: It will delete the SmartBot message supplied
6
+ # helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
7
+ # helpadmin: command_id: :delete_message
8
+ # helpadmin:
9
+ def delete_message(from, typem, url)
10
+ save_stats(__method__)
11
+ channel, ts = url.scan(/\/archives\/(\w+)\/(\w\d+)/)[0]
12
+ if config.masters.include?(from) and typem==:on_dm and !channel.nil? #master admin user
13
+ ts = "#{ts[0..-7]}.#{ts[-6..-1]}"
14
+ succ = delete(channel, ts)
15
+ if succ
16
+ react :heavy_check_mark
17
+ else
18
+ react :x
19
+ end
20
+ else
21
+ respond "Only master admin users on a private conversation with the SmartBot can delete SmartBot messages"
22
+ end
23
+ end
24
+ end
25
+
@@ -4,6 +4,7 @@ class SlackSmartBot
4
4
  # helpadmin: `get bot logs`
5
5
  # helpadmin: To see the bot logs
6
6
  # helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
7
+ # helpadmin: command_id: :get_bot_logs
7
8
  # helpadmin:
8
9
  def get_bot_logs(dest, from, typem)
9
10
  save_stats(__method__)
@@ -0,0 +1,34 @@
1
+ class SlackSmartBot
2
+
3
+ # helpadmin: ----------------------------------------------
4
+ # helpadmin: `react to #CHANNEL_NAME THREAD_ID EMOJIS`
5
+ # helpadmin: `react to URL EMOJIS`
6
+ # helpadmin: It will send the specified reactions as SmartBot
7
+ # helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
8
+ # helpadmin: Examples:
9
+ # helpadmin: _react to #sales 1622550707.012100 :thumbsup:_
10
+ # helpadmin: _react to #sales p1622550707012100 :thumbsup:_
11
+ # helpadmin: _react to #sales p1622550707012100 :thumbsup: :heavy_check_mark: :bathtub:_
12
+ # helpadmin: command_id: :react_to
13
+ # helpadmin:
14
+ def react_to(dest, from, typem, to, thread_ts, emojis)
15
+ save_stats(__method__)
16
+ if config.masters.include?(from) and typem==:on_dm #master admin user
17
+ succs = []
18
+ emojis.split(' ').each do |emoji|
19
+ succs << (react emoji, thread_ts, to)
20
+ end
21
+ succs.uniq!
22
+ if succs.size == 1 and succs[0] == true
23
+ react :heavy_check_mark
24
+ elsif succs.size == 2
25
+ react :exclamation
26
+ else
27
+ react :x
28
+ end
29
+ else
30
+ respond "Only master admin users on a private conversation with the SmartBot can send reactions as SmartBot.", dest
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,37 @@
1
+ class SlackSmartBot
2
+
3
+ # helpadmin: ----------------------------------------------
4
+ # helpadmin: `send message to @USER_NAME : MESSAGE`
5
+ # helpadmin: `send message to #CHANNEL_NAME : MESSAGE`
6
+ # helpadmin: `send message to THREAD_ID : MESSAGE`
7
+ # helpadmin: `send message to URL : MESSAGE`
8
+ # helpadmin: `send message to @USER1 @USER99 : MESSAGE`
9
+ # helpadmin: `send message to #CHANNEL1 #CHANNEL99 : MESSAGE`
10
+ # helpadmin: It will send the specified message as SmartBot
11
+ # helpadmin: You can use this command only if you are a Master admin user and if you are in a private conversation with the bot
12
+ # helpadmin: command_id: :send_message
13
+ # helpadmin:
14
+ def send_message(dest, from, typem, to, thread_ts, message)
15
+ save_stats(__method__)
16
+ if config.masters.include?(from) and typem==:on_dm #master admin user
17
+ unless Thread.current[:command_orig].to_s == ''
18
+ message_orig = Thread.current[:command_orig].to_s.gsub("\u00A0", " ").scan(/[^:]+\s*:\s+(.+)/im).join
19
+ message = message_orig unless message_orig == ''
20
+ end
21
+ succ = true
22
+ to.each do |t|
23
+ unless t.match?(/^\s*$/)
24
+ succ = (respond message, t, thread_ts: thread_ts, web_client: true) && succ
25
+ end
26
+ end
27
+ if succ
28
+ react :heavy_check_mark
29
+ else
30
+ react :x
31
+ end
32
+ else
33
+ respond "Only master admin users on a private conversation with the SmartBot can send messages as SmartBot.", dest
34
+ end
35
+ end
36
+ end
37
+
@@ -5,17 +5,16 @@ class SlackSmartBot
5
5
  # help: `remove repl SESSION_NAME`
6
6
  # help: Will delete the specified REPL
7
7
  # help: Only the creator of the REPL or an admin can delete REPLs
8
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
9
+ # help: command_id: :delete_repl
8
10
  # help:
9
11
  def delete_repl(dest, user, session_name)
10
12
  #todo: add tests
11
13
  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
14
+ if has_access?(__method__, user)
16
15
  if @repls.key?(session_name)
17
16
  Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
18
- if config.admins.include?(user.name) or @repls[session_name].creator_name == user.name
17
+ if is_admin?(user.name) or @repls[session_name].creator_name == user.name
19
18
  @repls.delete(session_name)
20
19
  update_repls()
21
20
  File.rename("#{config.path}/repl/#{@channel_id}/#{session_name}.input", "#{config.path}/repl/#{@channel_id}/#{session_name}_#{Time.now.strftime("%Y%m%d%H%M%S%N")}.deleted")
@@ -5,27 +5,26 @@ class SlackSmartBot
5
5
  # help: `delete global sc NAME`
6
6
  # help: It will delete the shortcut with the supplied name
7
7
  # help: 'global' or 'generic' can only be used on Master channel.
8
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#shortcuts|more info>
9
+ # help: command_id: :delete_shortcut
8
10
  # help:
9
11
 
10
12
  def delete_shortcut(dest, user, shortcut, typem, command, global)
11
13
  save_stats(__method__)
12
14
  unless typem == :on_extended
13
15
  from = user.name
14
- if config[:allow_access].key?(__method__) and !config[:allow_access][__method__].include?(user.name) and !config[:allow_access][__method__].include?(user.id) and
15
- (!user.key?(:enterprise_user) or ( user.key?(:enterprise_user) and !config[:allow_access][__method__].include?(user[:enterprise_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
16
+ if has_access?(__method__, user)
18
17
  deleted = false
19
18
 
20
19
  if global
21
20
  if !config.on_master_bot or typem != :on_master
22
21
  respond "It is only possible to delete global shortcuts from Master channel"
23
22
  else
24
- if !config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut) and
23
+ if !is_admin?(from) and @shortcuts_global[:all].include?(shortcut) and
25
24
  (!@shortcuts_global.key?(from) or !@shortcuts_global[from].include?(shortcut))
26
25
  respond "Only the creator of the shortcut or an admin user can delete it"
27
26
  elsif (@shortcuts_global.key?(from) and @shortcuts_global[from].keys.include?(shortcut)) or
28
- (config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut))
27
+ (is_admin?(from) and @shortcuts_global[:all].include?(shortcut))
29
28
 
30
29
  respond "global shortcut deleted!", dest
31
30
  if @shortcuts_global.key?(from) and @shortcuts_global[from].key?(shortcut)
@@ -41,11 +40,11 @@ class SlackSmartBot
41
40
  end
42
41
  end
43
42
  else
44
- if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut) and
43
+ if !is_admin?(from) and @shortcuts[:all].include?(shortcut) and
45
44
  (!@shortcuts.key?(from) or !@shortcuts[from].include?(shortcut))
46
45
  respond "Only the creator of the shortcut or an admin user can delete it", dest
47
46
  elsif (@shortcuts.keys.include?(from) and @shortcuts[from].keys.include?(shortcut)) or
48
- (config.admins.include?(from) and @shortcuts[:all].include?(shortcut))
47
+ (is_admin?(from) and @shortcuts[:all].include?(shortcut))
49
48
  #are you sure? to avoid deleting by mistake
50
49
  if answer.empty?
51
50
  ask("are you sure you want to delete it?", command, from, dest)