slack-bot-server 0.4.3 → 0.4.4

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: 504c4decb4b2eacb0315295a18eced229b625964
4
- data.tar.gz: 212c468b3d11018a48c966a1db9b4152f61b4f49
3
+ metadata.gz: 58eb298f86ae1232eae9487d0fc28c27eb15a9b4
4
+ data.tar.gz: 7cfe32f6ff625b0e6cee19872378d50021502396
5
5
  SHA512:
6
- metadata.gz: f93f32bd83af717a663f5e995eea4678f24c5b2db744dbec043e40e5b7a79e52823130cbd22bad4821e87c89c429cd5322d06bccd12d04087ed9f410a6d313a2
7
- data.tar.gz: a277171fd3fa7b384118992cf1b2d80777ab3ea05bbcbd2156f241c64d1063321190364b263d9e7497944aa991f88420cbfb01a5c6b6cc1328fbe8fae49b58c0
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
@@ -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 = @last_received_data.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 = @last_received_data ? @last_received_data.channel : nil
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
- @last_received_data = data.merge(message: message)
315
- instance_exec(@last_received_data, &block)
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 is_im_channel?(data.channel) && !bot_message?(data)
326
- @last_received_data = data.merge(message: data.text)
327
- instance_exec(@last_received_data, &block)
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? &&
@@ -1,4 +1,4 @@
1
1
  module SlackBotServer
2
2
  # The current version of the +SlackBotServer+ framework
3
- VERSION = "0.4.3"
3
+ VERSION = "0.4.4"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-bot-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Adam