slack-ruby-bot 0.13.0 → 0.14.0

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
  SHA256:
3
- metadata.gz: f7cdc662d2370824e2b531aecde4c20b1f55e895e8e10d9c1804ca44a160b884
4
- data.tar.gz: 3b5e9e13786df070f3d400c96e4752b4a6e2608472ab889d30e20e3ba95df6d1
3
+ metadata.gz: 9ab5b8a4dc4ab10bd0f5ef08fa56f0f2a7fb0d9148012f2a37b0b4fd2d8636af
4
+ data.tar.gz: b819aedc03a60e8ef5dea3798c42c8ba0a549437f3df81c0e666ac07a0038ab2
5
5
  SHA512:
6
- metadata.gz: 1018f35fb9be750feaf55a420b7ed6faa305e3e3ff6ea6e271db16951e898893b1a96ad184103e37a47e24f28adef7cecee02788821c37ac34e0f7f916620d5a
7
- data.tar.gz: a838815a6d65920fe1e1602e606e3bb73ab55c0176c9f565166f87d8cc643b42e37ab785f672ea651d2a156e93de68bf0eeff16b5237da0e6a75b7a98d7c2490
6
+ metadata.gz: e669b128e63dc889ea502837c7fd0cc74c19c5c4cc03e63e4076e08546899a5801f52f0cb142502990e748eb14287c73199443a60f3cbaae8cb09e59690a2eb6
7
+ data.tar.gz: ba46b14a83edcc108de08d231079f1c91f8d880f2aa8ae518f60686048d395f8e5c966dc44893d165a0934d22b6e712999aea09be93db0249248ad80d54772b4
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-03-28 18:37:09 -0400 using RuboCop version 0.80.1.
3
+ # on 2020-03-31 08:37:36 -0400 using RuboCop version 0.80.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -39,10 +39,11 @@ Style/AccessModifierDeclarations:
39
39
  Exclude:
40
40
  - 'lib/slack-ruby-bot/hooks/hook_support.rb'
41
41
 
42
- # Offense count: 1
42
+ # Offense count: 3
43
43
  Style/DoubleNegation:
44
44
  Exclude:
45
45
  - 'lib/slack-ruby-bot/commands/base.rb'
46
+ - 'lib/slack-ruby-bot/config.rb'
46
47
 
47
48
  # Offense count: 1
48
49
  # Cop supports --auto-correct.
@@ -1,3 +1,7 @@
1
+ ### 0.14.0 (2020/4/2)
2
+
3
+ * [#250](https://github.com/slack-ruby/slack-ruby-bot/pull/250): Added `config.allow_bot_messages`, defaults to `false` - [@dblock](https://github.com/dblock).
4
+
1
5
  ### 0.13.0 (2020/3/28)
2
6
 
3
7
  * [#244](https://github.com/slack-ruby/slack-ruby-bot/pull/244): Change log message when the bot is reconnected - [@wasabigeek](https://github.com/wasabigeek).
@@ -1,8 +1,8 @@
1
1
  ## Installation
2
2
 
3
- To integrate your bot with Slack, you must first create a new [Slack App](https://api.slack.com/apps).
3
+ To integrate your bot with Slack, you must first create a new [Classic Slack App](https://api.slack.com/authentication/migration#classic) and a [legacy bot](https://api.slack.com/legacy/custom-integrations/bot-users).
4
4
 
5
- ![](screenshots/create-app.png)
5
+ ![](screenshots/create-classic-app.png)
6
6
 
7
7
  ### Environment
8
8
 
data/README.md CHANGED
@@ -19,7 +19,8 @@ If you are not familiar with Slack bots or Slack API concepts, you might want to
19
19
 
20
20
  ## Stable Release
21
21
 
22
- You're reading the documentation for the **stable** release of slack-ruby-bot, v0.13.0. See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
22
+ You're reading the documentation for the **stable** release of slack-ruby-bot, v0.14.0.
23
+ See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
23
24
 
24
25
  ## Usage
25
26
 
@@ -470,6 +471,16 @@ server.hooks.add(:hello, ->(client, data) { puts "Hello!" })
470
471
 
471
472
  ```
472
473
 
474
+ ### Bot Message Protection
475
+
476
+ By default bots do not respond to self or other bots. If you wish to change that behavior, set `allow_bot_messages` to `true`.
477
+
478
+ ```ruby
479
+ SlackRubyBot.configure do |config|
480
+ config.allow_bot_messages = true
481
+ end
482
+ ```
483
+
473
484
  ### Message Loop Protection
474
485
 
475
486
  By default bots do not respond to their own messages. If you wish to change that behavior, set `allow_message_loops` to `true`.
@@ -1,6 +1,20 @@
1
1
  Upgrading SlackRubyBot
2
2
  ======================
3
3
 
4
+ ### Upgrading to >= 0.14.0
5
+
6
+ #### Bot Messages Disabled
7
+
8
+ By default bots will no longer respond to other bots. This caused confusing "I don't understand this command." errors when DMing the bot and rendering URLs that were being sent back as DMs. If you wish to restore the old behavior, set `allow_bot_messages` to `true`.
9
+
10
+ ```ruby
11
+ SlackRubyBot.configure do |config|
12
+ config.allow_bot_messages = true
13
+ end
14
+ ```
15
+
16
+ See [#250](https://github.com/slack-ruby/slack-ruby-bot/pull/250) for more information.
17
+
4
18
  ### Upgrading to >= 0.13.0
5
19
 
6
20
  #### Minimum Ruby Version
@@ -2,5 +2,5 @@
2
2
 
3
3
  source 'http://rubygems.org'
4
4
 
5
- gem 'celluloid-io'
5
+ gem 'async-websocket', '~> 0.8.0'
6
6
  gem 'slack-ruby-bot', path: '../..'
@@ -4,11 +4,15 @@ module SlackRubyBot
4
4
  module Config
5
5
  extend self
6
6
 
7
- ATTRS = %i[token url aliases user user_id team team_id allow_message_loops send_gifs logger].freeze
7
+ ATTRS = %i[token url aliases user user_id team team_id allow_bot_messages allow_message_loops send_gifs logger].freeze
8
8
  attr_accessor(*ATTRS)
9
9
 
10
+ def allow_bot_messages?
11
+ !!allow_bot_messages
12
+ end
13
+
10
14
  def allow_message_loops?
11
- allow_message_loops
15
+ !!allow_message_loops
12
16
  end
13
17
 
14
18
  def send_gifs?
@@ -5,6 +5,7 @@ module SlackRubyBot
5
5
  class Message
6
6
  def call(client, data)
7
7
  return if message_to_self_not_allowed? && message_to_self?(client, data)
8
+ return if bot_message_not_allowed? && bot_message?(client, data)
8
9
 
9
10
  data.text = data.text.strip if data.text
10
11
  result = child_command_classes.detect { |d| d.invoke(client, data) }
@@ -23,6 +24,14 @@ module SlackRubyBot
23
24
  client.self && client.self.id == data.user
24
25
  end
25
26
 
27
+ def bot_message_not_allowed?
28
+ !SlackRubyBot::Config.allow_bot_messages?
29
+ end
30
+
31
+ def bot_message?(_client, data)
32
+ data.subtype == 'bot_message'
33
+ end
34
+
26
35
  #
27
36
  # All commands.
28
37
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlackRubyBot
4
- VERSION = '0.13.0'
4
+ VERSION = '0.14.0'
5
5
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe SlackRubyBot::App do
4
+ def app
5
+ SlackRubyBot::App.new
6
+ end
7
+
8
+ let(:client) { subject.send(:client) }
9
+ let(:message_hook) { SlackRubyBot::Hooks::Message.new }
10
+
11
+ context 'default' do
12
+ it 'does not respond to bot messages' do
13
+ expect(client).to_not receive(:message)
14
+ message_hook.call(client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} hi", subtype: 'bot_message'))
15
+ end
16
+ end
17
+ context 'with allow_bot_messages=true' do
18
+ before do
19
+ SlackRubyBot::Config.allow_bot_messages = true
20
+ end
21
+ it 'responds to self' do
22
+ expect(client).to receive(:message)
23
+ message_hook.call(client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} hi", subtype: 'bot_message'))
24
+ end
25
+ end
26
+ end
@@ -50,6 +50,24 @@ describe SlackRubyBot::Hooks::Message do
50
50
  end
51
51
  end
52
52
  end
53
+ describe '#bot_message_not_allowed?' do
54
+ context 'with allow_bot_messages set to true' do
55
+ before do
56
+ SlackRubyBot::Config.allow_bot_messages = true
57
+ end
58
+ it do
59
+ expect(message_hook.send(:bot_message_not_allowed?)).to be false
60
+ end
61
+ end
62
+ context 'with allow_bot_messages set to false' do
63
+ before do
64
+ SlackRubyBot::Config.allow_bot_messages = false
65
+ end
66
+ it do
67
+ expect(message_hook.send(:bot_message_not_allowed?)).to be true
68
+ end
69
+ end
70
+ end
53
71
  describe '#message_to_self?' do
54
72
  let(:client) { Hashie::Mash.new(self: { 'id' => 'U0K8CKKT1' }) }
55
73
  context 'with message to self' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-28 00:00:00.000000000 Z
11
+ date: 2020-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -207,7 +207,7 @@ files:
207
207
  - lib/slack-ruby-bot/version.rb
208
208
  - lib/slack_ruby_bot.rb
209
209
  - screenshots/aliases.gif
210
- - screenshots/create-app.png
210
+ - screenshots/create-classic-app.png
211
211
  - screenshots/demo.gif
212
212
  - screenshots/dms.gif
213
213
  - screenshots/help.png
@@ -221,6 +221,7 @@ files:
221
221
  - spec/slack-ruby-bot/commands/aliases_spec.rb
222
222
  - spec/slack-ruby-bot/commands/attachment_spec.rb
223
223
  - spec/slack-ruby-bot/commands/bot_message_spec.rb
224
+ - spec/slack-ruby-bot/commands/bot_messages_spec.rb
224
225
  - spec/slack-ruby-bot/commands/bot_spec.rb
225
226
  - spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
226
227
  - spec/slack-ruby-bot/commands/commands_permitted_spec.rb
@@ -295,6 +296,7 @@ test_files:
295
296
  - spec/slack-ruby-bot/commands/aliases_spec.rb
296
297
  - spec/slack-ruby-bot/commands/attachment_spec.rb
297
298
  - spec/slack-ruby-bot/commands/bot_message_spec.rb
299
+ - spec/slack-ruby-bot/commands/bot_messages_spec.rb
298
300
  - spec/slack-ruby-bot/commands/bot_spec.rb
299
301
  - spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
300
302
  - spec/slack-ruby-bot/commands/commands_permitted_spec.rb
Binary file