slack-smart-bot 1.8.1 → 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 (92) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +127 -21
  3. data/lib/slack/smart-bot/comm/ask.rb +55 -42
  4. data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
  5. data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
  6. data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
  7. data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
  8. data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
  9. data/lib/slack/smart-bot/comm/get_users.rb +24 -0
  10. data/lib/slack/smart-bot/comm/react.rb +38 -8
  11. data/lib/slack/smart-bot/comm/respond.rb +219 -48
  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 +24 -7
  18. data/lib/slack/smart-bot/comm.rb +7 -1
  19. data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
  20. data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
  21. data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
  22. data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
  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 +13 -16
  36. data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
  37. data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
  38. data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
  39. data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
  40. data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
  41. data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
  42. data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
  43. data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
  44. data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
  45. data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
  46. data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +12 -4
  47. data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
  48. data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
  49. data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
  50. data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
  51. data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
  52. data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +3 -5
  53. data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
  54. data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
  55. data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
  56. data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
  57. data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
  58. data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
  59. data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
  60. data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
  61. data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
  62. data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +5 -3
  63. data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
  64. data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
  65. data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
  66. data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +49 -0
  67. data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
  68. data/lib/slack/smart-bot/commands.rb +19 -1
  69. data/lib/slack/smart-bot/listen.rb +7 -8
  70. data/lib/slack/smart-bot/process.rb +373 -192
  71. data/lib/slack/smart-bot/process_first.rb +202 -104
  72. data/lib/slack/smart-bot/treat_message.rb +325 -186
  73. data/lib/slack/smart-bot/utils/answer.rb +18 -0
  74. data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
  75. data/lib/slack/smart-bot/utils/build_help.rb +57 -5
  76. data/lib/slack/smart-bot/utils/create_routine_thread.rb +83 -30
  77. data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
  78. data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
  79. data/lib/slack/smart-bot/utils/get_help.rb +87 -35
  80. data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
  81. data/lib/slack/smart-bot/utils/has_access.rb +12 -0
  82. data/lib/slack/smart-bot/utils/save_stats.rb +23 -8
  83. data/lib/slack/smart-bot/utils/save_status.rb +52 -0
  84. data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
  85. data/lib/slack/smart-bot/utils.rb +5 -0
  86. data/lib/slack-smart-bot.rb +88 -47
  87. data/lib/slack-smart-bot_general_commands.rb +46 -0
  88. data/lib/slack-smart-bot_general_rules.rb +5 -2
  89. data/lib/slack-smart-bot_rules.rb +49 -23
  90. data/whats_new.txt +36 -0
  91. metadata +44 -13
  92. data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -0,0 +1,200 @@
1
+ class SlackSmartBot
2
+ # help: ----------------------------------------------
3
+ # help: `leaderboard`
4
+ # help: `ranking`
5
+ # help: `podium`
6
+ # help: `leaderboard from YYYY/MM/DD`
7
+ # help: `leaderboard from YYYY/MM/DD to YYYY/MM/DD`
8
+ # help: `leaderboard PERIOD`
9
+ # help: It will present some useful information about the use of the SmartBot in the period specified.
10
+ # help: If no 'from' and 'to' specified then it will be considered 'last week'
11
+ # help: PERIOD: today, yesterday, last week, this week, last month, this month, last year, this year
12
+ # help: The results will exclude master admins and routines.
13
+ # help: For a more detailed data use the command `bot stats`
14
+ # help: Examples:
15
+ # help: _leaderboard_
16
+ # help: _podium from 2021/05/01_
17
+ # help: _leaderboard from 2021/05/01 to 2021/05/31_
18
+ # help: _ranking today_
19
+ # help: <https://github.com/MarioRuiz/slack-smart-bot#bot-management|more info>
20
+ # help:
21
+
22
+ def leaderboard(from, to, period)
23
+ exclude_masters = true
24
+ exclude_routines = true
25
+ require 'csv'
26
+ if config.stats
27
+ message = []
28
+ else
29
+ message = ["You need to set stats to true to generate the stats when running the bot instance."]
30
+ end
31
+ save_stats(__method__)
32
+ if !File.exist?("#{config.stats_path}.#{Time.now.strftime("%Y-%m")}.log")
33
+ message<<'No stats'
34
+ else
35
+ if period == ''
36
+ message << "*Leaderboard SmartBot <##@channel_id> from #{from} to #{to}*\n"
37
+ else
38
+ message << "*Leaderboard SmartBot <##@channel_id> #{period}* (#{from} -> #{to})\n"
39
+ end
40
+ from_short = from
41
+ to_short = to
42
+ from_file = from[0..3] + '-' + from[5..6]
43
+ to_file = to[0..3] + '-' + to[5..6]
44
+ from+= " 00:00:00 +0000"
45
+ to+= " 23:59:59 +0000"
46
+ rows = []
47
+ users_id_name = {}
48
+ users_name_id = {}
49
+ count_users = {}
50
+ count_channels_dest = {}
51
+ count_commands_uniq_user = {}
52
+
53
+ # to translate global and enterprise users since sometimes was returning different names/ids
54
+ if from[0..3]=='2020' # this was an issue only on that period
55
+ Dir["#{config.stats_path}.*.log"].sort.each do |file|
56
+ if file >= "#{config.stats_path}.#{from_file}.log" or file <= "#{config.stats_path}.#{to_file}.log"
57
+ CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
58
+ unless users_id_name.key?(row[:user_id])
59
+ users_id_name[row[:user_id]] = row[:user_name]
60
+ end
61
+ unless users_name_id.key?(row[:user_name])
62
+ users_name_id[row[:user_name]] = row[:user_id]
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ master_admins = config.masters.dup
71
+ if users_id_name.size > 0
72
+ config.masters.each do |u|
73
+ if users_id_name.key?(u)
74
+ master_admins << users_id_name[u]
75
+ elsif users_name_id.key?(u)
76
+ master_admins << users_name_id[u]
77
+ end
78
+ end
79
+ end
80
+
81
+ Dir["#{config.stats_path}.*.log"].sort.each do |file|
82
+ if file >= "#{config.stats_path}.#{from_file}.log" and file <= "#{config.stats_path}.#{to_file}.log"
83
+ CSV.foreach(file, headers: true, header_converters: :symbol, converters: :numeric) do |row|
84
+ row[:date] = row[:date].to_s
85
+ if row[:dest_channel_id].to_s[0]=='D'
86
+ row[:dest_channel] = 'DM'
87
+ elsif row[:dest_channel].to_s == ''
88
+ row[:dest_channel] = row[:dest_channel_id]
89
+ end
90
+ if users_name_id.size > 0
91
+ row[:user_name] = users_id_name[row[:user_id]]
92
+ row[:user_id] = users_name_id[row[:user_name]]
93
+ else
94
+ users_id_name[row[:user_id]] ||= row[:user_name]
95
+ end
96
+ if !exclude_masters or (exclude_masters and !master_admins.include?(row[:user_name]) and
97
+ !master_admins.include?(row[:user_id]) and
98
+ !@master_admin_users_id.include?(row[:user_id]))
99
+ if !exclude_routines or (exclude_routines and !row[:user_name].match?(/^routine\//) )
100
+ if row[:bot_channel_id] == @channel_id
101
+ if row[:date] >= from and row[:date] <= to
102
+ count_users[row[:user_id]] ||= 0
103
+ count_users[row[:user_id]] += 1
104
+ rows << row.to_h
105
+ count_channels_dest[row[:dest_channel]] ||= 0
106
+ count_channels_dest[row[:dest_channel]] += 1
107
+ count_commands_uniq_user[row[:user_id]] ||= []
108
+ count_commands_uniq_user[row[:user_id]] << row[:command] unless count_commands_uniq_user[row[:user_id]].include?(row[:command])
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ total = rows.size
118
+
119
+ if total > 0
120
+
121
+ users = rows.user_id.uniq.sort
122
+ count_user = {}
123
+ users.each do |user|
124
+ count = rows.count {|h| h.user_id==user}
125
+ count_user[user] = count
126
+ end
127
+ mtc = nil
128
+ mtu = []
129
+ i = 0
130
+ count_user.sort_by {|k,v| -v}.each do |user, count|
131
+ if i >= 3
132
+ break
133
+ elsif mtc.nil? or mtc == count or i < 3
134
+ mtu << "*<@#{users_id_name[user]}>* (#{count})"
135
+ mtc = count
136
+ else
137
+ break
138
+ end
139
+ i+=1
140
+ end
141
+ message << "\t :boom: Users that called more commands: \n\t\t\t\t#{mtu.join("\n\t\t\t\t")}"
142
+
143
+ mtc = nil
144
+ mtu = []
145
+ i = 0
146
+ count_commands_uniq_user.sort_by {|k,v| -v.size}.each do |user, cmds|
147
+ if i >= 3
148
+ break
149
+ elsif mtc.nil? or mtc == cmds.size or i < 3
150
+ mtu << "*<@#{users_id_name[user]}>* (#{cmds.size})"
151
+ mtc = cmds.size
152
+ else
153
+ break
154
+ end
155
+ i+=1
156
+ end
157
+ message << "\t :stethoscope: Users that called more different commands: \n\t\t\t\t#{mtu.join("\n\t\t\t\t")}"
158
+
159
+ commands_attachment = []
160
+
161
+ commands = rows.command.uniq.sort
162
+ count_command = {}
163
+ commands.each do |command|
164
+ count = rows.count {|h| h.command==command}
165
+ count_command[command] = count
166
+ end
167
+
168
+ mtu = []
169
+ count_command.sort_by {|k,v| -v}[0..2].each do |command, count|
170
+ mtu << "*`#{command.gsub('_',' ')}`* (#{count})"
171
+ end
172
+ message << "\t :four_leaf_clover: Most used commands: \n\t\t\t\t#{mtu.join("\n\t\t\t\t")}"
173
+
174
+ count_channels_dest = count_channels_dest.sort_by(&:last).reverse.to_h
175
+ count_channels_dest.keys[0..0].each do |ch|
176
+ if ch=='DM'
177
+ message << "\t :star: Most used channel: *DM* (#{(count_channels_dest[ch].to_f*100/total).round(2)}%)"
178
+ else
179
+ message << "\t :star: Most used channel: *<##{@channels_id[ch]}>* (#{(count_channels_dest[ch].to_f*100/total).round(2)}%)"
180
+ end
181
+ end
182
+
183
+ types = rows.type_message.uniq.sort
184
+ count_type = {}
185
+ types.each do |type|
186
+ count = rows.count {|h| h.type_message==type}
187
+ count_type[type] = count
188
+ end
189
+
190
+ count_type.sort_by {|k,v| -v}[0..0].each do |type, count|
191
+ message << "\t :house_with_garden: Most calls came from *#{type}* (#{(count.to_f*100/total).round(2)}%)"
192
+ end
193
+ else
194
+ message << 'No data yet'
195
+ end
196
+ end
197
+ respond "#{message.join("\n")}"
198
+
199
+ end
200
+ end
@@ -0,0 +1,113 @@
1
+ class SlackSmartBot
2
+
3
+ def see_announcements(user, type, channel, mention=false, publish=false)
4
+ save_stats(__method__)
5
+ typem = Thread.current[:typem]
6
+ general_message = "\nRelated commands `add announcement MESSAGE`, `delete announcement ID`"
7
+ if channel == ''
8
+ if typem == :on_call
9
+ channel = Thread.current[:dchannel]
10
+ else
11
+ channel = Thread.current[:dest]
12
+ end
13
+ end
14
+ if publish
15
+ dest = channel
16
+ else
17
+ dest = Thread.current[:dest]
18
+ end
19
+
20
+ if type == 'all'
21
+ if config.masters.include?(user.name) and typem==:on_dm
22
+ channels = Dir.entries("#{config.path}/announcements/")
23
+ channels.select! {|i| i[/\.csv$/]}
24
+ else
25
+ channels = []
26
+ respond "Only master admins on a DM with the SmarBot can call this command.", dest
27
+ end
28
+ elsif typem == :on_dm and channel == Thread.current[:dest]
29
+ channels = [channel, @channel_id]
30
+ else
31
+ channels = [channel]
32
+ end
33
+ channels.each do |channel|
34
+ channel.gsub!('.csv','')
35
+ if channel[0]== 'D'
36
+ channel_id = channel
37
+ else
38
+ get_channels_name_and_id() unless @channels_name.keys.include?(channel) or @channels_id.keys.include?(channel)
39
+ channel_id = nil
40
+ if @channels_name.key?(channel) #it is an id
41
+ channel_id = channel
42
+ channel = @channels_name[channel_id]
43
+ elsif @channels_id.key?(channel) #it is a channel name
44
+ channel_id = @channels_id[channel]
45
+ end
46
+ end
47
+ if has_access?(__method__, user)
48
+ if (channel_id!=Thread.current[:dest] and config.masters.include?(user.name) and typem==:on_dm) or publish
49
+ see_announcements_on_demand = true
50
+ else
51
+ see_announcements_on_demand = false
52
+ end
53
+ if channel_id == Thread.current[:dest] or see_announcements_on_demand or publish #master admin user or publish_announcements
54
+ if File.exists?("#{config.path}/announcements/#{channel_id}.csv") and (!@announcements.key?(channel_id) or see_announcements_on_demand) # to force to have the last version that maybe was updated by other SmartBot in case of demand
55
+ t = CSV.table("#{config.path}/announcements/#{channel_id}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
56
+ @announcements[channel_id] = t
57
+ end
58
+ if @announcements.key?(channel_id)
59
+ message = []
60
+ @announcements[channel_id].each do |m|
61
+ if m[:user_deleted] == '' and (type == 'all' or type == '' or type==m[:type])
62
+ if m[:type].match?(/:\w+:/)
63
+ emoji = m[:type]
64
+ elsif m[:type] == 'white'
65
+ emoji = ':white_square:'
66
+ else
67
+ emoji = ":large_#{m[:type]}_square:"
68
+ end
69
+ if mention
70
+ user_created = "<@#{m[:user_created]}>"
71
+ else
72
+ user_created = m[:user_created]
73
+ end
74
+ if type == 'all' and channel_id[0]=='D'
75
+ message << "\t#{m[:message_id]} #{emoji} *_#{m[:date]}_* #{m[:time]} *:* \t*private*"
76
+ else
77
+ message << "\t#{m[:message_id]} #{emoji} *_#{m[:date]}_* #{m[:time]} #{"#{user_created} " unless channel_id[0]=='D'}*:* \t#{m[:message]}"
78
+ end
79
+ end
80
+ end
81
+ if message.size > 0
82
+ if channel_id[0]=='D'
83
+ if type == 'all'
84
+ message.unshift("*Private messages stored on DM with the SmartBot and <@#{@announcements[channel_id][:user_created][0]}>*")
85
+ else
86
+ message.unshift("*Private messages stored on your DM with the SmartBot*")
87
+ end
88
+ else
89
+ message.unshift("*Announcements for channel <##{channel_id}>*")
90
+ end
91
+ message << general_message
92
+ respond message.join("\n"), dest
93
+ else
94
+ if typem == :on_dm and channel_id[0]=='D'
95
+ respond("There are no #{type} announcements#{general_message}", dest) unless type == 'all'
96
+ else
97
+ respond("There are no #{type} announcements for <##{channel_id}>#{general_message}", dest) unless publish or type == 'all' or (typem==:on_dm and channel_id[0]!='D' and !see_announcements_on_demand)
98
+ end
99
+ end
100
+ else
101
+ if typem == :on_dm and channel_id[0]=='D'
102
+ respond("There are no announcements#{general_message}", dest) unless type == 'all'
103
+ else
104
+ respond("There are no announcements for <##{channel_id}>#{general_message}", dest) unless publish or type == 'all' or (typem==:on_dm and channel_id[0]!='D' and !see_announcements_on_demand)
105
+ end
106
+ end
107
+ else
108
+ respond "Go to <##{channel_id}> and call the command from there.", dest
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -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