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
@@ -0,0 +1,54 @@
1
+ class SlackSmartBot
2
+ def see_favorite_commands(user, only_mine)
3
+ save_stats(__method__)
4
+ if config.stats
5
+ if Thread.current[:typem] == :on_call
6
+ channel = Thread.current[:dchannel]
7
+ elsif Thread.current[:using_channel].to_s==''
8
+ channel = Thread.current[:dest]
9
+ else
10
+ channel = Thread.current[:using_channel]
11
+ end
12
+
13
+ files = Dir["#{config.stats_path}.*.log"].sort.reverse[0..1]
14
+ if files.empty?
15
+ respond "There is no data stored."
16
+ else
17
+ count_commands = {}
18
+ files.each do |file|
19
+ CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
20
+ row[:dest_channel_id] = row[:bot_channel_id] if row[:dest_channel_id].to_s[0] == "D"
21
+
22
+ if ((only_mine and row[:user_name]==user.name) or (!only_mine and !config.admins.include?(row[:user_name]))) and
23
+ row[:dest_channel_id] == channel and !row[:user_name].include?('routine/') and
24
+ row[:command] != 'dont_understand'
25
+
26
+ row[:command] = 'bot_help' if row[:command] == 'bot_rules'
27
+ count_commands[row[:command]] ||= 0
28
+ count_commands[row[:command]] += 1
29
+ end
30
+ end
31
+ end
32
+ commands = []
33
+ count_commands.sort_by {|k,v| -v}.each do |command, num|
34
+ commands << command
35
+ end
36
+ if commands.empty?
37
+ respond "There is no data stored."
38
+ else
39
+ output = ""
40
+ i = 0
41
+ commands.each do |command|
42
+ unless output.match?(/^\s*command_id:\s+:#{command}\s*$/)
43
+ i+=1
44
+ output += bot_help(user, user.name, Thread.current[:dest], channel, false, command.gsub('_',' '), config.rules_file, false)
45
+ break if i>=5
46
+ end
47
+ end
48
+ end
49
+ end
50
+ else
51
+ respond "Ask an admin to set stats to true to generate the stats when running the bot instance so you can get this command to work."
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,41 @@
1
+ class SlackSmartBot
2
+
3
+ def see_shares()
4
+ save_stats(__method__)
5
+ typem = Thread.current[:typem]
6
+ dest = Thread.current[:dest]
7
+ if typem == :on_call
8
+ channel = Thread.current[:dchannel]
9
+ else
10
+ channel = Thread.current[:dest]
11
+ end
12
+
13
+ general_message = "\nRelated commands `share messages /RegExp/ on #CHANNEL`, `share messages \"TEXT\" on #CHANNEL`, `delete share ID`"
14
+ if File.exist?("#{config.path}/shares/#{@channels_name[channel]}.csv")
15
+ t = CSV.table("#{config.path}/shares/#{@channels_name[channel]}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
16
+ message =[]
17
+ t.each do |m|
18
+ if m[:user_deleted] == ''
19
+ if m[:type]=='text'
20
+ emoji = ":abc:"
21
+ elsif m[:type] == 'regexp'
22
+ emoji = ":heavy_plus_sign:"
23
+ else
24
+ emoji = ':white_square:'
25
+ end
26
+ message << "\t#{m[:share_id]} #{emoji} *_#{m[:date]}_* #{m[:time]} *#{m[:user_created]}* <##{@channels_id[m[:to_channel]]}|#{m[:to_channel]}> : \t`#{m[:condition]}`"
27
+ end
28
+ end
29
+ if message.size == 0
30
+ message << "*There are no active shares right now.*"
31
+ else
32
+ message.unshift("*Shares from channel <##{channel}>*")
33
+ end
34
+ message << general_message
35
+ respond message.join("\n"), dest
36
+ else
37
+ respond "*There are no active shares right now.*#{general_message}"
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,78 @@
1
+ class SlackSmartBot
2
+ def see_statuses(user, channel, types, dest, not_on)
3
+ save_stats(__method__)
4
+ react :runner
5
+ if channel == ""
6
+ if dest[0] == "D"
7
+ cdest = @channel_id
8
+ else
9
+ cdest = dest
10
+ end
11
+ else
12
+ get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
13
+ channel_id = nil
14
+ if @channels_name.key?(channel) #it is an id
15
+ channel_id = channel
16
+ channel = @channels_name[channel_id]
17
+ elsif @channels_id.key?(channel) #it is a channel name
18
+ channel_id = @channels_id[channel]
19
+ end
20
+ cdest = channel_id
21
+ end
22
+ members = get_channel_members(cdest)
23
+ if members.include?(user.id)
24
+ list = {}
25
+ members.each do |member|
26
+ info = get_user_info(member)
27
+ text = info.user.profile.status_text
28
+ emoji = info.user.profile.status_emoji
29
+ exp = info.user.profile.expiration
30
+ unless (((!types.empty? and !types.include?(emoji)) or (emoji.to_s == "" and text.to_s == "" and exp.to_s == "")) and !not_on) or
31
+ (not_on and types.include?(emoji)) or info.user.deleted or info.user.is_bot or info.user.is_app_user
32
+ emoji = ":white_square:" if emoji.to_s == ""
33
+ list[emoji] ||= []
34
+ list[emoji] << {
35
+ type: "context",
36
+ elements: [
37
+ {
38
+ type: "plain_text",
39
+ text: "\t\t",
40
+ },
41
+ {
42
+ type: "image",
43
+ image_url: info.user.profile.image_24,
44
+ alt_text: info.user.name,
45
+ },
46
+ {
47
+ type: "mrkdwn",
48
+ text: " *#{info.user.profile.real_name}* (#{info.user.name}) #{text} #{exp}",
49
+ },
50
+ ],
51
+ }
52
+ end
53
+ end
54
+ if list.size > 0
55
+ list.each do |emoji, users|
56
+ blocks = [
57
+ {
58
+ "type": "context",
59
+ elements: [
60
+ {
61
+ type: "mrkdwn",
62
+ text: "*Users* #{emoji} on <##{cdest}>",
63
+ },
64
+ ],
65
+ },
66
+ ]
67
+ users = users.sort_by { |hsh| hsh.elements[2].text }
68
+ respond blocks: (blocks+users)
69
+ end
70
+ else
71
+ respond "Nobody on <##{cdest}> with that status"
72
+ end
73
+ else
74
+ respond "You need to join <##{cdest}> to be able to see the statuses on that channel."
75
+ end
76
+ unreact :runner
77
+ end
78
+ end
@@ -0,0 +1,58 @@
1
+ class SlackSmartBot
2
+ #todo: reaction type not added yet since RTM doesn't support it. See if we can add it as an event
3
+ def share_messages(user, from_channel, to_channel, condition)
4
+ save_stats(__method__)
5
+ if has_access?(__method__, user)
6
+ #todo: add a @shared variable to control not to be shared more than once when using reactions
7
+ #todo: it is only possible to share if smartbot is a member in both channels and the person adding the share command also
8
+ if Thread.current[:typem] == :on_call or Thread.current[:typem] == :on_dm
9
+ respond "You can use this command only from the source channel."
10
+ elsif from_channel == to_channel
11
+ respond "You cannot share messages on the same channel than source channel."
12
+ else
13
+ channels = get_channels(types: 'public_channel')
14
+ channel_found = channels.detect { |c| c.name == from_channel }
15
+ get_channels_name_and_id() unless @channels_id.key?(to_channel)
16
+ channel_found = false if !@channels_id.key?(to_channel)
17
+ if channel_found
18
+ members = get_channel_members(@channels_id[to_channel])
19
+ if members.include?(config.nick_id) and members.include?(user.id)
20
+ if condition.match?(/^\/.+\/$/)
21
+ type = :regexp
22
+ elsif condition.match?(/^".+"$/) or condition.match?(/^'.+'$/)
23
+ type = :text
24
+ else
25
+ type = :reaction
26
+ end
27
+ if File.exists?("#{config.path}/shares/#{from_channel}.csv")
28
+ t = CSV.table("#{config.path}/shares/#{from_channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
29
+ @shares[from_channel] = t
30
+ if t.size>0
31
+ num = t[:share_id].max + 1
32
+ else
33
+ num = 1
34
+ end
35
+ elsif !@shares.key?(from_channel)
36
+ File.open("#{config.path}/shares/#{from_channel}.csv","w")
37
+ t = CSV.table("#{config.path}/shares/#{from_channel}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
38
+ num = 1
39
+ @shares[from_channel] = t
40
+ else
41
+ num = @shares[from_channel][:share_id].max + 1
42
+ end
43
+ values = [num, '', user.name, Time.now.strftime("%Y/%m/%d"), Time.now.strftime("%H:%M"), type.to_s, to_channel, condition]
44
+ @shares[from_channel] << values
45
+ CSV.open("#{config.path}/shares/#{from_channel}.csv", "a+") do |csv|
46
+ csv << values
47
+ end
48
+ respond "*Share command*: id:#{num} Messages #{condition} will be shared from now on. Related commands `see shares`, `delete share ID`"
49
+ else
50
+ respond "*Share command*: The channel ##{to_channel} need to exist and the SmartBot and you have to be members."
51
+ end
52
+ else
53
+ respond "*Share command*: The channel <##{@channels_id[from_channel]}|#{from_channel}> has to be a public channel and the destination channel has to be a valid channel."
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,10 +1,13 @@
1
1
  class SlackSmartBot
2
2
  # help: ----------------------------------------------
3
3
  # help: `stop using rules from CHANNEL`
4
+ # help: `stop using CHANNEL`
4
5
  # help: it will stop using the rules from the specified channel.
6
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#using-rules-from-other-channels|more info>
5
7
  # help:
6
8
  def stop_using_rules(dest, channel, user, dchannel)
7
9
  save_stats(__method__)
10
+ channel.gsub!('#','') # for the case the channel name is in plain text including #
8
11
  if @channels_id.key?(channel)
9
12
  channel_id = @channels_id[channel]
10
13
  else
@@ -12,11 +15,12 @@ class SlackSmartBot
12
15
  end
13
16
 
14
17
  if dest[0] == "C" or dest[0] == "G" #channel
15
- if @rules_imported.key?(user.id) and @rules_imported[user.id].key?(dchannel)
16
- if @rules_imported[user.id][dchannel] != channel_id
18
+ if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(dchannel)
19
+ if @rules_imported[user.name][dchannel] != channel_id
17
20
  respond "You are not using those rules.", dest
18
21
  else
19
- @rules_imported[user.id].delete(dchannel)
22
+ @rules_imported[user.name].delete(dchannel)
23
+ sleep 0.5
20
24
  update_rules_imported()
21
25
  respond "You won't be using those rules from now on.", dest
22
26
 
@@ -27,11 +31,12 @@ class SlackSmartBot
27
31
  respond "You were not using those rules.", dest
28
32
  end
29
33
  else #direct message
30
- if @rules_imported.key?(user.id) and @rules_imported[user.id].key?(user.id)
31
- if @rules_imported[user.id][user.id] != channel_id
34
+ if @rules_imported.key?(user.name) and @rules_imported[user.name].key?(user.name)
35
+ if @rules_imported[user.name][user.name] != channel_id
32
36
  respond "You are not using those rules.", dest
33
37
  else
34
- @rules_imported[user.id].delete(user.id)
38
+ @rules_imported[user.name].delete(user.name)
39
+ sleep 0.5
35
40
  update_rules_imported()
36
41
  respond "You won't be using those rules from now on.", dest
37
42
 
@@ -0,0 +1,30 @@
1
+ class SlackSmartBot
2
+
3
+ # help: ----------------------------------------------
4
+ # help: `suggest command`
5
+ # help: `random command`
6
+ # help: `command suggestion`
7
+ # help: `suggest rule`
8
+ # help: `random rule`
9
+ # help: `rule suggestion`
10
+ # help: it will display the help content for a random command.
11
+ # help: if used 'rule' then it will display a random rule.
12
+ # help: if used 'command' it will show any kind of command or rule.
13
+ # help:
14
+ def suggest_command(from, dest, dchannel, specific, rules_file)
15
+ save_stats(__method__)
16
+ help_message = get_help(rules_file, dest, from, specific, true, descriptions: false, only_normal_user: true)
17
+ commands = help_message.gsub(/====+/,'-'*30).split(/^\s*-------*$/).flatten
18
+ commands.reject!{|c| c.match?(/These are specific commands for this bot on this/i) || c.match?(/\A\s*\z/)}
19
+ @last_suggested_commands ||= []
20
+ @last_suggested_commands.shift if @last_suggested_commands.size >=5
21
+ command = ''
22
+ begin
23
+ command = commands.sample
24
+ end until !@last_suggested_commands.include?(command) or commands.size <= 5
25
+ @last_suggested_commands << command
26
+ message = "*Command suggestion*:\n#{command}"
27
+ respond message, dest, unfurl_links: false, unfurl_media: false
28
+ end
29
+
30
+ end
@@ -6,17 +6,16 @@ class SlackSmartBot
6
6
  # help: `use CHANNEL`
7
7
  # help: it will use the rules from the specified channel.
8
8
  # help: you need to be part of that channel to be able to use the rules.
9
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#using-rules-from-other-channels|more info>
9
10
  # help:
10
11
  def use_rules(dest, channel, user, dchannel)
11
12
  save_stats(__method__)
12
13
  get_bots_created()
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
14
+ if has_access?(__method__, user)
17
15
  #todo: add pagination for case more than 1000 channels on the workspace
18
16
  channels = get_channels()
19
17
  channel.gsub!('#','') # for the case the channel name is in plain text including #
18
+ channel = @channels_name[channel] if @channels_name.key?(channel)
20
19
  channel_found = channels.detect { |c| c.name == channel }
21
20
  get_channels_name_and_id() unless @channels_id.key?(channel)
22
21
  members = get_channel_members(@channels_id[channel]) unless channel_found.nil? or !@channels_id.key?(channel)
@@ -31,12 +30,13 @@ class SlackSmartBot
31
30
  respond "The bot in that channel is not :on", dest
32
31
  else
33
32
  if user.id == channel_found.creator or members.include?(user.id)
34
- @rules_imported[user.id] = {} unless @rules_imported.key?(user.id)
33
+ @rules_imported[user.name] = {} unless @rules_imported.key?(user.name)
35
34
  if dest[0] == "C" or dest[0] == "G" #todo: take in consideration bots that are not master
36
- @rules_imported[user.id][dchannel] = channel_found.id
35
+ @rules_imported[user.name][dchannel] = channel_found.id
37
36
  else
38
- @rules_imported[user.id][user.id] = channel_found.id
37
+ @rules_imported[user.name][user.name] = channel_found.id
39
38
  end
39
+ sleep 0.5
40
40
  update_rules_imported()
41
41
  respond "I'm using now the rules from <##{channel_found.id}>", dest
42
42
 
@@ -0,0 +1,243 @@
1
+ # add here the general commands you will be using in any channel where The SmartBot is part of. Not necessary to use ! or ^, it will answer directly.
2
+ def general_bot_commands(user, command, dest, files = [])
3
+
4
+ begin
5
+ if config.simulate
6
+ display_name = user.profile.display_name
7
+ else
8
+ if user.profile.display_name.to_s.match?(/\A\s*\z/)
9
+ user.profile.display_name = user.profile.real_name
10
+ end
11
+ display_name = user.profile.display_name
12
+ end
13
+
14
+ case command
15
+
16
+
17
+ # help: ----------------------------------------------
18
+ # help: `bot help`
19
+ # help: `bot help COMMAND`
20
+ # help: `bot rules`
21
+ # help: `bot rules COMMAND`
22
+ # help: `bot help expanded`
23
+ # help: `bot rules expanded`
24
+ # help: `bot what can I do?`
25
+ # help: it will display this help. For a more detailed help call `bot help expanded` or `bot rules expanded`.
26
+ # help: if COMMAND supplied just help for that command
27
+ # help: you can use the option 'expanded' or the alias 'extended'
28
+ # help: `bot rules` will show only the specific rules for this channel.
29
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#bot-help|more info>
30
+ # help:
31
+
32
+
33
+ # help: ----------------------------------------------
34
+ # help: `Hi Bot`
35
+ # help: `Hi Smart`
36
+ # help: `Hello Bot` `Hola Bot` `Hallo Bot` `What's up Bot` `Hey Bot` `Hæ Bot`
37
+ # help: `Hello THE_NAME_OF_THE_BOT`
38
+ # help: Bot starts listening to you if you are on a Bot channel
39
+ # help: After that if you want to avoid a single message to be treated by the smart bot, start the message by -
40
+ # help: Also apart of Hello you can use _Hallo, Hi, Hola, What's up, Hey, Hæ_
41
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#how-to-access-the-smart-bot|more info>
42
+ # help:
43
+ when /\A\s*(Hello|Hallo|Hi|Hola|What's\sup|Hey|Hæ)\s+(#{@salutations.join("|")})\s*$/i
44
+ hi_bot(user, dest, user.name, display_name)
45
+
46
+ # help: ----------------------------------------------
47
+ # help: `Bye Bot`
48
+ # help: `Bye Smart`
49
+ # help: `Bye NAME_OF_THE_BOT`
50
+ # help: Bot stops listening to you if you are on a Bot channel
51
+ # help: Also apart of Bye you can use _Bæ, Good Bye, Adiós, Ciao, Bless, Bless Bless, Adeu_
52
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#how-to-access-the-smart-bot|more info>
53
+ # help:
54
+ when /\A\s*(Bye|Bæ|Good\s+Bye|Adiós|Ciao|Bless|Bless\sBless|Adeu)\s+(#{@salutations.join("|")})\s*$/i
55
+ bye_bot(dest, user.name, display_name)
56
+
57
+ # help: ----------------------------------------------
58
+ # help: `add announcement MESSAGE`
59
+ # help: `add red announcement MESSAGE`
60
+ # help: `add green announcement MESSAGE`
61
+ # help: `add yellow announcement MESSAGE`
62
+ # help: `add white announcement MESSAGE`
63
+ # help: `add EMOJI announcement MESSAGE`
64
+ # help: It will store the message on the announcement list labeled with the color or emoji specified, white by default.
65
+ # help: aliases for announcement: statement, declaration, message
66
+ # help: Examples:
67
+ # help: _add green announcement :heavy_check_mark: All customer services are up and running_
68
+ # help: _add red declaration Customers db is down :x:_
69
+ # help: _add yellow statement Don't access the linux server without VPN_
70
+ # help: _add message `*Party* will start at *20:00* :tada:`_
71
+ # help: _add :heavy_exclamation_mark: message Pay attention all DB are on maintenance until 20:00 GMT_
72
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
73
+ # help:
74
+ when /\A\s*(add|create)\s+(red\s+|green\s+|white\s+|yellow\s+)?(announcement|statement|declaration|message)\s+(.+)\s*\z/i,
75
+ /\A\s*(add|create)\s+(:\w+:)\s+(announcement|statement|declaration|message)\s+(.+)\s*\z/i
76
+ type = $2.to_s.downcase.strip
77
+ type = 'white' if type == ''
78
+ message = $4
79
+ add_announcement(user, type, message)
80
+
81
+
82
+ # help: ----------------------------------------------
83
+ # help: `delete announcement ID`
84
+ # help: It will delete the message on the announcement list.
85
+ # help: aliases for announcement: statement, declaration, message
86
+ # help: Examples:
87
+ # help: _delete announcement 24_
88
+ # help: _delete message 645_
89
+ # help: _delete statement 77_
90
+ # help: _delete declaration 334_
91
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
92
+ # help:
93
+ when /\A\s*(delete|remove)\s+(announcement|statement|declaration|message)\s+(\d+)\s*\z/i
94
+ message_id = $3
95
+ delete_announcement(user, message_id)
96
+
97
+ # help: ----------------------------------------------
98
+ # help: `see announcements`
99
+ # help: `see red announcements`
100
+ # help: `see green announcements`
101
+ # help: `see yellow announcements`
102
+ # help: `see white announcements`
103
+ # help: `see EMOJI announcements`
104
+ # helpmaster: `see announcements #CHANNEL`
105
+ # helpmaster: `see all announcements`
106
+ # help: It will display the announcements for the channel.
107
+ # help: aliases for announcements: statements, declarations, messages
108
+ # helpmaster: In case #CHANNEL it will display the announcements for that channel. Only master admins can use it from a DM with the Smartbot.
109
+ # helpmaster: In case 'all' it will display all the announcements for all channels. Only master admins can use it from a DM with the Smartbot.
110
+ # help: Examples:
111
+ # help: _see announcements_
112
+ # help: _see white messages_
113
+ # help: _see red statements_
114
+ # help: _see yellow declarations_
115
+ # help: _see messages_
116
+ # help: _see :heavy_exclamation_mark: messages_
117
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#announcements|more info>
118
+ # help:
119
+ when /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)()\s*\z/i,
120
+ /\A\s*see\s+(all\s+)?(announcements|statements|declarations|messages)()\s*\z/i,
121
+ /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)\s+#([\w\-]+)\s*\z/i,
122
+ /\A\s*see\s+(red\s+|green\s+|white\s+|yellow\s+|:\w+:\s+)?(announcements|statements|declarations|messages)\s+<#(C\w+)\|.*>\s*\z/i
123
+
124
+ type = $1.to_s.downcase.strip
125
+ channel = $3.to_s
126
+
127
+ see_announcements(user, type, channel)
128
+
129
+
130
+ # help: ----------------------------------------------
131
+ # help: `share messages /REGEXP/ on #CHANNEL`
132
+ # help: `share messages "TEXT" on #CHANNEL`
133
+ # xhelp: `share messages :EMOJI: on #CHANNEL`
134
+ # help: It will automatically share new messages published that meet the specified criteria.
135
+ # xhelp: In case :EMOJI: it will share the messages with the indicated reaction.
136
+ # help: SmartBot user and user adding the share need to be members on both channels.
137
+ # help: The Regexp will automatically add the parameters /im
138
+ # help: Only available on public channels.
139
+ # help: Examples:
140
+ # help: _share messages /(last\s+|previous\s+)?sales\s+results\s+/ on #sales_
141
+ # help: _share messages "share post" on #announcements_
142
+ # xhelp: _share messages :tada: on #announcements_
143
+ # xhelp: _share messages :moneybag: from #sales_
144
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
145
+ # help:
146
+ when /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+<#\w+\|(.+)>\s*\z/i,
147
+ /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+<#(\w+)\|>\s*\z/,
148
+ /\A\s*share\s+messages\s+(\/.+\/|".+"|'.+')\s+on\s+(.+)\s*\z/i
149
+ condition = $1
150
+ channel = $2
151
+ channel.gsub!('#','') # for the case the channel name is in plain text including #
152
+ channel = @channels_name[channel] if @channels_name.key?(channel)
153
+ channel_from = @channels_name[dest]
154
+ channel_to = channel
155
+ share_messages(user, channel_from, channel_to, condition)
156
+
157
+ # help: ----------------------------------------------
158
+ # help: `see shares`
159
+ # help: It will display the active shares from this channel.
160
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
161
+ # help:
162
+ when /\A\s*see\s+shares\s*\z/i
163
+ see_shares()
164
+
165
+ # help: ----------------------------------------------
166
+ # help: `delete share ID`
167
+ # help: It will delete the share id specified.
168
+ # help: Examples:
169
+ # help: _delete share 24_
170
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#share-messages|more info>
171
+ # help:
172
+ when /\A\s*(delete|remove)\s+share\s+(\d+)\s*\z/i
173
+ share_id = $2
174
+ delete_share(user, share_id)
175
+
176
+ # help: ----------------------------------------------
177
+ # help: `see statuses`
178
+ # help: `see statuses #CHANNEL`
179
+ # help: `see status EMOJI`
180
+ # help: `see status EMOJI #CHANNEL`
181
+ # help: `see status EMOJI1 EMOJI99`
182
+ # help: `who is on vacation?`
183
+ # help: `who is on EMOJI`
184
+ # help: `who is on EMOJI #CHANNEL`
185
+ # help: `who is on EMOJI1 EMOJI99`
186
+ # help: `who is not on vacation?`
187
+ # help: `who is not on EMOJI`
188
+ # help: It will display the current statuses of the members of the channel where you are calling the command or on the channel you supply.
189
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#see-statuses|more info>
190
+ # help:
191
+ when /\A\s*(see|get)\s+(statuses)()\s*\z/i,
192
+ /\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??()\s*\z/i,
193
+ /\A\s*(who\s+is\s+on|who\s+is\s+not\s+on)\s+(vacation|holiday)\s*\??()\s*\z/i,
194
+ /\A\s*(see|get)\s+(statuses)\s+#([\w\-]+)\s*\z/i,
195
+ /\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??\s+#([\w\-]+)\s*\z/i,
196
+ /\A\s*(who\s+is\s+on|who\s+is\s+not\s+on)\s+(vacation|holiday)\s*\??\s+#([\w\-]+)\s*\z/i,
197
+ /\A\s*(see|get)\s+(statuses)\s+<#(C\w+)\|.+>\s*\z/i,
198
+ /\A\s*(see\s+status|get\s+status|who\s+is\s+on|who\s+is\s+not\s+on)\s+(:[\w\-\:\s]+:)\s*\??\s+<#(C\w+)\|.+>\s*\z/i,
199
+ /\A\s*(who\s+is\s+on|who\s+is\s+not\s+on)\s+(vacation|holiday)\s*\??\s+<#(C\w+)\|.+>\s*\z/i
200
+
201
+ not_on = $1.match?(/who\s+is\s+not\s+on/i)
202
+ type = $2.downcase
203
+ channel = $3.to_s
204
+ if type == 'statuses'
205
+ types = []
206
+ elsif type =='vacation' or type == 'holiday'
207
+ types = [':palm_tree:']
208
+ else
209
+ type.gsub!(' ', '')
210
+ type.gsub!('::',': :')
211
+ types = type.split(' ')
212
+ end
213
+ see_statuses(user, channel, types, dest, not_on)
214
+
215
+
216
+ # help: ----------------------------------------------
217
+ # help: `see favorite commands`
218
+ # help: `see my favorite commands`
219
+ # help: `favorite commands`
220
+ # help: `my favorite commands`
221
+ # help: It will display the favorite commands.
222
+ # help: aliases for favorite: favourite, most used, fav
223
+ # helpmaster: You need to set stats to true to generate the stats when running the bot instance and get this info.
224
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#see-favorite-commands|more info>
225
+ # help:
226
+ when /\A\s*(see\s+)?(my\s+)?(fav|favorite|favourite|most\s+used)\s+commands\s*\z/i
227
+ only_mine = $2.to_s!=''
228
+ see_favorite_commands(user, only_mine)
229
+
230
+ else
231
+ return false
232
+ end
233
+ return true
234
+ rescue => exception
235
+ if defined?(@logger)
236
+ @logger.fatal exception
237
+ respond "Unexpected error!! Please contact an admin to solve it: <@#{config.admins.join(">, <@")}>"
238
+ else
239
+ puts exception
240
+ end
241
+ return false
242
+ end
243
+ end