slack-smart-bot 1.10.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +134 -23
  3. data/lib/slack/smart-bot/comm/delete.rb +13 -0
  4. data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
  5. data/lib/slack/smart-bot/comm/get_channel_members.rb +7 -3
  6. data/lib/slack/smart-bot/comm/get_presence.rb +20 -0
  7. data/lib/slack/smart-bot/comm/get_users.rb +1 -1
  8. data/lib/slack/smart-bot/comm/respond.rb +24 -13
  9. data/lib/slack/smart-bot/comm/send_msg_user.rb +12 -11
  10. data/lib/slack/smart-bot/comm/set_status.rb +21 -0
  11. data/lib/slack/smart-bot/comm.rb +3 -0
  12. data/lib/slack/smart-bot/commands/general/add_admin.rb +51 -0
  13. data/lib/slack/smart-bot/commands/general/add_announcement.rb +1 -1
  14. data/lib/slack/smart-bot/commands/general/add_memo_team.rb +117 -0
  15. data/lib/slack/smart-bot/commands/general/add_team.rb +80 -0
  16. data/lib/slack/smart-bot/commands/general/add_vacation.rb +51 -0
  17. data/lib/slack/smart-bot/commands/general/allow_access.rb +67 -0
  18. data/lib/slack/smart-bot/commands/general/bot_help.rb +20 -11
  19. data/lib/slack/smart-bot/commands/general/delete_announcement.rb +1 -1
  20. data/lib/slack/smart-bot/commands/general/delete_memo_team.rb +69 -0
  21. data/lib/slack/smart-bot/commands/general/delete_share.rb +1 -1
  22. data/lib/slack/smart-bot/commands/general/delete_team.rb +54 -0
  23. data/lib/slack/smart-bot/commands/general/deny_access.rb +36 -0
  24. data/lib/slack/smart-bot/commands/general/ping_team.rb +100 -0
  25. data/lib/slack/smart-bot/commands/general/poster.rb +116 -0
  26. data/lib/slack/smart-bot/commands/general/remove_admin.rb +58 -0
  27. data/lib/slack/smart-bot/commands/general/remove_vacation.rb +27 -0
  28. data/lib/slack/smart-bot/commands/general/see_access.rb +24 -0
  29. data/lib/slack/smart-bot/commands/general/see_admins.rb +33 -0
  30. data/lib/slack/smart-bot/commands/general/see_announcements.rb +7 -5
  31. data/lib/slack/smart-bot/commands/general/see_command_ids.rb +29 -0
  32. data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +3 -4
  33. data/lib/slack/smart-bot/commands/general/see_statuses.rb +34 -21
  34. data/lib/slack/smart-bot/commands/general/see_teams.rb +402 -0
  35. data/lib/slack/smart-bot/commands/general/see_vacations.rb +58 -0
  36. data/lib/slack/smart-bot/commands/general/see_vacations_team.rb +136 -0
  37. data/lib/slack/smart-bot/commands/general/set_memo_status.rb +58 -0
  38. data/lib/slack/smart-bot/commands/general/share_messages.rb +1 -1
  39. data/lib/slack/smart-bot/commands/general/update_team.rb +130 -0
  40. data/lib/slack/smart-bot/commands/general_bot_commands.rb +442 -13
  41. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +2 -1
  42. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +2 -1
  43. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +2 -1
  44. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +2 -1
  45. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +2 -1
  46. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -1
  47. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +3 -2
  48. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +2 -1
  49. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +10 -9
  50. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +2 -1
  51. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +2 -1
  52. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -1
  53. data/lib/slack/smart-bot/commands/on_bot/admin_master/delete_message.rb +25 -0
  54. data/lib/slack/smart-bot/commands/on_bot/admin_master/get_bot_logs.rb +1 -0
  55. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +3 -1
  56. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +15 -2
  57. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +2 -1
  58. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +5 -4
  59. data/lib/slack/smart-bot/commands/on_bot/general/bot_stats.rb +416 -0
  60. data/lib/slack/smart-bot/commands/{general → on_bot/general}/bot_status.rb +1 -0
  61. data/lib/slack/smart-bot/commands/{general → on_bot/general}/leaderboard.rb +1 -0
  62. data/lib/slack/smart-bot/commands/{general → on_bot/general}/stop_using_rules.rb +1 -0
  63. data/lib/slack/smart-bot/commands/{general → on_bot/general}/suggest_command.rb +6 -0
  64. data/lib/slack/smart-bot/commands/{general → on_bot/general}/use_rules.rb +1 -0
  65. data/lib/slack/smart-bot/commands/{general → on_bot/general}/whats_new.rb +2 -1
  66. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +2 -1
  67. data/lib/slack/smart-bot/commands/on_bot/kill_repl.rb +32 -0
  68. data/lib/slack/smart-bot/commands/on_bot/repl.rb +73 -15
  69. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +1 -0
  70. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +117 -28
  71. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +2 -1
  72. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +3 -2
  73. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +5 -4
  74. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +3 -2
  75. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
  76. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +6 -3
  77. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +2 -1
  78. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +2 -1
  79. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +1 -0
  80. data/lib/slack/smart-bot/commands/on_master/where_smartbot.rb +41 -0
  81. data/lib/slack/smart-bot/commands.rb +30 -7
  82. data/lib/slack/smart-bot/listen.rb +30 -30
  83. data/lib/slack/smart-bot/process.rb +53 -23
  84. data/lib/slack/smart-bot/process_first.rb +2 -2
  85. data/lib/slack/smart-bot/treat_message.rb +23 -17
  86. data/lib/slack/smart-bot/utils/build_help.rb +1 -1
  87. data/lib/slack/smart-bot/utils/check_vacations.rb +43 -0
  88. data/lib/slack/smart-bot/utils/create_routine_thread.rb +1 -1
  89. data/lib/slack/smart-bot/utils/get_access_channels.rb +13 -0
  90. data/lib/slack/smart-bot/utils/get_admins_channels.rb +33 -0
  91. data/lib/slack/smart-bot/utils/get_bots_created.rb +27 -10
  92. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +7 -2
  93. data/lib/slack/smart-bot/utils/get_command_ids.rb +84 -0
  94. data/lib/slack/smart-bot/utils/get_help.rb +36 -19
  95. data/lib/slack/smart-bot/utils/get_repls.rb +22 -2
  96. data/lib/slack/smart-bot/utils/get_routines.rb +22 -2
  97. data/lib/slack/smart-bot/utils/get_teams.rb +22 -0
  98. data/lib/slack/smart-bot/utils/get_vacations.rb +22 -0
  99. data/lib/slack/smart-bot/utils/has_access.rb +25 -9
  100. data/lib/slack/smart-bot/utils/is_admin.rb +27 -0
  101. data/lib/slack/smart-bot/utils/save_stats.rb +52 -42
  102. data/lib/slack/smart-bot/utils/save_status.rb +22 -7
  103. data/lib/slack/smart-bot/utils/update_access_channels.rb +8 -0
  104. data/lib/slack/smart-bot/utils/update_admins_channels.rb +25 -0
  105. data/lib/slack/smart-bot/utils/update_bots_file.rb +28 -7
  106. data/lib/slack/smart-bot/utils/update_repls.rb +7 -4
  107. data/lib/slack/smart-bot/utils/update_routines.rb +9 -3
  108. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +13 -6
  109. data/lib/slack/smart-bot/utils/update_teams.rb +16 -0
  110. data/lib/slack/smart-bot/utils/update_vacations.rb +16 -0
  111. data/lib/slack/smart-bot/utils.rb +11 -0
  112. data/lib/slack-smart-bot.rb +50 -12
  113. data/lib/slack-smart-bot_general_commands.rb +16 -1
  114. data/whats_new.txt +12 -30
  115. metadata +78 -21
  116. data/lib/slack/smart-bot/commands/general/bot_stats.rb +0 -314
@@ -9,15 +9,16 @@ class SlackSmartBot
9
9
  # helpadmin: Examples:
10
10
  # helpadmin: _run routine example_
11
11
  # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
12
+ # helpadmin: command_id: :run_routine
12
13
  # helpadmin:
13
14
 
14
15
  def run_routine(dest, from, name)
15
16
  save_stats(__method__)
16
- if config.admins.include?(from) #admin user
17
+ if is_admin?
17
18
  if !config.on_master_bot and dest[0] == "D"
18
19
  respond "It's only possible to run routines from MASTER channel from a direct message with the bot.", dest
19
20
  elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
20
- File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.exists?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
21
+ File.delete "#{config.path}/routines/#{@channel_id}/#{name}_output.txt" if File.exist?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
21
22
  if @routines[@channel_id][name][:file_path] != ""
22
23
  if @routines[@channel_id][name][:file_path].match?(/\.rb$/i)
23
24
  ruby = "ruby "
@@ -10,10 +10,11 @@ class SlackSmartBot
10
10
  # helpadmin: Examples:
11
11
  # helpadmin: _see routine result example_
12
12
  # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
13
+ # helpadmin: command_id: :see_result_routine
13
14
  # helpadmin:
14
15
  def see_result_routine(dest, from, name)
15
16
  save_stats(__method__)
16
- if config.admins.include?(from) #admin user
17
+ if is_admin?
17
18
  if @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
18
19
  if File.exist?("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")
19
20
  msg = "*Results from routine run #{File.mtime("#{config.path}/routines/#{@channel_id}/#{name}_output.txt")}*\n"
@@ -6,29 +6,30 @@ class SlackSmartBot
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
8
  # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
9
+ # helpadmin: command_id: :see_routines
9
10
  # helpadmin:
10
11
  def see_routines(dest, from, user, all)
11
12
  save_stats(__method__)
12
- if config.admins.include?(from) #admin user
13
+ if is_admin?
13
14
  if all
14
15
  routines = {}
15
16
  if config.on_master_bot
16
- Dir["#{config.path}/routines/routines_*.rb"].each do |rout|
17
- file_conf = IO.readlines(rout).join
18
- unless file_conf.to_s() == ""
19
- 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)
20
21
  end
21
22
  end
22
23
  else
23
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
24
- routines = @routines.dup
25
+ routines = @routines
25
26
  end
26
27
  else
27
28
  if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name) and dest[0] == "D"
28
- file_conf = IO.readlines("#{config.path}/routines/routines_#{@rules_imported[user.name][user.name]}.rb").join
29
- routines = eval(file_conf)
29
+ routines = YAML.load(File.read("#{config.path}/routines/routines_#{@rules_imported[user.name][user.name]}.yaml"))
30
+ routines = {} if routines.is_a?(FalseClass)
30
31
  else
31
- routines = @routines.dup
32
+ routines = @routines
32
33
  end
33
34
  end
34
35
 
@@ -6,10 +6,11 @@ class SlackSmartBot
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
8
  # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
9
+ # helpadmin: command_id: :start_bot
9
10
  # helpadmin:
10
11
  def start_bot(dest, from)
11
12
  save_stats(__method__)
12
- if config.admins.include?(from) #admin user
13
+ if is_admin?
13
14
  respond "This bot is running and listening from now on. You can pause again: pause this bot", dest
14
15
  @status = :on
15
16
  unless config.on_master_bot
@@ -8,11 +8,12 @@ class SlackSmartBot
8
8
  # helpadmin: Examples:
9
9
  # helpadmin: _start routine example_
10
10
  # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#routines|more info>
11
+ # helpadmin: command_id: :start_routine
11
12
  # helpadmin:
12
13
 
13
14
  def start_routine(dest, from, name)
14
15
  save_stats(__method__)
15
- if config.admins.include?(from) #admin user
16
+ if is_admin?
16
17
  if !config.on_master_bot and dest[0] == "D"
17
18
  respond "It's only possible to start routines from MASTER channel from a direct message with the bot.", dest
18
19
  elsif @routines.key?(@channel_id) and @routines[@channel_id].key?(name)
@@ -4,12 +4,13 @@ class SlackSmartBot
4
4
  # helpadmin: `stop using rules on CHANNEL_NAME`
5
5
  # helpadmin: it will stop using the extended rules on the specified channel.
6
6
  # helpadmin: <https://github.com/MarioRuiz/slack-smart-bot#extending-rules-to-other-channels|more info>
7
+ # helpadmin: command_id: :stop_using_rules_on
7
8
  # helpadmin:
8
9
 
9
10
  def stop_using_rules_on(dest, user, from, channel, typem)
10
11
  save_stats(__method__)
11
12
  unless typem == :on_extended
12
- if !config.admins.include?(from) #not admin
13
+ if !is_admin?
13
14
  respond "Only admins can extend or stop using the rules. Admins on this channel: #{config.admins}", dest
14
15
  else
15
16
  get_bots_created()
@@ -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__)
@@ -2,12 +2,14 @@ class SlackSmartBot
2
2
 
3
3
  # helpadmin: ----------------------------------------------
4
4
  # helpadmin: `react to #CHANNEL_NAME THREAD_ID EMOJIS`
5
+ # helpadmin: `react to URL EMOJIS`
5
6
  # helpadmin: It will send the specified reactions as SmartBot
6
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
7
8
  # helpadmin: Examples:
8
9
  # helpadmin: _react to #sales 1622550707.012100 :thumbsup:_
9
10
  # helpadmin: _react to #sales p1622550707012100 :thumbsup:_
10
11
  # helpadmin: _react to #sales p1622550707012100 :thumbsup: :heavy_check_mark: :bathtub:_
12
+ # helpadmin: command_id: :react_to
11
13
  # helpadmin:
12
14
  def react_to(dest, from, typem, to, thread_ts, emojis)
13
15
  save_stats(__method__)
@@ -25,7 +27,7 @@ class SlackSmartBot
25
27
  react :x
26
28
  end
27
29
  else
28
- respond "Only master admin users on a `pr`ivate conversation with the SmartBot can send reactions as SmartBot.", dest
30
+ respond "Only master admin users on a private conversation with the SmartBot can send reactions as SmartBot.", dest
29
31
  end
30
32
  end
31
33
  end
@@ -3,14 +3,27 @@ class SlackSmartBot
3
3
  # helpadmin: ----------------------------------------------
4
4
  # helpadmin: `send message to @USER_NAME : MESSAGE`
5
5
  # helpadmin: `send message to #CHANNEL_NAME : MESSAGE`
6
- # helpadmin: `send message to #CHANNEL_NAME THREAD_ID : 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`
7
10
  # helpadmin: It will send the specified message as SmartBot
8
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
9
13
  # helpadmin:
10
14
  def send_message(dest, from, typem, to, thread_ts, message)
11
15
  save_stats(__method__)
12
16
  if config.masters.include?(from) and typem==:on_dm #master admin user
13
- succ = (respond message, to, thread_ts: thread_ts, web_client: true)
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
14
27
  if succ
15
28
  react :heavy_check_mark
16
29
  else
@@ -6,6 +6,7 @@ class SlackSmartBot
6
6
  # help: Will delete the specified REPL
7
7
  # help: Only the creator of the REPL or an admin can delete REPLs
8
8
  # help: <https://github.com/MarioRuiz/slack-smart-bot#repl|more info>
9
+ # help: command_id: :delete_repl
9
10
  # help:
10
11
  def delete_repl(dest, user, session_name)
11
12
  #todo: add tests
@@ -13,7 +14,7 @@ class SlackSmartBot
13
14
  if has_access?(__method__, user)
14
15
  if @repls.key?(session_name)
15
16
  Dir.mkdir("#{config.path}/repl") unless Dir.exist?("#{config.path}/repl")
16
- 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
17
18
  @repls.delete(session_name)
18
19
  update_repls()
19
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")
@@ -6,6 +6,7 @@ class SlackSmartBot
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
8
  # help: <https://github.com/MarioRuiz/slack-smart-bot#shortcuts|more info>
9
+ # help: command_id: :delete_shortcut
9
10
  # help:
10
11
 
11
12
  def delete_shortcut(dest, user, shortcut, typem, command, global)
@@ -19,11 +20,11 @@ class SlackSmartBot
19
20
  if !config.on_master_bot or typem != :on_master
20
21
  respond "It is only possible to delete global shortcuts from Master channel"
21
22
  else
22
- if !config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut) and
23
+ if !is_admin?(from) and @shortcuts_global[:all].include?(shortcut) and
23
24
  (!@shortcuts_global.key?(from) or !@shortcuts_global[from].include?(shortcut))
24
25
  respond "Only the creator of the shortcut or an admin user can delete it"
25
26
  elsif (@shortcuts_global.key?(from) and @shortcuts_global[from].keys.include?(shortcut)) or
26
- (config.admins.include?(from) and @shortcuts_global[:all].include?(shortcut))
27
+ (is_admin?(from) and @shortcuts_global[:all].include?(shortcut))
27
28
 
28
29
  respond "global shortcut deleted!", dest
29
30
  if @shortcuts_global.key?(from) and @shortcuts_global[from].key?(shortcut)
@@ -39,11 +40,11 @@ class SlackSmartBot
39
40
  end
40
41
  end
41
42
  else
42
- if !config.admins.include?(from) and @shortcuts[:all].include?(shortcut) and
43
+ if !is_admin?(from) and @shortcuts[:all].include?(shortcut) and
43
44
  (!@shortcuts.key?(from) or !@shortcuts[from].include?(shortcut))
44
45
  respond "Only the creator of the shortcut or an admin user can delete it", dest
45
46
  elsif (@shortcuts.keys.include?(from) and @shortcuts[from].keys.include?(shortcut)) or
46
- (config.admins.include?(from) and @shortcuts[:all].include?(shortcut))
47
+ (is_admin?(from) and @shortcuts[:all].include?(shortcut))
47
48
  #are you sure? to avoid deleting by mistake
48
49
  if answer.empty?
49
50
  ask("are you sure you want to delete it?", command, from, dest)