slack-ruby-bot 0.6.1 → 0.6.2
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/.rubocop_todo.yml +6 -6
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/slack-ruby-bot/commands/base.rb +74 -70
- data/lib/slack-ruby-bot/hooks/message.rb +1 -2
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +1 -1
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +1 -1
- data/lib/slack-ruby-bot/server.rb +35 -25
- data/lib/slack-ruby-bot/version.rb +1 -1
- data/slack-ruby-bot.gemspec +1 -1
- data/spec/slack-ruby-bot/commands/bot_spec.rb +1 -1
- data/spec/slack-ruby-bot/commands/commands_spec.rb +10 -10
- data/spec/slack-ruby-bot/commands/empty_text_spec.rb +1 -1
- data/spec/slack-ruby-bot/commands/message_loop_spec.rb +3 -3
- data/spec/slack-ruby-bot/commands/nil_message_spec.rb +1 -1
- data/spec/slack-ruby-bot/commands/send_gif_spec.rb +3 -3
- data/spec/slack-ruby-bot/commands/send_message_spec.rb +1 -1
- data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +6 -6
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +1 -1
- data/spec/slack-ruby-bot/server_spec.rb +18 -0
- metadata +32 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875e496a2ad1228dd53fb09a429cef5d26bb2b33
|
4
|
+
data.tar.gz: 115852404bdba1534728728a3cd56cf818c4ac0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7442eeded435d0f5b23b63310086946170f8c15b51b9bf4d45592a01197aa3eaf95ef27df7bbaa6bab1290c538b0ebb1847f030d5979cc7e43db0385a7c00bd
|
7
|
+
data.tar.gz: 670e97f790446e1974429ac8dad199e6a3312356df6b55f28ed605e9464262468c9527f0b0f6a768ad9e7f125d8d652c704722db96d018e7a6cea92358b3b65e
|
data/.rubocop_todo.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2016-
|
2
|
+
# on 2016-02-02 07:10:58 -0500 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
|
@@ -9,7 +9,7 @@
|
|
9
9
|
Lint/HandleExceptions:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
-
# Offense count:
|
12
|
+
# Offense count: 6
|
13
13
|
Metrics/AbcSize:
|
14
14
|
Max: 28
|
15
15
|
|
@@ -17,21 +17,21 @@ Metrics/AbcSize:
|
|
17
17
|
Metrics/CyclomaticComplexity:
|
18
18
|
Max: 8
|
19
19
|
|
20
|
-
# Offense count:
|
20
|
+
# Offense count: 126
|
21
21
|
# Configuration parameters: AllowURI, URISchemes.
|
22
22
|
Metrics/LineLength:
|
23
|
-
Max:
|
23
|
+
Max: 158
|
24
24
|
|
25
25
|
# Offense count: 6
|
26
26
|
# Configuration parameters: CountComments.
|
27
27
|
Metrics/MethodLength:
|
28
|
-
Max:
|
28
|
+
Max: 21
|
29
29
|
|
30
30
|
# Offense count: 2
|
31
31
|
Metrics/PerceivedComplexity:
|
32
32
|
Max: 8
|
33
33
|
|
34
|
-
# Offense count:
|
34
|
+
# Offense count: 19
|
35
35
|
Style/Documentation:
|
36
36
|
Enabled: false
|
37
37
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### 0.6.2 (2/4/2016)
|
2
|
+
|
3
|
+
* [#44](https://github.com/dblock/slack-ruby-bot/pull/44): Bot graceful shutdown - [@accessd](https://github.com/accessd).
|
4
|
+
|
1
5
|
### 0.6.1 (1/29/2016)
|
2
6
|
|
3
7
|
* [#43](https://github.com/dblock/slack-ruby-bot/issues/43): Issuing a `bot` command terminates bot - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ A generic Slack bot framework written in Ruby on top of [slack-ruby-client](http
|
|
17
17
|
|
18
18
|
## Stable Release
|
19
19
|
|
20
|
-
You're reading the documentation for the **stable** release of slack-ruby-bot
|
20
|
+
You're reading the documentation for the **stable** release of slack-ruby-bot. See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
@@ -4,93 +4,97 @@ module SlackRubyBot
|
|
4
4
|
include Loggable
|
5
5
|
class_attribute :routes
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
class << self
|
8
|
+
def send_message(client, channel, text, options = {})
|
9
|
+
logger.warn '[DEPRECATION] `send_message` is deprecated. Please use `client.say` instead.'
|
10
|
+
if text && text.length > 0
|
11
|
+
client.say(options.merge(channel: channel, text: text))
|
12
|
+
else
|
13
|
+
client.say(options.merge(channel: channel, text: 'Nothing to see here.', gif: 'nothing'))
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def send_message_with_gif(client, channel, text, keywords, options = {})
|
18
|
+
logger.warn '[DEPRECATION] `send_message_with_gif` is deprecated. Please use `client.say` instead.'
|
19
|
+
client.say(options.merge(channel: channel, text: text, gif: keywords))
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def send_gif(client, channel, keywords, options = {})
|
23
|
+
logger.warn '[DEPRECATION] `send_gif` is deprecated. Please use `client.say` instead.'
|
24
|
+
client.say(options.merge(channel: channel, text: '', gif: keywords))
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def default_command_name
|
28
|
+
name && name.split(':').last.downcase
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def operator(*values, &block)
|
32
|
+
values.each do |value|
|
33
|
+
match Regexp.new("^(?<operator>\\#{value})(?<expression>.*)$", Regexp::IGNORECASE), &block
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def command(*values, &block)
|
38
|
+
values.each do |value|
|
39
|
+
escaped = Regexp.escape(value)
|
40
|
+
match Regexp.new("^(?<bot>[[:alnum:][:punct:]@<>]*)[\\s]+(?<command>#{escaped})$", Regexp::IGNORECASE), &block
|
41
|
+
match Regexp.new("^(?<bot>[[:alnum:][:punct:]@<>]*)[\\s]+(?<command>#{escaped})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
|
42
|
+
end
|
41
43
|
end
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
def invoke(client, data)
|
46
|
+
finalize_routes!
|
47
|
+
expression, text = parse(client, data)
|
48
|
+
called = false
|
49
|
+
routes.each_pair do |route, method|
|
50
|
+
match = route.match(expression)
|
51
|
+
match ||= route.match(text) if text
|
52
|
+
next unless match
|
53
|
+
next if match.names.include?('bot') && !client.name?(match['bot'])
|
54
|
+
called = true
|
55
|
+
if method
|
56
|
+
method.call(client, data, match)
|
57
|
+
elsif respond_to?(:call)
|
58
|
+
send(:call, client, data, match)
|
59
|
+
else
|
60
|
+
fail NotImplementedError, data.text
|
61
|
+
end
|
62
|
+
break
|
60
63
|
end
|
61
|
-
|
64
|
+
called
|
62
65
|
end
|
63
|
-
called
|
64
|
-
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
def match(match, &block)
|
68
|
+
self.routes ||= {}
|
69
|
+
self.routes[match] = block
|
70
|
+
end
|
70
71
|
|
71
|
-
|
72
|
-
text = data.text
|
73
|
-
return text unless direct_message?(data) && message_from_another_user?(data)
|
74
|
-
return text if bot_mentioned_in_message?(text, client.names)
|
75
|
-
["#{client.name} #{text}", text]
|
76
|
-
end
|
72
|
+
private
|
77
73
|
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
def parse(client, data)
|
75
|
+
text = data.text
|
76
|
+
return text unless direct_message?(data) && message_from_another_user?(data)
|
77
|
+
return text if bot_mentioned_in_message?(text, client.names)
|
78
|
+
["#{client.name} #{text}", text]
|
79
|
+
end
|
81
80
|
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
def direct_message?(data)
|
82
|
+
data.channel && data.channel[0] == 'D'
|
83
|
+
end
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
85
|
+
def message_from_another_user?(data)
|
86
|
+
data.user && data.user != SlackRubyBot.config.user_id
|
87
|
+
end
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
def bot_mentioned_in_message?(text, bot_names)
|
90
|
+
bot_names = bot_names.join('|')
|
91
|
+
!!text.downcase.match(/\A(#{bot_names})\s|\A(#{bot_names})\z/)
|
92
|
+
end
|
93
|
+
|
94
|
+
def finalize_routes!
|
95
|
+
return if routes && routes.any?
|
96
|
+
command default_command_name
|
97
|
+
end
|
94
98
|
end
|
95
99
|
end
|
96
100
|
end
|
@@ -4,7 +4,6 @@ module SlackRubyBot
|
|
4
4
|
extend Base
|
5
5
|
|
6
6
|
def message(client, data)
|
7
|
-
data = Hashie::Mash.new(data)
|
8
7
|
return if message_to_self_not_allowed? && message_to_self?(client, data)
|
9
8
|
data.text.strip! if data.text
|
10
9
|
result = child_command_classes.detect { |d| d.invoke(client, data) }
|
@@ -20,7 +19,7 @@ module SlackRubyBot
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def message_to_self?(client, data)
|
23
|
-
client.self && client.self
|
22
|
+
client.self && client.self.id == data.user
|
24
23
|
end
|
25
24
|
|
26
25
|
#
|
@@ -7,7 +7,7 @@ RSpec::Matchers.define :respond_with_error do |error, error_message|
|
|
7
7
|
begin
|
8
8
|
expect do
|
9
9
|
client = app.send(:client)
|
10
|
-
app.send(:message, client, text: message, channel: channel, user: user)
|
10
|
+
app.send(:message, client, Hashie::Mash.new(text: message, channel: channel, user: user))
|
11
11
|
end.to raise_error error, error_message
|
12
12
|
rescue RSpec::Expectations::ExpectationNotMetError => e
|
13
13
|
@error_message = e.message
|
@@ -6,7 +6,7 @@ RSpec::Matchers.define :respond_with_slack_message do |expected|
|
|
6
6
|
allow(Giphy).to receive(:random)
|
7
7
|
client = app.send(:client)
|
8
8
|
expect(client).to receive(:message).with(channel: channel, text: expected)
|
9
|
-
app.send(:message, client, text: message, channel: channel, user: user)
|
9
|
+
app.send(:message, client, Hashie::Mash.new(text: message, channel: channel, user: user))
|
10
10
|
true
|
11
11
|
end
|
12
12
|
|
@@ -2,9 +2,9 @@ module SlackRubyBot
|
|
2
2
|
class Server
|
3
3
|
include Loggable
|
4
4
|
cattr_accessor :hooks
|
5
|
-
attr_accessor :token
|
6
|
-
|
7
|
-
|
5
|
+
attr_accessor :token, :aliases, :send_gifs
|
6
|
+
|
7
|
+
TRAPPED_SIGNALS = %w(INT TERM).freeze
|
8
8
|
|
9
9
|
include SlackRubyBot::Hooks::Hello
|
10
10
|
include SlackRubyBot::Hooks::Message
|
@@ -18,24 +18,9 @@ module SlackRubyBot
|
|
18
18
|
def run
|
19
19
|
auth!
|
20
20
|
loop do
|
21
|
-
|
21
|
+
handle_execeptions do
|
22
|
+
handle_signals
|
22
23
|
start!
|
23
|
-
rescue Slack::Web::Api::Error => e
|
24
|
-
logger.error e
|
25
|
-
case e.message
|
26
|
-
when 'migration_in_progress'
|
27
|
-
sleep 1 # ignore, try again
|
28
|
-
else
|
29
|
-
raise e
|
30
|
-
end
|
31
|
-
rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::SSLError => e
|
32
|
-
logger.error e
|
33
|
-
sleep 1 # ignore, try again
|
34
|
-
rescue StandardError => e
|
35
|
-
logger.error e
|
36
|
-
raise e
|
37
|
-
ensure
|
38
|
-
@client = nil
|
39
24
|
end
|
40
25
|
end
|
41
26
|
end
|
@@ -63,11 +48,7 @@ module SlackRubyBot
|
|
63
48
|
end
|
64
49
|
|
65
50
|
def restart!(wait = 1)
|
66
|
-
|
67
|
-
start_async
|
68
|
-
else
|
69
|
-
start!
|
70
|
-
end
|
51
|
+
@async ? start_async : start!
|
71
52
|
rescue StandardError => e
|
72
53
|
sleep wait
|
73
54
|
logger.error "#{e.message}, reconnecting in #{wait} second(s)."
|
@@ -77,6 +58,35 @@ module SlackRubyBot
|
|
77
58
|
|
78
59
|
private
|
79
60
|
|
61
|
+
def handle_execeptions
|
62
|
+
yield
|
63
|
+
rescue Slack::Web::Api::Error => e
|
64
|
+
logger.error e
|
65
|
+
case e.message
|
66
|
+
when 'migration_in_progress'
|
67
|
+
sleep 1 # ignore, try again
|
68
|
+
else
|
69
|
+
raise e
|
70
|
+
end
|
71
|
+
rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::SSLError => e
|
72
|
+
logger.error e
|
73
|
+
sleep 1 # ignore, try again
|
74
|
+
rescue StandardError => e
|
75
|
+
logger.error e
|
76
|
+
raise e
|
77
|
+
ensure
|
78
|
+
@client = nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def handle_signals
|
82
|
+
TRAPPED_SIGNALS.each do |signal|
|
83
|
+
Signal.trap(signal) do
|
84
|
+
stop!
|
85
|
+
exit
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
80
90
|
def client
|
81
91
|
@client ||= begin
|
82
92
|
client = SlackRubyBot::Client.new(aliases: aliases, send_gifs: send_gifs, token: token)
|
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-ruby-client', '>= 0.
|
18
|
+
s.add_dependency 'slack-ruby-client', '>= 0.6.0'
|
19
19
|
s.add_dependency 'faye-websocket'
|
20
20
|
s.add_dependency 'activesupport'
|
21
21
|
s.add_dependency 'giphy', '~> 2.0.2'
|
@@ -14,7 +14,7 @@ describe SlackRubyBot::Bot do
|
|
14
14
|
let(:client) { app.send(:client) }
|
15
15
|
it 'sends a message' do
|
16
16
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
17
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} bot_spec message", channel: 'channel', user: 'user')
|
17
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} bot_spec message", channel: 'channel', user: 'user'))
|
18
18
|
end
|
19
19
|
it 'sends a message' do
|
20
20
|
expect(message: "#{SlackRubyBot.config.user} bot_spec message").to respond_with_slack_message('message')
|
@@ -19,21 +19,21 @@ describe SlackRubyBot::Commands do
|
|
19
19
|
expect(message: "#{SlackRubyBot.config.user} saybye arg1 arg2").to respond_with_slack_message('saybye: arg1 arg2')
|
20
20
|
end
|
21
21
|
it 'checks for direct message' do
|
22
|
-
expect(command.direct_message
|
23
|
-
expect(command.direct_message
|
22
|
+
expect(command.send(:direct_message?, Hashie::Mash.new(channel: 'D0K79RKJ7'))).to be true
|
23
|
+
expect(command.send(:direct_message?, Hashie::Mash.new(channel: 'S0K79RKJ7'))).to be false
|
24
24
|
end
|
25
25
|
it 'checks that message from another user' do
|
26
26
|
SlackRubyBot.config.user_id = 'UDEADBEEF'
|
27
|
-
expect(command.message_from_another_user
|
28
|
-
expect(command.message_from_another_user
|
27
|
+
expect(command.send(:message_from_another_user?, Hashie::Mash.new(user: 'U0CPHNZ2N'))).to be true
|
28
|
+
expect(command.send(:message_from_another_user?, Hashie::Mash.new(user: 'UDEADBEEF'))).to be false
|
29
29
|
end
|
30
30
|
it 'checks that bot mentioned in message' do
|
31
31
|
bot_names = ['rubybot', '<@deadbeef>', '<@deadbeef>:', 'rubybot:']
|
32
|
-
expect(command.bot_mentioned_in_message
|
33
|
-
expect(command.bot_mentioned_in_message
|
34
|
-
expect(command.bot_mentioned_in_message
|
35
|
-
expect(command.bot_mentioned_in_message
|
36
|
-
expect(command.bot_mentioned_in_message
|
37
|
-
expect(command.bot_mentioned_in_message
|
32
|
+
expect(command.send(:bot_mentioned_in_message?, 'rubybot', bot_names)).to be true
|
33
|
+
expect(command.send(:bot_mentioned_in_message?, 'rubybot ', bot_names)).to be true
|
34
|
+
expect(command.send(:bot_mentioned_in_message?, 'rubybotbot', bot_names)).to be false
|
35
|
+
expect(command.send(:bot_mentioned_in_message?, 'rubybot:', bot_names)).to be true
|
36
|
+
expect(command.send(:bot_mentioned_in_message?, 'rubybot: ', bot_names)).to be true
|
37
|
+
expect(command.send(:bot_mentioned_in_message?, 'rubybot:bot', bot_names)).to be false
|
38
38
|
end
|
39
39
|
end
|
@@ -17,6 +17,6 @@ describe SlackRubyBot::Commands do
|
|
17
17
|
it 'sends default text' do
|
18
18
|
allow(Giphy).to receive(:random)
|
19
19
|
expect(client).to receive(:message).with(channel: 'channel', text: '')
|
20
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user')
|
20
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user'))
|
21
21
|
end
|
22
22
|
end
|
@@ -6,13 +6,13 @@ describe SlackRubyBot::App do
|
|
6
6
|
end
|
7
7
|
let(:client) { subject.send(:client) }
|
8
8
|
before do
|
9
|
-
allow(client).to receive(:self).and_return('id' => 'UDEADBEEF')
|
9
|
+
allow(client).to receive(:self).and_return(Hashie::Mash.new('id' => 'UDEADBEEF'))
|
10
10
|
allow(Giphy).to receive(:random)
|
11
11
|
end
|
12
12
|
context 'default' do
|
13
13
|
it 'does not respond to self' do
|
14
14
|
expect(client).to_not receive(:message)
|
15
|
-
subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
|
15
|
+
subject.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF'))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
context 'with allow_message_loops=true' do
|
@@ -28,7 +28,7 @@ describe SlackRubyBot::App do
|
|
28
28
|
end
|
29
29
|
it 'responds to self' do
|
30
30
|
expect(client).to receive(:message)
|
31
|
-
subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
|
31
|
+
subject.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF'))
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -17,6 +17,6 @@ describe SlackRubyBot::Commands do
|
|
17
17
|
it 'ignores nil messages' do
|
18
18
|
allow(Giphy).to receive(:random)
|
19
19
|
expect(client).to_not receive(:message)
|
20
|
-
app.send(:message, client, text: nil, channel: 'channel', user: 'user')
|
20
|
+
app.send(:message, client, Hashie::Mash.new(text: nil, channel: 'channel', user: 'user'))
|
21
21
|
end
|
22
22
|
end
|
@@ -17,16 +17,16 @@ describe SlackRubyBot::Commands do
|
|
17
17
|
gif = Giphy::RandomGif.new('image_url' => gif_image_url)
|
18
18
|
expect(Giphy).to receive(:random).and_return(gif)
|
19
19
|
expect(client).to receive(:message).with(channel: 'channel', text: gif_image_url)
|
20
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
|
20
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user'))
|
21
21
|
end
|
22
22
|
it 'eats up the error' do
|
23
23
|
expect(Giphy).to receive(:random) { fail 'oh no!' }
|
24
24
|
expect(client).to receive(:message).with(channel: 'channel', text: '')
|
25
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
|
25
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user'))
|
26
26
|
end
|
27
27
|
it 'eats up nil gif' do
|
28
28
|
expect(Giphy).to receive(:random).and_return(nil)
|
29
29
|
expect(client).to receive(:message).with(channel: 'channel', text: '')
|
30
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
|
30
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user'))
|
31
31
|
end
|
32
32
|
end
|
@@ -14,6 +14,6 @@ describe SlackRubyBot::Commands do
|
|
14
14
|
let(:client) { app.send(:client) }
|
15
15
|
it 'sends a message' do
|
16
16
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
17
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_spec message", channel: 'channel', user: 'user')
|
17
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_spec message", channel: 'channel', user: 'user'))
|
18
18
|
end
|
19
19
|
end
|
@@ -17,17 +17,17 @@ describe SlackRubyBot::Commands do
|
|
17
17
|
gif = Giphy::RandomGif.new('image_url' => gif_image_url)
|
18
18
|
expect(Giphy).to receive(:random).and_return(gif)
|
19
19
|
expect(client).to receive(:message).with(channel: 'channel', text: "message\n#{gif_image_url}")
|
20
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
20
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user'))
|
21
21
|
end
|
22
22
|
it 'eats up the error' do
|
23
23
|
expect(Giphy).to receive(:random) { fail 'oh no!' }
|
24
24
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
25
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
25
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user'))
|
26
26
|
end
|
27
27
|
it 'eats up nil gif' do
|
28
28
|
expect(Giphy).to receive(:random).and_return(nil)
|
29
29
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
30
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
30
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user'))
|
31
31
|
end
|
32
32
|
context 'send_gifs' do
|
33
33
|
context 'set to false via client' do
|
@@ -37,7 +37,7 @@ describe SlackRubyBot::Commands do
|
|
37
37
|
it 'does not send a gif' do
|
38
38
|
expect(Giphy).to_not receive(:random)
|
39
39
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
40
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
40
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user'))
|
41
41
|
end
|
42
42
|
after do
|
43
43
|
client.send_gifs = true
|
@@ -50,7 +50,7 @@ describe SlackRubyBot::Commands do
|
|
50
50
|
it 'does not send a gif' do
|
51
51
|
expect(Giphy).to_not receive(:random)
|
52
52
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
53
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
53
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user'))
|
54
54
|
end
|
55
55
|
after do
|
56
56
|
SlackRubyBot::Config.reset!
|
@@ -63,7 +63,7 @@ describe SlackRubyBot::Commands do
|
|
63
63
|
it 'does not send a gif' do
|
64
64
|
expect(Giphy).to_not receive(:random)
|
65
65
|
expect(client).to receive(:message).with(channel: 'channel', text: 'message')
|
66
|
-
app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
|
66
|
+
app.send(:message, client, Hashie::Mash.new(text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user'))
|
67
67
|
end
|
68
68
|
after do
|
69
69
|
ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS'
|
@@ -13,6 +13,6 @@ describe SlackRubyBot::Commands::Unknown do
|
|
13
13
|
end
|
14
14
|
it 'does not respond to sad face' do
|
15
15
|
expect(SlackRubyBot::Commands::Base).to_not receive(:send_message)
|
16
|
-
SlackRubyBot::App.new.send(:message, client, text: ':((')
|
16
|
+
SlackRubyBot::App.new.send(:message, client, Hashie::Mash.new(text: ':(('))
|
17
17
|
end
|
18
18
|
end
|
@@ -70,4 +70,22 @@ describe SlackRubyBot::Server do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
|
+
context 'exits without error' do
|
74
|
+
subject do
|
75
|
+
SlackRubyBot::Server.new(token: 'token')
|
76
|
+
end
|
77
|
+
before do
|
78
|
+
allow(subject).to receive(:auth!)
|
79
|
+
allow(subject).to receive(:start!)
|
80
|
+
end
|
81
|
+
SlackRubyBot::Server::TRAPPED_SIGNALS.each do |signal|
|
82
|
+
it "if #{signal} signal received" do
|
83
|
+
server_pid = fork { subject.run }
|
84
|
+
sleep 0.1
|
85
|
+
Process.kill(signal, server_pid)
|
86
|
+
_, status = Process.waitpid2(server_pid)
|
87
|
+
expect(status.success?).to be true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
73
91
|
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.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-04 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
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: 0.
|
33
|
+
version: 0.6.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: 0.
|
40
|
+
version: 0.6.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faye-websocket
|
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: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
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: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: giphy
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 2.0.2
|
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: 2.0.2
|
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
|
@@ -272,17 +272,17 @@ require_paths:
|
|
272
272
|
- lib
|
273
273
|
required_ruby_version: !ruby/object:Gem::Requirement
|
274
274
|
requirements:
|
275
|
-
- -
|
275
|
+
- - ">="
|
276
276
|
- !ruby/object:Gem::Version
|
277
277
|
version: '0'
|
278
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
279
279
|
requirements:
|
280
|
-
- -
|
280
|
+
- - ">="
|
281
281
|
- !ruby/object:Gem::Version
|
282
282
|
version: 1.3.6
|
283
283
|
requirements: []
|
284
284
|
rubyforge_project:
|
285
|
-
rubygems_version: 2.4.
|
285
|
+
rubygems_version: 2.4.8
|
286
286
|
signing_key:
|
287
287
|
specification_version: 4
|
288
288
|
summary: The easiest way to write a Slack bot in Ruby.
|