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
@@ -0,0 +1,33 @@
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: command_id: :publish_announcements
10
+ # helpmaster:
11
+ def publish_announcements(user)
12
+ save_stats(__method__)
13
+ if config.on_master_bot
14
+ if config.masters.include?(user.name) #admin user
15
+ channels = Dir.entries("#{config.path}/announcements/")
16
+ channels.select! {|i| i[/\.csv$/]}
17
+ channels.each do |channel|
18
+ channel.gsub!('.csv','')
19
+ unless channel[0]== 'D'
20
+ see_announcements(user, '', channel, false, true)
21
+ sleep 0.5 # to avoid reach ratelimit
22
+ end
23
+ end
24
+ react :heavy_check_mark
25
+
26
+ else
27
+ respond 'Only master admins on master channel can use this command.'
28
+ end
29
+ else
30
+ respond 'Only master admins on master channel can use this command.'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
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: command_id: :set_general_message
15
+ # helpmaster:
16
+ def set_general_message(from, status, message)
17
+ save_stats(__method__)
18
+ if config.on_master_bot
19
+ if config.masters.include?(from) #admin user
20
+ if status == 'on'
21
+ config.general_message = message
22
+ respond "General message has been set."
23
+ else
24
+ config.general_message = ''
25
+ respond "General message won't be displayed anymore."
26
+ end
27
+
28
+ file = File.open("#{config.path}/config_tmp.status", "w")
29
+ file.write config.inspect
30
+ file.close
31
+
32
+ else
33
+ respond 'Only master admins on master channel can use this command.'
34
+ end
35
+ else
36
+ respond 'Only master admins on master channel can use this command.'
37
+ end
38
+ end
39
+ end
@@ -8,11 +8,18 @@ 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>
17
+ # helpmaster: command_id: :set_maintenance
11
18
  # helpmaster:
12
19
  def set_maintenance(from, status, message)
13
20
  save_stats(__method__)
14
21
  if config.on_master_bot
15
- if config.admins.include?(from) #admin user
22
+ if config.masters.include?(from) #admin user
16
23
  if message == ''
17
24
  config.on_maintenance_message = "Sorry I'm on maintenance so I cannot attend your request."
18
25
  else
@@ -22,9 +29,11 @@ class SlackSmartBot
22
29
  if status == 'on'
23
30
  config.on_maintenance = true
24
31
  respond "From now on I'll be on maintenance status so I won't be responding accordingly."
32
+ save_status :off, :maintenance_on, config.on_maintenance_message
25
33
  else
26
34
  config.on_maintenance = false
27
35
  respond "From now on I won't be on maintenance. Everything is back to normal!"
36
+ save_status :on, :maintenance_off, config.on_maintenance_message
28
37
  end
29
38
 
30
39
  file = File.open("#{config.path}/config_tmp.status", "w")
@@ -2,18 +2,21 @@ 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>
12
+ # helpmaster: command_id: :create_bot
9
13
  # helpmaster:
10
- def create_bot(dest, user, cloud, channel)
14
+ def create_bot(dest, user, type, channel)
15
+ cloud = type.include?('cloud')
16
+ silent = type.include?('silent')
11
17
  save_stats(__method__)
12
18
  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
19
+ if has_access?(__method__, user)
17
20
  if config.on_master_bot
18
21
  get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
19
22
  channel_id = nil
@@ -25,6 +28,7 @@ class SlackSmartBot
25
28
  end
26
29
  #todo: add pagination for case more than 1000 channels on the workspace
27
30
  channels = get_channels()
31
+ channel = @channels_name[channel] if @channels_name.key?(channel)
28
32
  channel_found = channels.detect { |c| c.name == channel }
29
33
  members = get_channel_members(@channels_id[channel]) unless channel_found.nil?
30
34
 
@@ -40,32 +44,40 @@ class SlackSmartBot
40
44
  if channel_id != config[:channel]
41
45
  begin
42
46
  rules_file = "slack-smart-bot_rules_#{channel_id}_#{from.gsub(" ", "_")}.rb"
43
- if defined?(RULES_FOLDER)
47
+ if defined?(RULES_FOLDER) # consider removing RULES_FOLDER since we are not using it anywhere else
44
48
  rules_file = RULES_FOLDER + rules_file
45
49
  general_rules_file = RULES_FOLDER + 'general_rules.rb'
50
+ general_commands_file = RULES_FOLDER + 'general_commands.rb'
46
51
  else
47
52
  Dir.mkdir("#{config.path}/rules") unless Dir.exist?("#{config.path}/rules")
48
53
  Dir.mkdir("#{config.path}/rules/#{channel_id}") unless Dir.exist?("#{config.path}/rules/#{channel_id}")
49
54
  rules_file = "/rules/#{channel_id}/" + rules_file
50
55
  general_rules_file = "/rules/general_rules.rb"
56
+ general_commands_file = "/rules/general_commands.rb"
51
57
  end
52
58
  default_rules = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_rules.rb")
53
59
  default_general_rules = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_general_rules.rb")
60
+ default_general_commands = (__FILE__).gsub(/slack\/smart-bot\/commands\/on_master\/create_bot\.rb$/, "slack-smart-bot_general_commands.rb")
54
61
 
55
62
  File.delete(config.path + rules_file) if File.exist?(config.path + rules_file)
56
63
  FileUtils.copy_file(default_rules, config.path + rules_file) unless File.exist?(config.path + rules_file)
57
64
  FileUtils.copy_file(default_general_rules, config.path + general_rules_file) unless File.exist?(config.path + general_rules_file)
65
+ FileUtils.copy_file(default_general_commands, config.path + general_commands_file) unless File.exist?(config.path + general_commands_file)
58
66
  admin_users = Array.new()
59
- creator_info = get_user_info(channel_found.creator)
60
- admin_users = [from, creator_info.user.name] + config.masters
67
+ creator_info = @users.select{|u| u.id == channel_found.creator or (u.key?(:enterprise_user) and u.enterprise_user.id == channel_found.creator)}[-1]
68
+ if creator_info.nil? or creator_info.empty? or creator_info.user.nil?
69
+ admin_users = [from] + config.masters
70
+ else
71
+ admin_users = [from, creator_info.user.name] + config.masters
72
+ end
61
73
  admin_users.uniq!
62
- @logger.info "ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on"
74
+ @logger.info "BOT_SILENT=#{silent} ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on"
63
75
 
64
76
  if cloud
65
77
  respond "Copy the bot folder to your cloud location and run `ruby #{config.file} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on&`", dest
66
78
  else
67
79
  t = Thread.new do
68
- `BOT_SILENT=false ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on`
80
+ `BOT_SILENT=#{silent} ruby #{config.file_path} \"#{channel}\" \"#{admin_users.join(",")}\" \"#{rules_file}\" on`
69
81
  end
70
82
  end
71
83
  @bots_created[channel_id] = {
@@ -80,6 +92,8 @@ class SlackSmartBot
80
92
  cloud: cloud,
81
93
  thread: t,
82
94
  }
95
+ @bots_created[channel_id].silent = true if silent
96
+
83
97
  respond "The bot has been created on channel: #{channel}. Rules file: #{File.basename rules_file}. Admins: #{admin_users.join(", ")}", dest
84
98
  update_bots_file()
85
99
  rescue Exception => stack
@@ -0,0 +1,41 @@
1
+ class SlackSmartBot
2
+ # helpmaster: ----------------------------------------------
3
+ # helpmaster: `where is smartbot?`
4
+ # helpmaster: `which channels smartbot?`
5
+ # helpmaster: `where is a member smartbot?`
6
+ # helpmaster: It will list all channels where the smartbot is a member.
7
+ # helpmaster: command_id: :where_smartbot
8
+ # helpmaster:
9
+ def where_smartbot(user)
10
+ #todo: add tests
11
+ save_stats(__method__)
12
+ if has_access?(__method__, user)
13
+ channels = get_channels(bot_is_in: true)
14
+ message = []
15
+ extended = @bots_created.values.extended.flatten
16
+ channels.each do |c|
17
+ type = ''
18
+ unless c.id[0] == "D"
19
+ if @bots_created.key?(c.id)
20
+ type = '_`(SmartBot)`_'
21
+ elsif c.id == @master_bot_id
22
+ type = '_`(Master)`_'
23
+ elsif extended.include?(c.name)
24
+ @bots_created.each do |bot,values|
25
+ if values.extended.include?(c.name)
26
+ type += "_`(Extended from ##{values.channel_name})`_ "
27
+ end
28
+ end
29
+ end
30
+ if c.is_private?
31
+ message << "#{c.id}: *##{c.name}* #{type}"
32
+ else
33
+ message << "#{c.id}: *<##{c.id}>* #{type}"
34
+ end
35
+ end
36
+ end
37
+ message.sort!
38
+ respond "*<@#{config.nick_id}> is a member of:*\n\n#{message.join("\n")}"
39
+ end
40
+ end
41
+ end
@@ -1,34 +1,65 @@
1
- require_relative "commands/general/whats_new"
2
1
  require_relative "commands/general/hi_bot"
3
2
  require_relative "commands/general/bye_bot"
4
3
  require_relative "commands/general/bot_help"
4
+ require_relative "commands/on_bot/general/suggest_command"
5
5
  require_relative "commands/on_bot/ruby_code"
6
6
  require_relative "commands/on_bot/repl"
7
7
  require_relative "commands/on_bot/get_repl"
8
8
  require_relative "commands/on_bot/run_repl"
9
9
  require_relative "commands/on_bot/delete_repl"
10
10
  require_relative "commands/on_bot/see_repls"
11
- require_relative "commands/general/use_rules"
12
- require_relative "commands/general/stop_using_rules"
11
+ require_relative "commands/on_bot/general/whats_new"
12
+ require_relative "commands/on_bot/general/use_rules"
13
+ require_relative "commands/on_bot/general/stop_using_rules"
13
14
  require_relative "commands/on_master/admin_master/exit_bot"
14
15
  require_relative "commands/on_master/admin_master/notify_message"
15
16
  require_relative "commands/on_master/admin/kill_bot_on_channel"
16
17
  require_relative "commands/on_master/create_bot"
18
+ require_relative "commands/on_master/where_smartbot"
17
19
  require_relative "commands/on_bot/admin/add_routine"
18
20
  require_relative "commands/on_bot/admin/start_bot"
19
21
  require_relative "commands/on_bot/admin/pause_bot"
20
22
  require_relative "commands/on_bot/admin/remove_routine"
23
+ require_relative "commands/on_bot/admin/see_result_routine"
21
24
  require_relative "commands/on_bot/admin/run_routine"
22
25
  require_relative "commands/on_bot/admin/pause_routine"
23
26
  require_relative "commands/on_bot/admin/start_routine"
24
27
  require_relative "commands/on_bot/admin/see_routines"
25
28
  require_relative "commands/on_bot/admin/extend_rules"
26
29
  require_relative "commands/on_bot/admin/stop_using_rules_on"
27
- require_relative "commands/general/bot_status"
30
+ require_relative "commands/on_bot/general/bot_status"
28
31
  require_relative "commands/on_bot/add_shortcut"
29
32
  require_relative "commands/on_bot/delete_shortcut"
30
33
  require_relative "commands/on_bot/see_shortcuts"
31
34
  require_relative "commands/on_extended/bot_rules"
32
35
  require_relative "commands/on_bot/admin_master/get_bot_logs"
33
- require_relative "commands/general/bot_stats"
36
+ require_relative "commands/on_bot/admin_master/send_message"
37
+ require_relative "commands/on_bot/admin_master/delete_message"
38
+ require_relative "commands/on_bot/admin_master/react_to"
39
+ require_relative "commands/on_bot/general/bot_stats"
40
+ require_relative "commands/on_bot/general/leaderboard"
41
+ require_relative "commands/general/add_announcement"
42
+ require_relative "commands/general/delete_announcement"
43
+ require_relative "commands/general/see_announcements"
44
+ require_relative "commands/general/see_statuses"
45
+ require_relative "commands/general/see_favorite_commands"
46
+ require_relative "commands/on_master/admin_master/publish_announcements"
34
47
  require_relative "commands/on_master/admin_master/set_maintenance"
48
+ require_relative "commands/on_master/admin_master/set_general_message"
49
+ require_relative "commands/general_bot_commands"
50
+ require_relative "commands/general/share_messages"
51
+ require_relative "commands/general/see_shares"
52
+ require_relative "commands/general/delete_share"
53
+ require_relative "commands/general/see_admins"
54
+ require_relative "commands/general/add_admin"
55
+ require_relative "commands/general/remove_admin"
56
+ require_relative "commands/general/see_command_ids"
57
+ require_relative "commands/general/poster"
58
+ require_relative "commands/general/see_access"
59
+ require_relative "commands/general/allow_access"
60
+ require_relative "commands/general/deny_access"
61
+ require_relative "commands/general/add_team"
62
+ require_relative "commands/general/see_teams"
63
+ require_relative "commands/general/update_team"
64
+ require_relative "commands/general/ping_team"
65
+ require_relative "commands/general/delete_team"
@@ -1,44 +1,42 @@
1
1
  class SlackSmartBot
2
2
  def listen_simulate
3
- @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart"]
3
+ @salutations = [config[:nick], "<@#{config[:nick_id]}>", "bot", "smart", "smartbot", "smart-bot", "smart bot"]
4
4
  @pings = []
5
5
  @last_activity_check = Time.now
6
6
  get_bots_created()
7
- @buffer_complete = [] unless defined?(@buffer_complete)
8
- b = File.read("#{config.path}/buffer_complete.log")
9
- result = b.scan(/^\|(\w+)\|(\w+)\|(\w+)\|([^~]+)~~~/m)
10
- result.delete(nil)
11
- new_messages = result[@buffer_complete.size..-1]
12
- unless new_messages.nil? or new_messages.empty?
13
- @buffer_complete = result
14
- new_messages.each do |message|
15
- channel = message[0].strip
16
- user = message[1].strip
17
- user_name = message[2].strip
18
- command = message[3].to_s.strip
19
- # take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
20
- @logger.info "treat message: #{message}" if config.testing
21
-
22
-
23
- if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
24
- command.scan(/`([^`]+)`/).flatten.each do |cmd|
25
- if cmd.to_s!=''
26
- cmd = "^#{cmd}"
27
- treat_message({channel: channel, user: user, text: cmd, user_name: user_name}, false)
28
- end
7
+ @buffer_complete = [] unless defined?(@buffer_complete)
8
+ b = File.read("#{config.path}/buffer_complete.log")
9
+ result = b.scan(/^\|(\w+)\|(\w+)\|(\w+)\|([^~]+)~~~/m)
10
+ result.delete(nil)
11
+ new_messages = result[@buffer_complete.size..-1]
12
+ unless new_messages.nil? or new_messages.empty?
13
+ @buffer_complete = result
14
+ new_messages.each do |message|
15
+ channel = message[0].strip
16
+ user = message[1].strip
17
+ user_name = message[2].strip
18
+ command = message[3].to_s.strip
19
+ # take in consideration that on simulation we are treating all messages even those that are not populated on real cases like when the message is not populated to the specific bot connection when message is sent with the bot
20
+ @logger.info "treat message: #{message}" if config.testing
21
+ if command.match?(/^\s*\-!!/) or command.match?(/^\s*\-\^/)
22
+ command.scan(/`([^`]+)`/).flatten.each do |cmd|
23
+ if cmd.to_s != ""
24
+ cmd = "^#{cmd}"
25
+ treat_message({ channel: channel, user: user, text: cmd, user_name: user_name }, false)
29
26
  end
30
- elsif command.match?(/^\s*\-!/)
31
- command.scan(/`([^`]+)`/).flatten.each do |cmd|
32
- if cmd.to_s!=''
33
- cmd = "!#{cmd}"
34
- treat_message({channel: channel, user: user, text: cmd, user_name: user_name}, false)
35
- end
27
+ end
28
+ elsif command.match?(/^\s*\-!/)
29
+ command.scan(/`([^`]+)`/).flatten.each do |cmd|
30
+ if cmd.to_s != ""
31
+ cmd = "!#{cmd}"
32
+ treat_message({ channel: channel, user: user, text: cmd, user_name: user_name }, false)
36
33
  end
37
- else
38
- treat_message({channel: channel, user: user, text: command, user_name: user_name})
39
34
  end
35
+ else
36
+ treat_message({ channel: channel, user: user, text: command, user_name: user_name })
40
37
  end
41
38
  end
39
+ end
42
40
  end
43
41
 
44
42
  def listen
@@ -50,7 +48,7 @@ class SlackSmartBot
50
48
  unless data.user == "USLACKBOT" or data.text.nil?
51
49
  if data.text.match?(/^\s*\-!!/) or data.text.match?(/^\s*\-\^/)
52
50
  data.text.scan(/`([^`]+)`/).flatten.each do |cmd|
53
- if cmd.to_s!=''
51
+ if cmd.to_s != ""
54
52
  datao = data.dup
55
53
  datao.text = "^#{cmd}"
56
54
  treat_message(datao, false)
@@ -58,7 +56,7 @@ class SlackSmartBot
58
56
  end
59
57
  elsif data.text.match?(/^\s*\-!/)
60
58
  data.text.scan(/`([^`]+)`/).flatten.each do |cmd|
61
- if cmd.to_s!=''
59
+ if cmd.to_s != ""
62
60
  datao = data.dup
63
61
  datao.text = "!#{cmd}"
64
62
  treat_message(datao, false)