slack-ruby-bot 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +8 -4
- data/CHANGELOG.md +15 -10
- data/README.md +12 -0
- data/lib/slack-ruby-bot/commands/base.rb +3 -2
- data/lib/slack-ruby-bot/config.rb +1 -0
- data/lib/slack-ruby-bot/hooks/message.rb +1 -0
- data/lib/slack-ruby-bot/version.rb +1 -1
- data/slack.png +0 -0
- data/spec/slack-ruby-bot/commands/match_spec.rb +17 -0
- data/spec/slack-ruby-bot/commands/message_loop_spec.rb +34 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7cc27a7b3b83580c0e59dfc18919ac3a6ec68c4
|
4
|
+
data.tar.gz: af0fd175600080e47df3d3285bc9aa0ad665c95e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc4d80b5c27530ddb7d53e7043e75e44420d2ea3f57ee1aff16993dce0bc22f848523f00982d0f6cd153e90aed0bf4b8dafc622d2474e572b44f949432e6a2ff
|
7
|
+
data.tar.gz: eb6b9f4a8b1233256040854dc9d8642826e3743453b72708adab1f2854be83160bccd5caa7fca767803af09428394758a846babf099ddacacadc3edff68c9e92
|
data/.rubocop_todo.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-
|
2
|
+
# on 2015-10-28 17:37:44 -0700 using RuboCop version 0.32.1.
|
3
3
|
# The point is for the user to remove these configuration records
|
4
4
|
# one by one as the offenses are removed from the code base.
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
@@ -13,15 +13,15 @@ Lint/HandleExceptions:
|
|
13
13
|
Lint/UselessAccessModifier:
|
14
14
|
Enabled: false
|
15
15
|
|
16
|
-
# Offense count:
|
16
|
+
# Offense count: 5
|
17
17
|
Metrics/AbcSize:
|
18
18
|
Max: 23
|
19
19
|
|
20
|
-
# Offense count:
|
20
|
+
# Offense count: 2
|
21
21
|
Metrics/CyclomaticComplexity:
|
22
22
|
Max: 7
|
23
23
|
|
24
|
-
# Offense count:
|
24
|
+
# Offense count: 91
|
25
25
|
# Configuration parameters: AllowURI, URISchemes.
|
26
26
|
Metrics/LineLength:
|
27
27
|
Max: 142
|
@@ -31,6 +31,10 @@ Metrics/LineLength:
|
|
31
31
|
Metrics/MethodLength:
|
32
32
|
Max: 21
|
33
33
|
|
34
|
+
# Offense count: 1
|
35
|
+
Metrics/PerceivedComplexity:
|
36
|
+
Max: 8
|
37
|
+
|
34
38
|
# Offense count: 15
|
35
39
|
Style/Documentation:
|
36
40
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,32 @@
|
|
1
|
-
### 0.4.
|
1
|
+
### 0.4.5 (10/29/2015)
|
2
2
|
|
3
|
-
* [#
|
4
|
-
* [#
|
5
|
-
|
6
|
-
|
3
|
+
* [#23](https://github.com/dblock/slack-ruby-bot/pull/23): Fixed `match` that forced bot name into the expression being evaluated - [@dblock](https://github.com/dblock).
|
4
|
+
* [#22](https://github.com/dblock/slack-ruby-bot/issues/22), [slack-ruby-client#17](https://github.com/dblock/slack-ruby-client/issues/17): Do not respond to messages from self, override with `allow_message_loops` - [@dblock](https://github.com/dblock).
|
5
|
+
|
6
|
+
### 0.4.4 (10/5/2015)
|
7
|
+
|
8
|
+
* [#17](https://github.com/dblock/slack-ruby-bot/issues/17): Address bot by `name:` - [@dblock](https://github.com/dblock).
|
9
|
+
* [#19](https://github.com/dblock/slack-ruby-bot/issues/19): Retry on `Faraday::Error::TimeoutError`, `TimeoutError` and `SSLError` - [@dblock](https://github.com/dblock).
|
10
|
+
* [#3](https://github.com/dblock/slack-ruby-bot/issues/3): Retry on `migration_in_progress` errors during `rtm.start` - [@dblock](https://github.com/dblock).
|
11
|
+
* Respond to direct messages without being addressed by name - [@dblock](https://github.com/dblock).
|
7
12
|
* Added `send_gif`, to allow GIFs to be sent without text - [@maclover7](https://github.com/maclover7).
|
8
13
|
|
9
14
|
### 0.4.3 (8/21/2015)
|
10
15
|
|
11
|
-
* [#13](https://github.com/dblock/slack-ruby-bot/issues/13): You can now address the bot by its Slack @id - [@dblock](https://
|
16
|
+
* [#13](https://github.com/dblock/slack-ruby-bot/issues/13): You can now address the bot by its Slack @id - [@dblock](https://github.com/dblock).
|
12
17
|
|
13
18
|
### 0.4.2 (8/20/2015)
|
14
19
|
|
15
|
-
* [#12](https://github.com/dblock/slack-ruby-bot/issues/12): Added support for bot aliases - [@dblock](https://
|
20
|
+
* [#12](https://github.com/dblock/slack-ruby-bot/issues/12): Added support for bot aliases - [@dblock](https://github.com/dblock).
|
16
21
|
|
17
22
|
### 0.4.1 (7/25/2015)
|
18
23
|
|
19
|
-
* Use a real client in `respond_with_slack_message` expectaions - [@dblock](https://
|
24
|
+
* Use a real client in `respond_with_slack_message` expectaions - [@dblock](https://github.com/dblock).
|
20
25
|
|
21
26
|
### 0.4.0 (7/25/2015)
|
22
27
|
|
23
|
-
* Using [slack-ruby-client](https://github.com/dblock/slack-ruby-client) - [@dblock](https://
|
24
|
-
* Use RealTime API to post messages - [@dblock](https://
|
28
|
+
* Using [slack-ruby-client](https://github.com/dblock/slack-ruby-client) - [@dblock](https://github.com/dblock).
|
29
|
+
* Use RealTime API to post messages - [@dblock](https://github.com/dblock).
|
25
30
|
|
26
31
|
### 0.3.1 (7/21/2015)
|
27
32
|
|
data/README.md
CHANGED
@@ -6,6 +6,8 @@ Slack-Ruby-Bot
|
|
6
6
|
|
7
7
|
A generic Slack bot framework written in Ruby on top of [slack-ruby-client](https://github.com/dblock/slack-ruby-client). This library does all the heavy lifting, such as message parsing, so you can focus on implementing slack bot commands. It also attempts to introduce the bare minimum number of requirements or any sorts of limitations. It's a Slack bot boilerplate.
|
8
8
|
|
9
|
+
![](slack.png)
|
10
|
+
|
9
11
|
## Usage
|
10
12
|
|
11
13
|
### A Minimal Bot
|
@@ -193,6 +195,16 @@ module MyBot
|
|
193
195
|
end
|
194
196
|
```
|
195
197
|
|
198
|
+
### Message Loop Protection
|
199
|
+
|
200
|
+
By default bots do not respond to their own messages. If you wish to change that behavior, set `allow_message_loops` to `true`.
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
SlackRubyBot.configure do |config|
|
204
|
+
config.allow_message_loops = true
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
196
208
|
### RSpec Shared Behaviors
|
197
209
|
|
198
210
|
Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in your RSpec tests. Require 'slack-ruby-bot/rspec' in your `spec_helper.rb`.
|
@@ -54,10 +54,11 @@ module SlackRubyBot
|
|
54
54
|
|
55
55
|
def self.invoke(client, data)
|
56
56
|
self.finalize_routes!
|
57
|
-
expression = parse(data)
|
57
|
+
expression, text = parse(data)
|
58
58
|
called = false
|
59
59
|
routes.each_pair do |route, method|
|
60
60
|
match = route.match(expression)
|
61
|
+
match ||= route.match(text) if text
|
61
62
|
next unless match
|
62
63
|
next if match.names.include?('bot') && !SlackRubyBot.config.name?(match['bot'])
|
63
64
|
called = true
|
@@ -88,7 +89,7 @@ module SlackRubyBot
|
|
88
89
|
return text if td == name || td.starts_with?("#{name} ")
|
89
90
|
end
|
90
91
|
end
|
91
|
-
"#{SlackRubyBot.config.user} #{text}"
|
92
|
+
["#{SlackRubyBot.config.user} #{text}", text]
|
92
93
|
end
|
93
94
|
|
94
95
|
def self.finalize_routes!
|
@@ -5,6 +5,7 @@ module SlackRubyBot
|
|
5
5
|
|
6
6
|
def message(client, data)
|
7
7
|
data = Hashie::Mash.new(data)
|
8
|
+
return if !SlackRubyBot::Config.allow_message_loops && (client.self && client.self['id'] == data.user)
|
8
9
|
data.text.strip! if data.text
|
9
10
|
result = child_command_classes.detect { |d| d.invoke(client, data) }
|
10
11
|
result ||= built_in_command_classes.detect { |d| d.invoke(client, data) }
|
data/slack.png
ADDED
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlackRubyBot::Commands do
|
4
|
+
let! :command do
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
+
match(/^Reticulate (?<spline_name>\w*)$/) do |client, data, match|
|
7
|
+
send_message client, data.channel, "Reticulated #{match[:spline_name]}."
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def app
|
12
|
+
SlackRubyBot::App.new
|
13
|
+
end
|
14
|
+
it 'matches' do
|
15
|
+
expect(message: 'Reticulate spline').to respond_with_slack_message('Reticulated spline.')
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlackRubyBot::App do
|
4
|
+
def app
|
5
|
+
SlackRubyBot::App.new
|
6
|
+
end
|
7
|
+
let(:client) { subject.send(:client) }
|
8
|
+
before do
|
9
|
+
allow(client).to receive(:self).and_return('id' => 'UDEADBEEF')
|
10
|
+
allow(Giphy).to receive(:random)
|
11
|
+
end
|
12
|
+
context 'default' do
|
13
|
+
it 'does not respond to self' do
|
14
|
+
expect(SlackRubyBot::Commands::Base).to_not receive(:send_client_message)
|
15
|
+
subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
context 'with allow_message_loops=true' do
|
19
|
+
before do
|
20
|
+
SlackRubyBot.configure do |config|
|
21
|
+
config.allow_message_loops = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
after do
|
25
|
+
SlackRubyBot.configure do |config|
|
26
|
+
config.allow_message_loops = nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
it 'responds to self' do
|
30
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message)
|
31
|
+
subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
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.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- screenshots/register-bot.png
|
227
227
|
- screenshots/weather.gif
|
228
228
|
- slack-ruby-bot.gemspec
|
229
|
+
- slack.png
|
229
230
|
- spec/slack-ruby-bot/app_spec.rb
|
230
231
|
- spec/slack-ruby-bot/commands/about_spec.rb
|
231
232
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
@@ -237,6 +238,8 @@ files:
|
|
237
238
|
- spec/slack-ruby-bot/commands/empty_text_spec.rb
|
238
239
|
- spec/slack-ruby-bot/commands/help_spec.rb
|
239
240
|
- spec/slack-ruby-bot/commands/hi_spec.rb
|
241
|
+
- spec/slack-ruby-bot/commands/match_spec.rb
|
242
|
+
- spec/slack-ruby-bot/commands/message_loop_spec.rb
|
240
243
|
- spec/slack-ruby-bot/commands/nil_message_spec.rb
|
241
244
|
- spec/slack-ruby-bot/commands/not_implemented_spec.rb
|
242
245
|
- spec/slack-ruby-bot/commands/operators_spec.rb
|
@@ -284,6 +287,8 @@ test_files:
|
|
284
287
|
- spec/slack-ruby-bot/commands/empty_text_spec.rb
|
285
288
|
- spec/slack-ruby-bot/commands/help_spec.rb
|
286
289
|
- spec/slack-ruby-bot/commands/hi_spec.rb
|
290
|
+
- spec/slack-ruby-bot/commands/match_spec.rb
|
291
|
+
- spec/slack-ruby-bot/commands/message_loop_spec.rb
|
287
292
|
- spec/slack-ruby-bot/commands/nil_message_spec.rb
|
288
293
|
- spec/slack-ruby-bot/commands/not_implemented_spec.rb
|
289
294
|
- spec/slack-ruby-bot/commands/operators_spec.rb
|