slack-ruby-bot 0.3.1 → 0.4.0
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 +3 -8
- data/CHANGELOG.md +5 -0
- data/README.md +24 -10
- data/TUTORIAL.md +2 -2
- data/UPGRADING.md +64 -0
- data/examples/minimal/pongbot.rb +2 -2
- data/examples/weather/weatherbot.rb +2 -2
- data/lib/slack-ruby-bot/app.rb +5 -5
- data/lib/slack-ruby-bot/commands/about.rb +2 -2
- data/lib/slack-ruby-bot/commands/base.rb +10 -10
- data/lib/slack-ruby-bot/commands/help.rb +2 -2
- data/lib/slack-ruby-bot/commands/hi.rb +2 -2
- data/lib/slack-ruby-bot/commands/unknown.rb +2 -2
- data/lib/slack-ruby-bot/hooks/hello.rb +1 -1
- data/lib/slack-ruby-bot/hooks/message.rb +4 -4
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +2 -1
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +3 -2
- data/lib/slack-ruby-bot/version.rb +1 -1
- data/slack-ruby-bot.gemspec +1 -1
- data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +4 -4
- data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -2
- data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -2
- data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +4 -4
- data/spec/slack-ruby-bot/commands/empty_text_spec.rb +5 -4
- data/spec/slack-ruby-bot/commands/nil_message_spec.rb +4 -3
- data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -2
- data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +4 -4
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +2 -1
- data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +1 -1
- metadata +34 -34
- data/lib/initializers/slack/request.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3d7872ab2b68fdc72e14cf52cbcf37201d8b92c
|
4
|
+
data.tar.gz: 94a228decdfacb81a8058a0ae5979a1cb1019fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b28a955dfcc42e289fe74b885035fd456f75d10fcf20d7fef5dc69cb69ed0ac1c8afbab962e3bea835f541131b946e51d75d8514becb18ed83dd81c23850f42
|
7
|
+
data.tar.gz: d3f659a40cd9ee1bda675f020700eefc0a8bcd49bc5a4944992aac4e6636806eb835df6a320023fa73ef4582d626d4aac00efa2ffc1c4a595914525472638722
|
data/.rubocop_todo.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-07-19
|
2
|
+
# on 2015-07-25 19:18:18 -0400 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
|
@@ -15,9 +15,9 @@ Lint/UselessAccessModifier:
|
|
15
15
|
|
16
16
|
# Offense count: 2
|
17
17
|
Metrics/AbcSize:
|
18
|
-
Max:
|
18
|
+
Max: 23
|
19
19
|
|
20
|
-
# Offense count:
|
20
|
+
# Offense count: 51
|
21
21
|
# Configuration parameters: AllowURI, URISchemes.
|
22
22
|
Metrics/LineLength:
|
23
23
|
Max: 142
|
@@ -36,11 +36,6 @@ Style/Documentation:
|
|
36
36
|
Style/FileName:
|
37
37
|
Enabled: false
|
38
38
|
|
39
|
-
# Offense count: 1
|
40
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
41
|
-
Style/MethodName:
|
42
|
-
Enabled: false
|
43
|
-
|
44
39
|
# Offense count: 1
|
45
40
|
Style/ModuleFunction:
|
46
41
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.4.0 (7/25/2015)
|
2
|
+
|
3
|
+
* Using [slack-ruby-client](https://github.com/dblock/slack-ruby-client) - [@dblock](https://githubcom/dblock).
|
4
|
+
* Use RealTime API to post messages - [@dblock](https://githubcom/dblock).
|
5
|
+
|
1
6
|
### 0.3.1 (7/21/2015)
|
2
7
|
|
3
8
|
* [#8](https://github.com/dblock/slack-ruby-bot/issues/8): Fix: `undefined method `strip!' for nil:NilClass` on nil message - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -28,8 +28,8 @@ module PongBot
|
|
28
28
|
end
|
29
29
|
|
30
30
|
class Ping < SlackRubyBot::Commands::Base
|
31
|
-
command 'ping' do |data, _match|
|
32
|
-
|
31
|
+
command 'ping' do |client, data, _match|
|
32
|
+
client.message text: 'pong', channel: data.channel
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -61,8 +61,8 @@ Bots are addressed by name and respond to commands and operators. By default a c
|
|
61
61
|
class Phone < SlackRubyBot::Commands::Base
|
62
62
|
command 'call'
|
63
63
|
|
64
|
-
def self.call(data, _match)
|
65
|
-
send_message data.channel, 'called'
|
64
|
+
def self.call(client, data, _match)
|
65
|
+
send_message client, data.channel, 'called'
|
66
66
|
end
|
67
67
|
end
|
68
68
|
```
|
@@ -74,8 +74,8 @@ class Phone < SlackRubyBot::Commands::Base
|
|
74
74
|
command 'call'
|
75
75
|
command '呼び出し'
|
76
76
|
|
77
|
-
def self.call(data, _match)
|
78
|
-
send_message data.channel, 'called'
|
77
|
+
def self.call(client, data, _match)
|
78
|
+
send_message client, data.channel, 'called'
|
79
79
|
end
|
80
80
|
end
|
81
81
|
```
|
@@ -84,8 +84,8 @@ You can combine multiple commands and use a block to implement them.
|
|
84
84
|
|
85
85
|
```ruby
|
86
86
|
class Phone < SlackRubyBot::Commands::Base
|
87
|
-
command 'call', '呼び出し' do |data, _match|
|
88
|
-
send_message data.channel, 'called'
|
87
|
+
command 'call', '呼び出し' do |client, data, _match|
|
88
|
+
send_message client, data.channel, 'called'
|
89
89
|
end
|
90
90
|
end
|
91
91
|
```
|
@@ -110,14 +110,24 @@ Commands and operators are generic versions of bot routes. You can respond to ju
|
|
110
110
|
|
111
111
|
```ruby
|
112
112
|
class Weather < SlackRubyBot::Commands::Base
|
113
|
-
match /^How is the weather in (<?location>\w*)\?$/ do |data, match|
|
114
|
-
send_message data.channel, "The weather in #{match[:location]} is nice."
|
113
|
+
match /^How is the weather in (<?location>\w*)\?$/ do |client, data, match|
|
114
|
+
send_message client, data.channel, "The weather in #{match[:location]} is nice."
|
115
115
|
end
|
116
116
|
end
|
117
117
|
```
|
118
118
|
|
119
119
|
![](screenshots/weather.gif)
|
120
120
|
|
121
|
+
### SlackRubyBot::Commands::Base Functions
|
122
|
+
|
123
|
+
#### send_message(client, channel, text)
|
124
|
+
|
125
|
+
Send text using a RealTime client to a channel.
|
126
|
+
|
127
|
+
#### send_message_with_gif(client, channel, text, keyword)
|
128
|
+
|
129
|
+
Send text along with a random animated GIF based on a keyword.
|
130
|
+
|
121
131
|
### Built-In Commands
|
122
132
|
|
123
133
|
Slack-ruby-bot comes with several built-in commands. You can re-define built-in commands, normally, as described above.
|
@@ -146,6 +156,10 @@ Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in
|
|
146
156
|
|
147
157
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
148
158
|
|
159
|
+
## Upgrading
|
160
|
+
|
161
|
+
See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
|
162
|
+
|
149
163
|
## Copyright and License
|
150
164
|
|
151
165
|
Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
|
data/TUTORIAL.md
CHANGED
@@ -51,8 +51,8 @@ Create a folder called `slack-mathbot/commands` and inside of it create `calcula
|
|
51
51
|
module SlackMathbot
|
52
52
|
module Commands
|
53
53
|
class Calculate < SlackRubyBot::Commands::Base
|
54
|
-
command 'calculate' do |data, _match|
|
55
|
-
send_message data.channel, '4'
|
54
|
+
command 'calculate' do |client, data, _match|
|
55
|
+
send_message client, data.channel, '4'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Upgrading SlackRubyBot
|
2
|
+
======================
|
3
|
+
|
4
|
+
### Upgrading to >= 0.4.0
|
5
|
+
|
6
|
+
This version uses [slack-ruby-client](https://github.com/dblock/slack-ruby-client) instead of [slack-ruby-gem](https://github.com/aki017/slack-ruby-gem).
|
7
|
+
|
8
|
+
The command interface now takes a `client` parameter, which is the RealTime Messaging API instance. Add the new parameter to all `call` calls in classes that inherit from `SlackRubyBot::Commands::Base`.
|
9
|
+
|
10
|
+
Before:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
def self.call(data, match)
|
14
|
+
...
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
After:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
def self.call(client, data, match)
|
22
|
+
...
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
This also applies to `command`, `operator` and `match` blocks.
|
27
|
+
|
28
|
+
Before:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
command 'ping' do |data, match|
|
32
|
+
...
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
After:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
command 'ping' do |client, data, match|
|
40
|
+
...
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
You can now send messages directly via the RealTime Messaging API.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
client.message text: 'text', channel: 'channel'
|
48
|
+
```
|
49
|
+
|
50
|
+
Otherwise you must now pass the `client` parameter to `send_message` and `send_message_with_gif`.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
def self.call(client, data, match)
|
54
|
+
send_message client, data.channel, 'hello'
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
def self.call(client, data, match)
|
60
|
+
send_message_with_gif client, data.channel, 'hello', 'hi'
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
|
data/examples/minimal/pongbot.rb
CHANGED
@@ -5,8 +5,8 @@ module WeatherBot
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class Weather < SlackRubyBot::Commands::Base
|
8
|
-
match(/^How is the weather in (?<location>\w*)\?$/i) do |data, match|
|
9
|
-
send_message data.channel, "The weather in #{match[:location]} is nice."
|
8
|
+
match(/^How is the weather in (?<location>\w*)\?$/i) do |client, data, match|
|
9
|
+
send_message client, data.channel, "The weather in #{match[:location]} is nice."
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/slack-ruby-bot/app.rb
CHANGED
@@ -42,22 +42,22 @@ module SlackRubyBot
|
|
42
42
|
|
43
43
|
def start!
|
44
44
|
loop do
|
45
|
-
client.start
|
45
|
+
client.start!
|
46
46
|
@client = nil
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def client
|
51
51
|
@client ||= begin
|
52
|
-
client = Slack.
|
52
|
+
client = Slack::RealTime::Client.new
|
53
53
|
hooks.each do |hook|
|
54
54
|
client.on hook do |data|
|
55
55
|
begin
|
56
|
-
send hook, data
|
56
|
+
send hook, client, data
|
57
57
|
rescue StandardError => e
|
58
58
|
logger.error e
|
59
59
|
begin
|
60
|
-
|
60
|
+
client.message(channel: data['channel'], text: e.message) if data.key?('channel')
|
61
61
|
rescue
|
62
62
|
# ignore
|
63
63
|
end
|
@@ -69,7 +69,7 @@ module SlackRubyBot
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def auth!
|
72
|
-
auth =
|
72
|
+
auth = client.web_client.auth_test
|
73
73
|
SlackRubyBot.configure do |config|
|
74
74
|
config.url = auth['url']
|
75
75
|
config.team = auth['team']
|
@@ -4,8 +4,8 @@ module SlackRubyBot
|
|
4
4
|
command 'about'
|
5
5
|
match(/^(?<bot>\w*)$/)
|
6
6
|
|
7
|
-
def self.call(data, _match)
|
8
|
-
send_message_with_gif data.channel, SlackRubyBot::ABOUT, 'selfie'
|
7
|
+
def self.call(client, data, _match)
|
8
|
+
send_message_with_gif client, data.channel, SlackRubyBot::ABOUT, 'selfie'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -3,15 +3,15 @@ module SlackRubyBot
|
|
3
3
|
class Base
|
4
4
|
class_attribute :routes
|
5
5
|
|
6
|
-
def self.send_message(channel, text, options = {
|
6
|
+
def self.send_message(client, channel, text, options = {})
|
7
7
|
if text && text.length > 0
|
8
|
-
|
8
|
+
send_client_message(client, { channel: channel, text: text }.merge(options))
|
9
9
|
else
|
10
|
-
send_message_with_gif channel, 'Nothing to see here.', 'nothing', options
|
10
|
+
send_message_with_gif client, channel, 'Nothing to see here.', 'nothing', options
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.send_message_with_gif(channel, text, keywords, options = {
|
14
|
+
def self.send_message_with_gif(client, channel, text, keywords, options = {})
|
15
15
|
gif = begin
|
16
16
|
Giphy.random(keywords)
|
17
17
|
rescue StandardError => e
|
@@ -19,7 +19,7 @@ module SlackRubyBot
|
|
19
19
|
nil
|
20
20
|
end
|
21
21
|
text = text + "\n" + gif.image_url.to_s if gif
|
22
|
-
send_message channel, text, options
|
22
|
+
send_message client, channel, text, options
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.logger
|
@@ -46,7 +46,7 @@ module SlackRubyBot
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.invoke(data)
|
49
|
+
def self.invoke(client, data)
|
50
50
|
self.finalize_routes!
|
51
51
|
expression = data.text
|
52
52
|
called = false
|
@@ -56,9 +56,9 @@ module SlackRubyBot
|
|
56
56
|
next if match.names.include?('bot') && match['bot'].downcase != SlackRubyBot.config.user
|
57
57
|
called = true
|
58
58
|
if method
|
59
|
-
method.call(data, match)
|
59
|
+
method.call(client, data, match)
|
60
60
|
elsif self.respond_to?(:call)
|
61
|
-
send(:call, data, match)
|
61
|
+
send(:call, client, data, match)
|
62
62
|
else
|
63
63
|
fail NotImplementedError, data.text
|
64
64
|
end
|
@@ -74,8 +74,8 @@ module SlackRubyBot
|
|
74
74
|
|
75
75
|
private
|
76
76
|
|
77
|
-
def self.
|
78
|
-
|
77
|
+
def self.send_client_message(client, data)
|
78
|
+
client.message(data)
|
79
79
|
end
|
80
80
|
|
81
81
|
def self.finalize_routes!
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module SlackRubyBot
|
2
2
|
module Commands
|
3
3
|
class Help < Base
|
4
|
-
def self.call(data, _match)
|
5
|
-
send_message_with_gif data.channel, 'See https://github.com/dblock/slack-ruby-bot, please.', 'help'
|
4
|
+
def self.call(client, data, _match)
|
5
|
+
send_message_with_gif client, data.channel, 'See https://github.com/dblock/slack-ruby-bot, please.', 'help'
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module SlackRubyBot
|
2
2
|
module Commands
|
3
3
|
class Hi < Base
|
4
|
-
def self.call(data, _match)
|
5
|
-
send_message_with_gif data.channel, "Hi <@#{data.user}>!", 'hi'
|
4
|
+
def self.call(client, data, _match)
|
5
|
+
send_message_with_gif client, data.channel, "Hi <@#{data.user}>!", 'hi'
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -3,8 +3,8 @@ module SlackRubyBot
|
|
3
3
|
class Unknown < Base
|
4
4
|
match(/^(?<bot>\w*)[\s]*(?<expression>.*)$/)
|
5
5
|
|
6
|
-
def self.call(data, _match)
|
7
|
-
send_message_with_gif data.channel, "Sorry <@#{data.user}>, I don't understand that command!", 'idiot'
|
6
|
+
def self.call(client, data, _match)
|
7
|
+
send_message_with_gif client, data.channel, "Sorry <@#{data.user}>, I don't understand that command!", 'idiot'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -3,12 +3,12 @@ module SlackRubyBot
|
|
3
3
|
module Message
|
4
4
|
extend Base
|
5
5
|
|
6
|
-
def message(data)
|
6
|
+
def message(client, data)
|
7
7
|
data = Hashie::Mash.new(data)
|
8
8
|
data.text.strip! if data.text
|
9
|
-
result = child_command_classes.detect { |d| d.invoke(data) }
|
10
|
-
result ||= built_in_command_classes.detect { |d| d.invoke(data) }
|
11
|
-
result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(data) }
|
9
|
+
result = child_command_classes.detect { |d| d.invoke(client, data) }
|
10
|
+
result ||= built_in_command_classes.detect { |d| d.invoke(client, data) }
|
11
|
+
result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(client, data) }
|
12
12
|
result
|
13
13
|
end
|
14
14
|
|
@@ -6,7 +6,8 @@ RSpec::Matchers.define :respond_with_error do |error, error_message|
|
|
6
6
|
allow(Giphy).to receive(:random)
|
7
7
|
begin
|
8
8
|
expect do
|
9
|
-
app.send(:
|
9
|
+
client = app.send(:client)
|
10
|
+
app.send(:message, client, text: message, channel: channel, user: user)
|
10
11
|
end.to raise_error error, error_message
|
11
12
|
rescue RSpec::Expectations::ExpectationNotMetError => e
|
12
13
|
@error_message = e.message
|
@@ -4,8 +4,9 @@ RSpec::Matchers.define :respond_with_slack_message do |expected|
|
|
4
4
|
match do |actual|
|
5
5
|
channel, user, message = parse(actual)
|
6
6
|
allow(Giphy).to receive(:random)
|
7
|
-
|
8
|
-
|
7
|
+
client = double(Slack::RealTime::Client)
|
8
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: channel, text: expected)
|
9
|
+
app.send(:message, client, text: message, channel: channel, user: user)
|
9
10
|
true
|
10
11
|
end
|
11
12
|
|
data/slack-ruby-bot.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.licenses = ['MIT']
|
16
16
|
s.summary = 'The easiest way to write a Slack bot in Ruby.'
|
17
17
|
s.add_dependency 'hashie'
|
18
|
-
s.add_dependency 'slack-
|
18
|
+
s.add_dependency 'slack-ruby-client'
|
19
19
|
s.add_dependency 'activesupport'
|
20
20
|
s.add_dependency 'giphy', '~> 2.0.2'
|
21
21
|
s.add_dependency 'websocket-driver', '~> 0.5.4'
|
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe SlackRubyBot::Commands do
|
4
4
|
let! :command do
|
5
5
|
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
-
command 'tomato' do |data, match|
|
7
|
-
send_message data.channel, "#{match[:command]}: #{match[:expression]}"
|
6
|
+
command 'tomato' do |client, data, match|
|
7
|
+
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
|
8
8
|
end
|
9
9
|
|
10
|
-
command 'tomatoes' do |data, match|
|
11
|
-
send_message data.channel, "#{match[:command]}: #{match[:expression]}"
|
10
|
+
command 'tomatoes' do |client, data, match|
|
11
|
+
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -3,8 +3,8 @@ require 'spec_helper'
|
|
3
3
|
describe SlackRubyBot::Commands do
|
4
4
|
let! :command do
|
5
5
|
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
-
command 'space' do |data, match|
|
7
|
-
send_message data.channel, "#{match[:command]}: #{match[:expression]}"
|
6
|
+
command 'space' do |client, data, match|
|
7
|
+
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -6,8 +6,8 @@ describe SlackRubyBot::Commands do
|
|
6
6
|
command 'sayhi'
|
7
7
|
command 'saybye'
|
8
8
|
|
9
|
-
def self.call(data, match)
|
10
|
-
send_message data.channel, "#{match[:command]}: #{match[:expression]}"
|
9
|
+
def self.call(client, data, match)
|
10
|
+
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe SlackRubyBot::Commands do
|
4
4
|
let! :command do
|
5
5
|
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
-
command 'sayhi' do |data, match|
|
7
|
-
send_message data.channel, "#{match[:command]}: #{match[:expression]}"
|
6
|
+
command 'sayhi' do |client, data, match|
|
7
|
+
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
|
8
8
|
end
|
9
9
|
|
10
|
-
command 'one', 'two' do |data, match|
|
11
|
-
send_message data.channel, "#{match[:command]}: #{match[:expression]}"
|
10
|
+
command 'one', 'two' do |client, data, match|
|
11
|
+
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -5,17 +5,18 @@ describe SlackRubyBot::Commands do
|
|
5
5
|
Class.new(SlackRubyBot::Commands::Base) do
|
6
6
|
command 'empty_text'
|
7
7
|
|
8
|
-
def self.call(data, _match)
|
9
|
-
send_message data.channel, nil
|
8
|
+
def self.call(client, data, _match)
|
9
|
+
send_message client, data.channel, nil
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
def app
|
14
14
|
SlackRubyBot::App.new
|
15
15
|
end
|
16
|
+
let(:client) { app.send(:client) }
|
16
17
|
it 'sends default text' do
|
17
18
|
allow(Giphy).to receive(:random)
|
18
|
-
expect(SlackRubyBot::Commands::Base).to receive(:send_message_with_gif).with('channel', 'Nothing to see here.', 'nothing',
|
19
|
-
app.send(:message, text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user')
|
19
|
+
expect(SlackRubyBot::Commands::Base).to receive(:send_message_with_gif).with(client, 'channel', 'Nothing to see here.', 'nothing', {})
|
20
|
+
app.send(:message, client, text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user')
|
20
21
|
end
|
21
22
|
end
|
@@ -5,17 +5,18 @@ describe SlackRubyBot::Commands do
|
|
5
5
|
Class.new(SlackRubyBot::Commands::Base) do
|
6
6
|
command 'nil_text'
|
7
7
|
|
8
|
-
def self.call(data, _match)
|
9
|
-
send_message data.channel, nil
|
8
|
+
def self.call(_client, data, _match)
|
9
|
+
send_message cilent, data.channel, nil
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
def app
|
14
14
|
SlackRubyBot::App.new
|
15
15
|
end
|
16
|
+
let(:client) { app.send(:client) }
|
16
17
|
it 'ignores nil messages' do
|
17
18
|
allow(Giphy).to receive(:random)
|
18
19
|
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message_with_gif)
|
19
|
-
app.send(:message, text: nil, channel: 'channel', user: 'user')
|
20
|
+
app.send(:message, client, text: nil, channel: 'channel', user: 'user')
|
20
21
|
end
|
21
22
|
end
|
@@ -6,8 +6,8 @@ describe SlackRubyBot::Commands do
|
|
6
6
|
operator '='
|
7
7
|
operator '-'
|
8
8
|
|
9
|
-
def self.call(data, match)
|
10
|
-
send_message data.channel, "#{match[:operator]}: #{match[:expression]}"
|
9
|
+
def self.call(client, data, match)
|
10
|
+
send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe SlackRubyBot::Commands do
|
4
4
|
let! :command do
|
5
5
|
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
-
operator '=' do |data, match|
|
7
|
-
send_message data.channel, "#{match[:operator]}: #{match[:expression]}"
|
6
|
+
operator '=' do |client, data, match|
|
7
|
+
send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
|
8
8
|
end
|
9
9
|
|
10
|
-
operator '+', '-' do |data, match|
|
11
|
-
send_message data.channel, "#{match[:operator]}: #{match[:expression]}"
|
10
|
+
operator '+', '-' do |client, data, match|
|
11
|
+
send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -4,11 +4,12 @@ describe SlackRubyBot::Commands::Unknown do
|
|
4
4
|
def app
|
5
5
|
SlackRubyBot::App.new
|
6
6
|
end
|
7
|
+
let(:client) { app.send(:client) }
|
7
8
|
it 'invalid command' do
|
8
9
|
expect(message: "#{SlackRubyBot.config.user} foobar").to respond_with_slack_message("Sorry <@user>, I don't understand that command!")
|
9
10
|
end
|
10
11
|
it 'does not respond to sad face' do
|
11
12
|
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message)
|
12
|
-
SlackRubyBot::App.new.send(:message, text: ':((')
|
13
|
+
SlackRubyBot::App.new.send(:message, client, text: ':((')
|
13
14
|
end
|
14
15
|
end
|
metadata
CHANGED
@@ -1,153 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.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: 2015-07-
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: slack-
|
28
|
+
name: slack-ruby-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: giphy
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.0.2
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.0.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: websocket-driver
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.5.4
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.5.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rack-test
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: vcr
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: webmock
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
@@ -170,11 +170,11 @@ executables: []
|
|
170
170
|
extensions: []
|
171
171
|
extra_rdoc_files: []
|
172
172
|
files:
|
173
|
-
- .gitignore
|
174
|
-
- .rspec
|
175
|
-
- .rubocop.yml
|
176
|
-
- .rubocop_todo.yml
|
177
|
-
- .travis.yml
|
173
|
+
- ".gitignore"
|
174
|
+
- ".rspec"
|
175
|
+
- ".rubocop.yml"
|
176
|
+
- ".rubocop_todo.yml"
|
177
|
+
- ".travis.yml"
|
178
178
|
- CHANGELOG.md
|
179
179
|
- CONTRIBUTING.md
|
180
180
|
- DEPLOYMENT.md
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- RELEASING.md
|
185
185
|
- Rakefile
|
186
186
|
- TUTORIAL.md
|
187
|
+
- UPGRADING.md
|
187
188
|
- examples/minimal/Gemfile
|
188
189
|
- examples/minimal/Gemfile.lock
|
189
190
|
- examples/minimal/pongbot.rb
|
@@ -193,7 +194,6 @@ files:
|
|
193
194
|
- lib/config/boot.rb
|
194
195
|
- lib/config/environment.rb
|
195
196
|
- lib/initializers/giphy.rb
|
196
|
-
- lib/initializers/slack/request.rb
|
197
197
|
- lib/slack-ruby-bot.rb
|
198
198
|
- lib/slack-ruby-bot/about.rb
|
199
199
|
- lib/slack-ruby-bot/app.rb
|
@@ -249,17 +249,17 @@ require_paths:
|
|
249
249
|
- lib
|
250
250
|
required_ruby_version: !ruby/object:Gem::Requirement
|
251
251
|
requirements:
|
252
|
-
- -
|
252
|
+
- - ">="
|
253
253
|
- !ruby/object:Gem::Version
|
254
254
|
version: '0'
|
255
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
256
256
|
requirements:
|
257
|
-
- -
|
257
|
+
- - ">="
|
258
258
|
- !ruby/object:Gem::Version
|
259
259
|
version: 1.3.6
|
260
260
|
requirements: []
|
261
261
|
rubyforge_project:
|
262
|
-
rubygems_version: 2.
|
262
|
+
rubygems_version: 2.2.2
|
263
263
|
signing_key:
|
264
264
|
specification_version: 4
|
265
265
|
summary: The easiest way to write a Slack bot in Ruby.
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Slack
|
2
|
-
module Request
|
3
|
-
private
|
4
|
-
|
5
|
-
alias_method :_request, :request
|
6
|
-
|
7
|
-
def request(method, path, options)
|
8
|
-
response = _request(method, path, options)
|
9
|
-
fail response['error'] unless response['ok'] if response.is_a?(Hash)
|
10
|
-
response
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|