ruboty-slack_rtm 2.4.2 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/adapters/slack_rtm.rb +15 -16
- data/lib/ruboty/slack_rtm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 359ba35900b7f5a50ae244f89d0ef51b7d83ab44
|
4
|
+
data.tar.gz: 292b9ec04aad2813568975987433471fd48288ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b275014e2d920b612ec864a1250056a2bef3ff5d741160ceef715fcce3ed90a5f6d755cdd641cd0d4f46ceeae71535e01815884cd147dfe6a0214bb0cfe17e
|
7
|
+
data.tar.gz: 0db4ff4ef1b3a90f28ccaf8a0c8284fc0646229156b35c12ceac48ab8e16b4a998a23d4eae93f2c78e6f57ca0f463061737eb4e539790dc9b291bdb14b78bcb6
|
@@ -99,7 +99,6 @@ module Ruboty
|
|
99
99
|
# event handlers
|
100
100
|
|
101
101
|
def on_message(data)
|
102
|
-
data = resolve_mention!(data)
|
103
102
|
user = user_info(data['user']) || {}
|
104
103
|
|
105
104
|
channel = channel_info(data['channel'])
|
@@ -122,16 +121,18 @@ module Ruboty
|
|
122
121
|
to: channel_to,
|
123
122
|
channel: channel,
|
124
123
|
user: user,
|
125
|
-
mention_to: data['mention_to'],
|
126
124
|
time: Time.at(data['ts'].to_f)
|
127
125
|
}
|
128
126
|
|
129
|
-
|
127
|
+
text, mention_to = extract_mention(data['text'])
|
128
|
+
robot.receive(message_info.merge(body: text, mention_to: mention_to))
|
130
129
|
|
131
130
|
(data['attachments'] || []).each do |attachment|
|
132
|
-
body = attachment['fallback'] || "#{attachment['text']} #{attachment['pretext']}"
|
131
|
+
body, body_mention_to = extract_mention(attachment['fallback'] || "#{attachment['text']} #{attachment['pretext']}".strip)
|
133
132
|
|
134
|
-
|
133
|
+
unless body.empty?
|
134
|
+
robot.receive(message_info.merge(body: body, mention_to: body_mention_to))
|
135
|
+
end
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
@@ -150,18 +151,16 @@ module Ruboty
|
|
150
151
|
alias_method :on_bot_added, :on_user_change
|
151
152
|
alias_method :on_bot_changed, :on_user_change
|
152
153
|
|
153
|
-
def
|
154
|
-
|
155
|
-
|
156
|
-
data['mention_to'] = []
|
154
|
+
def extract_mention(text)
|
155
|
+
mention_to = []
|
157
156
|
|
158
|
-
|
157
|
+
text = (text || '').gsub(/\<\@(?<uid>[0-9A-Z]+)(?:\|(?<name>[^>]+))?\>/) do |_|
|
159
158
|
name = Regexp.last_match[:name]
|
160
159
|
|
161
160
|
unless name
|
162
161
|
user = user_info(Regexp.last_match[:uid])
|
163
162
|
|
164
|
-
|
163
|
+
mention_to << user
|
165
164
|
|
166
165
|
name = user['name']
|
167
166
|
end
|
@@ -169,7 +168,7 @@ module Ruboty
|
|
169
168
|
"@#{name}"
|
170
169
|
end
|
171
170
|
|
172
|
-
|
171
|
+
text.gsub!(/\<!subteam\^(?<usergroup_id>[0-9A-Z]+)(?:\|(?<handle>[^>]+))?\>/) do |_|
|
173
172
|
handle = Regexp.last_match[:handle]
|
174
173
|
|
175
174
|
unless handle
|
@@ -179,16 +178,16 @@ module Ruboty
|
|
179
178
|
"#{handle}"
|
180
179
|
end
|
181
180
|
|
182
|
-
|
181
|
+
text.gsub!(/\<!(?<special>[^>|@]+)(\|\@[^>]+)?\>/) do |_|
|
183
182
|
"@#{Regexp.last_match[:special]}"
|
184
183
|
end
|
185
184
|
|
186
|
-
|
185
|
+
text.gsub!(/\<((?<link>[^>|]+)(?:\|(?<ref>[^>]*))?)\>/) do |_|
|
187
186
|
Regexp.last_match[:ref] || Regexp.last_match[:link]
|
188
187
|
end
|
189
188
|
|
190
189
|
|
191
|
-
|
190
|
+
text.gsub!(/\#(?<room_id>[A-Z0-9]+)/) do |_|
|
192
191
|
room_id = Regexp.last_match[:room_id]
|
193
192
|
msg = "##{room_id}"
|
194
193
|
|
@@ -199,7 +198,7 @@ module Ruboty
|
|
199
198
|
msg
|
200
199
|
end
|
201
200
|
|
202
|
-
|
201
|
+
[CGI.unescapeHTML(text), mention_to]
|
203
202
|
end
|
204
203
|
|
205
204
|
def resolve_send_mention(text)
|