slack-smart-bot 1.9.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,16 +1,20 @@
1
1
  class SlackSmartBot
2
2
 
3
3
  def get_user_info(user)
4
- if user.to_s.length>0
5
- if config.simulate and config.key?(:client)
6
- if user[0]=='@' #name
7
- client.web_client.users_info.select{|k, v| v[:user][:name] == user[1..-1]}.values[-1]
8
- else #id
9
- client.web_client.users_info[user.to_sym]
4
+ begin
5
+ if user.to_s.length>0
6
+ if config.simulate and config.key?(:client)
7
+ if user[0]=='@' #name
8
+ client.web_client.users_info.select{|k, v| v[:user][:name] == user[1..-1]}.values[-1]
9
+ else #id
10
+ client.web_client.users_info[user.to_sym]
11
+ end
12
+ else
13
+ client.web_client.users_info(user: user)
10
14
  end
11
- else
12
- client.web_client.users_info(user: user)
13
15
  end
16
+ rescue Exception => stack
17
+ @logger.warn stack
14
18
  end
15
19
  end
16
20
  end
@@ -0,0 +1,24 @@
1
+ class SlackSmartBot
2
+
3
+ def get_users()
4
+ begin
5
+ users = []
6
+ cursor = nil
7
+ if config.simulate
8
+ users = client.web_client.users_list
9
+ else
10
+ begin
11
+ resp = client.web_client.users_list(limit: 1000, cursor: cursor)
12
+ if resp.key?(:members) and resp[:members].is_a(Array) and resp[:members].size > 0
13
+ users << resp[:members]
14
+ end
15
+ cursor = resp.get_values(:next_cursor).values[-1]
16
+ end until cursor.empty?
17
+ users.flatten!
18
+ end
19
+ return users
20
+ rescue Exception => stack
21
+ @logger.warn stack
22
+ end
23
+ end
24
+ end
@@ -2,7 +2,9 @@ class SlackSmartBot
2
2
  # list of available emojis: https://www.webfx.com/tools/emoji-cheat-sheet/
3
3
  # react(:thumbsup)
4
4
  # ts: can be true, false or a specific ts
5
- def react(emoji, ts=false)
5
+ def react(emoji, ts=false, channel='')
6
+ result = true
7
+ channel = Thread.current[:dest] if channel == ''
6
8
  if ts.is_a?(TrueClass) or ts.is_a?(FalseClass)
7
9
  parent = ts
8
10
  ts = nil
@@ -15,15 +17,30 @@ class SlackSmartBot
15
17
  else
16
18
  ts = Thread.current[:ts]
17
19
  end
20
+ else
21
+ if ts.to_s.match?(/^\d+\.\d+$/)
22
+ #thread id
23
+ elsif ts.to_s.match?(/^p\d\d\d\d\d+$/)
24
+ #a thread id taken from url fex: p1622549264010700
25
+ ts = ts.scan(/(\d+)/).join
26
+ ts = "#{ts[0..9]}.#{ts[10..-1]}"
27
+ else
28
+ ts = Thread.current[:thread_ts] if ts == ''
29
+ end
30
+
18
31
  end
19
32
  if ts.nil?
20
33
  @logger.warn 'react method no ts supplied'
34
+ result = false
21
35
  else
36
+ emoji.gsub!(':','') if emoji.is_a?(String)
22
37
  begin
23
- client.web_client.reactions_add(channel: Thread.current[:dest], name: emoji, timestamp: ts) unless config.simulate
38
+ client.web_client.reactions_add(channel: channel, name: emoji.to_sym, timestamp: ts) unless config.simulate
24
39
  rescue Exception => stack
25
40
  @logger.warn stack
41
+ result = false
26
42
  end
27
43
  end
44
+ return result
28
45
  end
29
46
  end
@@ -1,85 +1,230 @@
1
1
  class SlackSmartBot
2
- def respond(msg, dest = nil)
3
- if dest.nil? and Thread.current.key?(:dest)
4
- dest = Thread.current[:dest]
5
- end
6
- dest = @channels_id[dest] if @channels_id.key?(dest) #it is a name of channel
7
- if !config.simulate #https://api.slack.com/docs/rate-limits
8
- msg.to_s.size > 500 ? wait = 0.5 : wait = 0.1
9
- sleep wait if Time.now <= (@last_respond+wait)
10
- else
11
- wait = 0
12
- end
13
- msgs = msg.chars.each_slice(4000).map(&:join) # max of 4000 characters per message
14
- if dest.nil?
15
- if config[:simulate]
16
- open("#{config.path}/buffer_complete.log", "a") { |f|
17
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{msg}~~~"
18
- }
19
- else
20
- if Thread.current[:on_thread]
21
- msgs.each do |msg|
22
- client.message(channel: @channel_id, text: msg, as_user: true, thread_ts: Thread.current[:thread_ts])
23
- sleep wait
24
- end
2
+ def respond(msg = "", dest = nil, unfurl_links: true, unfurl_media: true, thread_ts: "", web_client: true, blocks: [], dont_share: false)
3
+ result = true
4
+ if (msg.to_s != "" or !msg.to_s.match?(/^A\s*\z/) or !blocks.empty?) and Thread.current[:routine_type].to_s != "bgroutine"
5
+ if !web_client.is_a?(TrueClass) and !web_client.is_a?(FalseClass)
6
+ (!unfurl_links or !unfurl_media) ? web_client = true : web_client = false
7
+ end
8
+ begin
9
+ msg = msg.to_s
10
+ web_client = true if !blocks.empty?
11
+
12
+ on_thread = Thread.current[:on_thread]
13
+ if dest.nil? and Thread.current.key?(:dest)
14
+ dest = Thread.current[:dest]
15
+ elsif dest.is_a?(Symbol) and dest == :on_thread
16
+ on_thread = true
17
+ dest = Thread.current[:dest]
18
+ elsif dest.is_a?(Symbol) and dest == :direct
19
+ dest = Thread.current[:user].id
20
+ end
21
+ if thread_ts.to_s.match?(/^\d+\.\d+$/)
22
+ on_thread = true
23
+ #thread id
24
+ elsif thread_ts.to_s.match?(/^p\d\d\d\d\d+$/)
25
+ on_thread = true
26
+ #a thread id taken from url fex: p1622549264010700
27
+ thread_ts = thread_ts.scan(/(\d+)/).join
28
+ thread_ts = "#{thread_ts[0..9]}.#{thread_ts[10..-1]}"
25
29
  else
26
- msgs.each do |msg|
27
- client.message(channel: @channel_id, text: msg, as_user: true)
28
- sleep wait
29
- end
30
+ thread_ts = Thread.current[:thread_ts] if thread_ts == ""
30
31
  end
31
- end
32
- if config[:testing] and config.on_master_bot
33
- open("#{config.path}/buffer.log", "a") { |f|
34
- f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{msg}"
35
- }
36
- end
37
- elsif dest[0] == "C" or dest[0] == "G" # channel
38
- if config[:simulate]
39
- open("#{config.path}/buffer_complete.log", "a") { |f|
40
- f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{msg}~~~"
41
- }
42
- else
43
- if Thread.current[:on_thread]
44
- msgs.each do |msg|
45
- client.message(channel: dest, text: msg, as_user: true, thread_ts: Thread.current[:thread_ts])
46
- sleep wait
32
+
33
+ dest = @channels_id[dest] if @channels_id.key?(dest) #it is a name of channel
34
+
35
+ on_thread ? txt_on_thread=':on_thread:' : txt_on_thread=''
36
+
37
+ if blocks.empty?
38
+ if !config.simulate #https://api.slack.com/docs/rate-limits
39
+ msg.size > 500 ? wait = 0.5 : wait = 0.1
40
+ sleep wait if Time.now <= (@last_respond + wait)
41
+ else
42
+ wait = 0
43
+ end
44
+
45
+ msgs = [] # max of 4000 characters per message
46
+ txt = ""
47
+ msg.split("\n").each do |m|
48
+ if (m + txt).size > 4000
49
+ msgs << txt.chars.each_slice(4000).map(&:join) unless txt == ""
50
+ txt = ""
51
+ end
52
+ txt += (m + "\n")
53
+ end
54
+ msgs << txt
55
+ msgs.flatten!
56
+ if dest.nil?
57
+ if config[:simulate]
58
+ open("#{config.path}/buffer_complete.log", "a") { |f|
59
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{txt_on_thread}#{msg}~~~"
60
+ }
61
+ else
62
+ if on_thread
63
+ msgs.each do |msg|
64
+ if web_client
65
+ resp = client.web_client.chat_postMessage(channel: @channel_id, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: thread_ts)
66
+ else
67
+ resp = client.message(channel: @channel_id, text: msg, as_user: true, thread_ts: thread_ts, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
68
+ end
69
+ sleep wait
70
+ end
71
+ else
72
+ msgs.each do |msg|
73
+ if web_client
74
+ resp = client.web_client.chat_postMessage(channel: @channel_id, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
75
+ else
76
+ resp = client.message(channel: @channel_id, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
77
+ end
78
+ sleep wait
79
+ end
80
+ end
81
+ end
82
+ if config[:testing] and config.on_master_bot and !@buffered
83
+ @buffered = true
84
+ open("#{config.path}/buffer.log", "a") { |f|
85
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{msg}"
86
+ }
87
+ end
88
+ elsif dest[0] == "C" or dest[0] == "G" # channel
89
+ if config[:simulate]
90
+ open("#{config.path}/buffer_complete.log", "a") { |f|
91
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{txt_on_thread}#{msg}~~~"
92
+ }
93
+ else
94
+ if on_thread
95
+ msgs.each do |msg|
96
+ if web_client
97
+ resp = client.web_client.chat_postMessage(channel: dest, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media, thread_ts: thread_ts)
98
+ else
99
+ resp = client.message(channel: dest, text: msg, as_user: true, thread_ts: thread_ts, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
100
+ end
101
+ sleep wait
102
+ end
103
+ else
104
+ msgs.each do |msg|
105
+ if web_client
106
+ resp = client.web_client.chat_postMessage(channel: dest, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
107
+ else
108
+ resp = client.message(channel: dest, text: msg, as_user: true, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
109
+ end
110
+ sleep wait
111
+ end
112
+ end
113
+ end
114
+ if config[:testing] and config.on_master_bot and !@buffered
115
+ @buffered = true
116
+ open("#{config.path}/buffer.log", "a") { |f|
117
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{msg}"
118
+ }
119
+ end
120
+ elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
121
+ msgs.each do |msg|
122
+ send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
123
+ sleep wait
124
+ end
125
+ elsif dest[0] == "@"
126
+ begin
127
+ user_info = @users.select { |u| u.id == dest[1..-1] or u.name == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
128
+ msgs.each do |msg|
129
+ send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
130
+ sleep wait
131
+ end
132
+ rescue Exception => stack
133
+ @logger.warn("user #{dest} not found.")
134
+ @logger.warn stack
135
+ if Thread.current.key?(:dest)
136
+ respond("User #{dest} not found.")
137
+ end
138
+ result = false
139
+ end
140
+ else
141
+ @logger.warn("method respond not treated correctly: msg:#{msg} dest:#{dest}")
142
+ result = false
47
143
  end
48
144
  else
49
- msgs.each do |msg|
50
- client.message(channel: dest, text: msg, as_user: true)
51
- sleep wait
145
+ wait = 0.1
146
+ if dest.nil?
147
+ if config[:simulate]
148
+ open("#{config.path}/buffer_complete.log", "a") { |f|
149
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{txt_on_thread}#{blocks.join}~~~"
150
+ }
151
+ else
152
+ if on_thread
153
+ blocks.each_slice(40).to_a.each do |blockstmp|
154
+ resp = client.web_client.chat_postMessage(channel: @channel_id, blocks: blockstmp, as_user: true, thread_ts: thread_ts)
155
+ sleep wait
156
+ end
157
+ else
158
+ blocks.each_slice(40).to_a.each do |blockstmp|
159
+ resp = client.web_client.chat_postMessage(channel: @channel_id, blocks: blockstmp, as_user: true)
160
+ sleep wait
161
+ end
162
+ end
163
+ end
164
+ if config[:testing] and config.on_master_bot and !@buffered
165
+ @buffered = true
166
+ open("#{config.path}/buffer.log", "a") { |f|
167
+ f.puts "|#{@channel_id}|#{config[:nick_id]}|#{config[:nick]}|#{blocks.join}"
168
+ }
169
+ end
170
+ elsif dest[0] == "C" or dest[0] == "G" # channel
171
+ if config[:simulate]
172
+ open("#{config.path}/buffer_complete.log", "a") { |f|
173
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{txt_on_thread}#{blocks.join}~~~"
174
+ }
175
+ else
176
+ if on_thread
177
+ blocks.each_slice(40).to_a.each do |blockstmp|
178
+ resp = client.web_client.chat_postMessage(channel: dest, blocks: blockstmp, as_user: true, thread_ts: thread_ts)
179
+ sleep wait
180
+ end
181
+ else
182
+ blocks.each_slice(40).to_a.each do |blockstmp|
183
+ resp = client.web_client.chat_postMessage(channel: dest, blocks: blockstmp, as_user: true)
184
+ sleep wait
185
+ end
186
+ end
187
+ end
188
+ if config[:testing] and config.on_master_bot and !@buffered
189
+ @buffered = true
190
+ open("#{config.path}/buffer.log", "a") { |f|
191
+ f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{blocks.join}"
192
+ }
193
+ end
194
+ elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
195
+ blocks.each_slice(40).to_a.each do |blockstmp|
196
+ send_msg_user(dest, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
197
+ sleep wait
198
+ end
199
+ elsif dest[0] == "@"
200
+ begin
201
+ user_info = @users.select { |u| u.id == dest[1..-1] or (u.key?(:enterprise_user) and u.enterprise_user.id == dest[1..-1]) }[-1]
202
+ blocks.each_slice(40).to_a.each do |blockstmp|
203
+ send_msg_user(user_info.id, msg, on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media, blocks: blockstmp)
204
+ sleep wait
205
+ end
206
+ rescue Exception => stack
207
+ @logger.warn("user #{dest} not found.")
208
+ @logger.warn stack
209
+ if Thread.current.key?(:dest)
210
+ respond("User #{dest} not found.")
211
+ end
212
+ result = false
213
+ end
214
+ else
215
+ @logger.warn("method respond not treated correctly: msg:#{msg} dest:#{dest}")
216
+ result = false
52
217
  end
53
218
  end
54
- end
55
- if config[:testing] and config.on_master_bot
56
- open("#{config.path}/buffer.log", "a") { |f|
57
- f.puts "|#{dest}|#{config[:nick_id]}|#{config[:nick]}|#{msg}"
58
- }
59
- end
60
- elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
61
- msgs.each do |msg|
62
- send_msg_user(dest, msg)
63
- sleep wait
64
- end
65
- elsif dest[0] == "@"
66
- begin
67
- user_info = get_user_info(dest)
68
- msgs.each do |msg|
69
- send_msg_user(user_info.user.id, msg)
70
- sleep wait
71
- end
219
+ @last_respond = Time.now
72
220
  rescue Exception => stack
73
- @logger.warn("user #{dest} not found.")
74
221
  @logger.warn stack
75
- if Thread.current.key?(:dest)
76
- respond("User #{dest} not found.")
77
- end
222
+ result = false
78
223
  end
79
- else
80
- @logger.warn("method respond not treated correctly: msg:#{msg} dest:#{dest}")
81
224
  end
82
- @last_respond = Time.now
225
+ if Thread.current.key?(:routine) and Thread.current[:routine]
226
+ File.write("#{config.path}/routines/#{@channel_id}/#{Thread.current[:routine_name]}_output.txt", msg, mode: "a+")
227
+ end
228
+ return result
83
229
  end
84
-
85
230
  end
@@ -1,6 +1,5 @@
1
1
  class SlackSmartBot
2
- def respond_direct(msg)
3
- dest = Thread.current[:user].id
4
- respond(msg, dest)
2
+ def respond_direct(msg, unfurl_links: true, unfurl_media: true)
3
+ respond(msg, :direct, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
5
4
  end
6
5
  end
@@ -0,0 +1,5 @@
1
+ class SlackSmartBot
2
+ def respond_thread(msg, unfurl_links: true, unfurl_media: true)
3
+ respond(msg, :on_thread, unfurl_links: unfurl_links, unfurl_media: unfurl_media)
4
+ end
5
+ end
@@ -7,42 +7,46 @@ class SlackSmartBot
7
7
  #send_file(dest, 'the message', "myfile.rb", 'message to be sent', 'text/plain', "ruby", content: "the content to be sent when no file supplied")
8
8
  def send_file(to, msg, file, title, format, type = "text", content: '')
9
9
  unless config[:simulate]
10
- file = 'myfile' if file.to_s == '' and content!=''
11
- if to[0] == "U" or to[0] == "W" #user
12
- im = client.web_client.im_open(user: to)
13
- channel = im["channel"]["id"]
14
- else
15
- channel = to
16
- end
10
+ begin
11
+ file = 'myfile' if file.to_s == '' and content!=''
12
+ if to[0] == "U" or to[0] == "W" #user
13
+ im = client.web_client.conversations_open(users: id_user)
14
+ channel = im["channel"]["id"]
15
+ else
16
+ channel = to
17
+ end
17
18
 
18
- if Thread.current[:on_thread]
19
- ts = Thread.current[:thread_ts]
20
- else
21
- ts = nil
22
- end
19
+ if Thread.current[:on_thread]
20
+ ts = Thread.current[:thread_ts]
21
+ else
22
+ ts = nil
23
+ end
23
24
 
24
- if content.to_s == ''
25
- client.web_client.files_upload(
26
- channels: channel,
27
- as_user: true,
28
- file: Faraday::UploadIO.new(file, format),
29
- title: title,
30
- filename: file,
31
- filetype: type,
32
- initial_comment: msg,
33
- thread_ts: ts
34
- )
35
- else
36
- client.web_client.files_upload(
37
- channels: channel,
38
- as_user: true,
39
- content: content,
40
- title: title,
41
- filename: file,
42
- filetype: type,
43
- initial_comment: msg,
44
- thread_ts: ts
45
- )
25
+ if content.to_s == ''
26
+ client.web_client.files_upload(
27
+ channels: channel,
28
+ as_user: true,
29
+ file: Faraday::UploadIO.new(file, format),
30
+ title: title,
31
+ filename: file,
32
+ filetype: type,
33
+ initial_comment: msg,
34
+ thread_ts: ts
35
+ )
36
+ else
37
+ client.web_client.files_upload(
38
+ channels: channel,
39
+ as_user: true,
40
+ content: content,
41
+ title: title,
42
+ filename: file,
43
+ filetype: type,
44
+ initial_comment: msg,
45
+ thread_ts: ts
46
+ )
47
+ end
48
+ rescue Exception => stack
49
+ @logger.warn stack
46
50
  end
47
51
  end
48
52
  end