slack-smart-bot 1.8.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +127 -21
- data/lib/slack/smart-bot/comm/ask.rb +55 -42
- data/lib/slack/smart-bot/comm/dont_understand.rb +2 -2
- data/lib/slack/smart-bot/comm/event_hello.rb +34 -0
- data/lib/slack/smart-bot/comm/get_channel_members.rb +13 -0
- data/lib/slack/smart-bot/comm/get_channels.rb +35 -0
- data/lib/slack/smart-bot/comm/get_user_info.rb +20 -0
- data/lib/slack/smart-bot/comm/get_users.rb +24 -0
- data/lib/slack/smart-bot/comm/react.rb +38 -8
- data/lib/slack/smart-bot/comm/respond.rb +219 -48
- data/lib/slack/smart-bot/comm/respond_direct.rb +2 -3
- data/lib/slack/smart-bot/comm/respond_thread.rb +5 -0
- data/lib/slack/smart-bot/comm/send_file.rb +38 -34
- data/lib/slack/smart-bot/comm/send_msg_channel.rb +27 -22
- data/lib/slack/smart-bot/comm/send_msg_user.rb +58 -33
- data/lib/slack/smart-bot/comm/unreact.rb +24 -7
- data/lib/slack/smart-bot/comm.rb +7 -1
- data/lib/slack/smart-bot/commands/general/add_announcement.rb +32 -0
- data/lib/slack/smart-bot/commands/general/bot_help.rb +68 -28
- data/lib/slack/smart-bot/commands/general/bot_stats.rb +314 -0
- data/lib/slack/smart-bot/commands/general/bot_status.rb +3 -5
- data/lib/slack/smart-bot/commands/general/bye_bot.rb +0 -7
- data/lib/slack/smart-bot/commands/general/delete_announcement.rb +34 -0
- data/lib/slack/smart-bot/commands/general/delete_share.rb +34 -0
- data/lib/slack/smart-bot/commands/general/hi_bot.rb +16 -11
- data/lib/slack/smart-bot/commands/general/leaderboard.rb +200 -0
- data/lib/slack/smart-bot/commands/general/see_announcements.rb +113 -0
- data/lib/slack/smart-bot/commands/general/see_favorite_commands.rb +54 -0
- data/lib/slack/smart-bot/commands/general/see_shares.rb +41 -0
- data/lib/slack/smart-bot/commands/general/see_statuses.rb +78 -0
- data/lib/slack/smart-bot/commands/general/share_messages.rb +58 -0
- data/lib/slack/smart-bot/commands/general/stop_using_rules.rb +11 -6
- data/lib/slack/smart-bot/commands/general/suggest_command.rb +30 -0
- data/lib/slack/smart-bot/commands/general/use_rules.rb +13 -16
- data/lib/slack/smart-bot/commands/general/whats_new.rb +19 -0
- data/lib/slack/smart-bot/commands/general_bot_commands.rb +243 -0
- data/lib/slack/smart-bot/commands/on_bot/add_shortcut.rb +67 -38
- data/lib/slack/smart-bot/commands/on_bot/admin/add_routine.rb +49 -14
- data/lib/slack/smart-bot/commands/on_bot/admin/extend_rules.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/pause_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/remove_routine.rb +2 -3
- data/lib/slack/smart-bot/commands/on_bot/admin/run_routine.rb +6 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/see_result_routine.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/see_routines.rb +12 -4
- data/lib/slack/smart-bot/commands/on_bot/admin/start_bot.rb +4 -1
- data/lib/slack/smart-bot/commands/on_bot/admin/start_routine.rb +1 -0
- data/lib/slack/smart-bot/commands/on_bot/admin/stop_using_rules_on.rb +2 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/react_to.rb +32 -0
- data/lib/slack/smart-bot/commands/on_bot/admin_master/send_message.rb +24 -0
- data/lib/slack/smart-bot/commands/on_bot/delete_repl.rb +3 -5
- data/lib/slack/smart-bot/commands/on_bot/delete_shortcut.rb +54 -25
- data/lib/slack/smart-bot/commands/on_bot/get_repl.rb +7 -9
- data/lib/slack/smart-bot/commands/on_bot/repl.rb +55 -25
- data/lib/slack/smart-bot/commands/on_bot/ruby_code.rb +36 -13
- data/lib/slack/smart-bot/commands/on_bot/run_repl.rb +5 -7
- data/lib/slack/smart-bot/commands/on_bot/see_repls.rb +4 -6
- data/lib/slack/smart-bot/commands/on_bot/see_shortcuts.rb +29 -13
- data/lib/slack/smart-bot/commands/on_extended/bot_rules.rb +55 -9
- data/lib/slack/smart-bot/commands/on_master/admin/kill_bot_on_channel.rb +4 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/exit_bot.rb +5 -3
- data/lib/slack/smart-bot/commands/on_master/admin_master/notify_message.rb +2 -1
- data/lib/slack/smart-bot/commands/on_master/admin_master/publish_announcements.rb +32 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_general_message.rb +38 -0
- data/lib/slack/smart-bot/commands/on_master/admin_master/set_maintenance.rb +49 -0
- data/lib/slack/smart-bot/commands/on_master/create_bot.rb +30 -21
- data/lib/slack/smart-bot/commands.rb +19 -1
- data/lib/slack/smart-bot/listen.rb +7 -8
- data/lib/slack/smart-bot/process.rb +373 -192
- data/lib/slack/smart-bot/process_first.rb +202 -104
- data/lib/slack/smart-bot/treat_message.rb +325 -186
- data/lib/slack/smart-bot/utils/answer.rb +18 -0
- data/lib/slack/smart-bot/utils/answer_delete.rb +15 -0
- data/lib/slack/smart-bot/utils/build_help.rb +57 -5
- data/lib/slack/smart-bot/utils/create_routine_thread.rb +83 -30
- data/lib/slack/smart-bot/utils/get_bots_created.rb +4 -1
- data/lib/slack/smart-bot/utils/get_channels_name_and_id.rb +1 -7
- data/lib/slack/smart-bot/utils/get_help.rb +87 -35
- data/lib/slack/smart-bot/utils/get_shares.rb +12 -0
- data/lib/slack/smart-bot/utils/has_access.rb +12 -0
- data/lib/slack/smart-bot/utils/save_stats.rb +23 -8
- data/lib/slack/smart-bot/utils/save_status.rb +52 -0
- data/lib/slack/smart-bot/utils/update_shortcuts_file.rb +6 -0
- data/lib/slack/smart-bot/utils.rb +5 -0
- data/lib/slack-smart-bot.rb +88 -47
- data/lib/slack-smart-bot_general_commands.rb +46 -0
- data/lib/slack-smart-bot_general_rules.rb +5 -2
- data/lib/slack-smart-bot_rules.rb +49 -23
- data/whats_new.txt +36 -0
- metadata +44 -13
- data/lib/slack/smart-bot/commands/on_bot/admin_master/bot_stats.rb +0 -195
@@ -0,0 +1,13 @@
|
|
1
|
+
#todo: add pagination for case more than 1000 members in the channel
|
2
|
+
def get_channel_members(channel_id)
|
3
|
+
begin
|
4
|
+
if config.simulate and config.key?(:client)
|
5
|
+
client.web_client.conversations_members[channel_id.to_sym].members
|
6
|
+
else
|
7
|
+
client.web_client.conversations_members(channel: channel_id, limit: 1000).members
|
8
|
+
end
|
9
|
+
rescue Exception => stack
|
10
|
+
@logger.warn stack
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
def get_channels(bot_is_in: false, types: 'private_channel,public_channel')
|
2
|
+
begin
|
3
|
+
if config.simulate and config.key?(:client)
|
4
|
+
if bot_is_in
|
5
|
+
client.web_client.conversations_members.reject { |r, v| !v.members.include?(config.nick_id) }.values
|
6
|
+
else
|
7
|
+
client.web_client.conversations_members.values
|
8
|
+
end
|
9
|
+
else
|
10
|
+
if bot_is_in
|
11
|
+
client.web_client.users_conversations(exclude_archived: true, limit: 1000, types: "im, public_channel,private_channel").channels
|
12
|
+
else
|
13
|
+
resp = client.web_client.conversations_list(types: types, limit: "600", exclude_archived: "true")
|
14
|
+
channels = resp.channels
|
15
|
+
begin
|
16
|
+
while resp.response_metadata.next_cursor.to_s != ""
|
17
|
+
resp = client.web_client.conversations_list(
|
18
|
+
cursor: resp.response_metadata.next_cursor.to_s,
|
19
|
+
types: types,
|
20
|
+
limit: "600",
|
21
|
+
exclude_archived: "true",
|
22
|
+
)
|
23
|
+
channels += resp.channels
|
24
|
+
end
|
25
|
+
rescue Exception => stack
|
26
|
+
@logger.warn stack
|
27
|
+
end
|
28
|
+
return channels
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue Exception => stack
|
32
|
+
@logger.warn stack
|
33
|
+
return []
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class SlackSmartBot
|
2
|
+
|
3
|
+
def get_user_info(user)
|
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)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
rescue Exception => stack
|
17
|
+
@logger.warn stack
|
18
|
+
end
|
19
|
+
end
|
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
|
@@ -1,16 +1,46 @@
|
|
1
1
|
class SlackSmartBot
|
2
2
|
# list of available emojis: https://www.webfx.com/tools/emoji-cheat-sheet/
|
3
3
|
# react(:thumbsup)
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
# ts: can be true, false or a specific ts
|
5
|
+
def react(emoji, ts=false, channel='')
|
6
|
+
result = true
|
7
|
+
channel = Thread.current[:dest] if channel == ''
|
8
|
+
if ts.is_a?(TrueClass) or ts.is_a?(FalseClass)
|
9
|
+
parent = ts
|
10
|
+
ts = nil
|
7
11
|
else
|
8
|
-
|
12
|
+
parent = false
|
9
13
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
if ts.nil?
|
15
|
+
if parent or Thread.current[:ts].to_s == ''
|
16
|
+
ts = Thread.current[:thread_ts]
|
17
|
+
else
|
18
|
+
ts = Thread.current[:ts]
|
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
|
+
|
31
|
+
end
|
32
|
+
if ts.nil?
|
33
|
+
@logger.warn 'react method no ts supplied'
|
34
|
+
result = false
|
35
|
+
else
|
36
|
+
emoji.gsub!(':','') if emoji.is_a?(String)
|
37
|
+
begin
|
38
|
+
client.web_client.reactions_add(channel: channel, name: emoji.to_sym, timestamp: ts) unless config.simulate
|
39
|
+
rescue Exception => stack
|
40
|
+
@logger.warn stack
|
41
|
+
result = false
|
42
|
+
end
|
14
43
|
end
|
44
|
+
return result
|
15
45
|
end
|
16
46
|
end
|
@@ -1,59 +1,230 @@
|
|
1
1
|
class SlackSmartBot
|
2
|
-
def respond(msg, dest = nil)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if Thread.current
|
14
|
-
|
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]}"
|
15
29
|
else
|
16
|
-
|
30
|
+
thread_ts = Thread.current[:thread_ts] if thread_ts == ""
|
17
31
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
143
|
+
end
|
32
144
|
else
|
33
|
-
|
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
|
217
|
+
end
|
34
218
|
end
|
35
|
-
|
36
|
-
if config[:testing] and config.on_master_bot
|
37
|
-
open("#{config.path}/buffer.log", "a") { |f|
|
38
|
-
f.puts "|#{dest}|#{config[:nick_id]}|#{msg}"
|
39
|
-
}
|
40
|
-
end
|
41
|
-
elsif dest[0] == "D" or dest[0] == "U" or dest[0] == "W" # Direct message
|
42
|
-
send_msg_user(dest, msg)
|
43
|
-
elsif dest[0] == "@"
|
44
|
-
begin
|
45
|
-
user_info = client.web_client.users_info(user: dest)
|
46
|
-
send_msg_user(user_info.user.id, msg)
|
219
|
+
@last_respond = Time.now
|
47
220
|
rescue Exception => stack
|
48
|
-
@logger.warn("user #{dest} not found.")
|
49
221
|
@logger.warn stack
|
50
|
-
|
51
|
-
respond("User #{dest} not found.")
|
52
|
-
end
|
222
|
+
result = false
|
53
223
|
end
|
54
|
-
else
|
55
|
-
@logger.warn("method respond not treated correctly: msg:#{msg} dest:#{dest}")
|
56
224
|
end
|
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
|
57
229
|
end
|
58
|
-
|
59
230
|
end
|