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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f77e6ea5e7b18b37c9552ff4a2bdd4f49e543ef7
4
- data.tar.gz: ad5c8c7c9f66110e4b67cffa8fa851d5fada7886
3
+ metadata.gz: 359ba35900b7f5a50ae244f89d0ef51b7d83ab44
4
+ data.tar.gz: 292b9ec04aad2813568975987433471fd48288ed
5
5
  SHA512:
6
- metadata.gz: f3e6d5f9ca604bacb69ff8bcf0f6b91c95a00c7470d0e5666b5584382c789b9ebf785b2a8202a76f719b594bd0e78495217097876be2e0ac08391f4bf771024a
7
- data.tar.gz: 2559a3b14c72ff93ca8a0e859a64071cc43e34366da65a78a350a02eed262d6be8051dbbed864f369d67a22e46cf0412ec3894c0cb8ced46f555f48e34516fa8
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
- robot.receive(message_info.merge(body: CGI.unescapeHTML(data['text'])))
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
- robot.receive(message_info.merge(body: CGI.unescapeHTML(body))) unless body.empty?
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 resolve_mention!(data)
154
- data = data.dup
155
-
156
- data['mention_to'] = []
154
+ def extract_mention(text)
155
+ mention_to = []
157
156
 
158
- data['text'] = (data['text'] || '').gsub(/\<\@(?<uid>[0-9A-Z]+)(?:\|(?<name>[^>]+))?\>/) do |_|
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
- data['mention_to'] << user
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
- data['text'].gsub!(/\<!subteam\^(?<usergroup_id>[0-9A-Z]+)(?:\|(?<handle>[^>]+))?\>/) do |_|
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
- data['text'].gsub!(/\<!(?<special>[^>|@]+)(\|\@[^>]+)?\>/) do |_|
181
+ text.gsub!(/\<!(?<special>[^>|@]+)(\|\@[^>]+)?\>/) do |_|
183
182
  "@#{Regexp.last_match[:special]}"
184
183
  end
185
184
 
186
- data['text'].gsub!(/\<((?<link>[^>|]+)(?:\|(?<ref>[^>]*))?)\>/) do |_|
185
+ text.gsub!(/\<((?<link>[^>|]+)(?:\|(?<ref>[^>]*))?)\>/) do |_|
187
186
  Regexp.last_match[:ref] || Regexp.last_match[:link]
188
187
  end
189
188
 
190
189
 
191
- data['text'].gsub!(/\#(?<room_id>[A-Z0-9]+)/) do |_|
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
- data
201
+ [CGI.unescapeHTML(text), mention_to]
203
202
  end
204
203
 
205
204
  def resolve_send_mention(text)
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module SlackRTM
3
- VERSION = '2.4.2'
3
+ VERSION = '2.4.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-slack_rtm
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Kusano