slack-bot-server 0.4.3 → 0.4.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/slack_bot_server/bot.rb +12 -7
- data/lib/slack_bot_server/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: 58eb298f86ae1232eae9487d0fc28c27eb15a9b4
|
|
4
|
+
data.tar.gz: 7cfe32f6ff625b0e6cee19872378d50021502396
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 906ea70d84f329a2b4ef0e3968c33dd32892d55a7c3d6db18f6a9d9ba1cfbf3177587f9bf0ae6399e371ffdcbe0312231c18e44f132088140cb9942fcb4219a7
|
|
7
|
+
data.tar.gz: 963d701368d4038051b42d63b1869831fb3c03163b9bce3737822e2a8df5fbe4c44407851e8c4ebeb4cb0cc21703b2ea67c84d81ee317463403d1005b68605a6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## Unreleased
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
### Changes
|
|
6
|
+
- Add new bot-private API method `user_message?(data)`, which returns true if the message is some utterance from a user
|
|
7
|
+
- Allow replying from the low-level `on(:message)` callback, although caution should be exercised when doing this (i.e. make sure you aren't replying to bot or other low-level API messages!)
|
|
8
|
+
|
|
3
9
|
## 0.4.3
|
|
4
10
|
|
|
5
11
|
### Changes
|
data/lib/slack_bot_server/bot.rb
CHANGED
|
@@ -111,7 +111,7 @@ class SlackBotServer::Bot
|
|
|
111
111
|
# @param options [Hash] As {#say}, although the +:channel+ option is
|
|
112
112
|
# redundant
|
|
113
113
|
def reply(options)
|
|
114
|
-
channel = @
|
|
114
|
+
channel = @last_received_user_message.channel
|
|
115
115
|
say(options.merge(channel: channel))
|
|
116
116
|
end
|
|
117
117
|
|
|
@@ -129,7 +129,7 @@ class SlackBotServer::Bot
|
|
|
129
129
|
# @param options [Hash] can contain +:channel+, which should be an ID; if no options
|
|
130
130
|
# are provided, the channel from the most recently recieved message is used
|
|
131
131
|
def typing(options={})
|
|
132
|
-
last_received_channel = @
|
|
132
|
+
last_received_channel = @last_received_user_message ? @last_received_user_message.channel : nil
|
|
133
133
|
default_options = {channel: last_received_channel}
|
|
134
134
|
@client.typing(default_options.merge(options))
|
|
135
135
|
end
|
|
@@ -158,6 +158,7 @@ class SlackBotServer::Bot
|
|
|
158
158
|
@client.on :message do |data|
|
|
159
159
|
begin
|
|
160
160
|
debug message: data
|
|
161
|
+
@last_received_user_message = data if user_message?(data)
|
|
161
162
|
handle_message(data)
|
|
162
163
|
rescue => e
|
|
163
164
|
log error: e
|
|
@@ -311,8 +312,8 @@ class SlackBotServer::Bot
|
|
|
311
312
|
(data.text =~ /\A(#{mention_keywords.join('|')})[\s\:](.*)/i ||
|
|
312
313
|
data.text =~ /\A(<@#{bot_user_id}>)[\s\:](.*)/)
|
|
313
314
|
message = $2.strip
|
|
314
|
-
@
|
|
315
|
-
instance_exec(@
|
|
315
|
+
@last_received_user_message.merge!(message: message)
|
|
316
|
+
instance_exec(@last_received_user_message, &block)
|
|
316
317
|
end
|
|
317
318
|
end
|
|
318
319
|
end
|
|
@@ -322,9 +323,9 @@ class SlackBotServer::Bot
|
|
|
322
323
|
def on_im(&block)
|
|
323
324
|
on(:message) do |data|
|
|
324
325
|
debug on_im: data, bot_message: bot_message?(data), is_im_channel: is_im_channel?(data.channel)
|
|
325
|
-
if
|
|
326
|
-
@
|
|
327
|
-
instance_exec(@
|
|
326
|
+
if !bot_message?(data) && is_im_channel?(data.channel)
|
|
327
|
+
@last_received_user_message.merge!(message: data.text)
|
|
328
|
+
instance_exec(@last_received_user_message, &block)
|
|
328
329
|
end
|
|
329
330
|
end
|
|
330
331
|
end
|
|
@@ -391,6 +392,10 @@ class SlackBotServer::Bot
|
|
|
391
392
|
data.previous_message.user == bot_user_id
|
|
392
393
|
end
|
|
393
394
|
|
|
395
|
+
def user_message?(data)
|
|
396
|
+
!bot_message?(data) && data.subtype.nil?
|
|
397
|
+
end
|
|
398
|
+
|
|
394
399
|
def rtm_incompatible_message?(data)
|
|
395
400
|
!(data[:attachments].nil? &&
|
|
396
401
|
data[:username].nil? &&
|