slack-ruby-bot 0.12.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.gitignore +3 -2
- data/.rubocop.yml +14 -1
- data/.rubocop_todo.yml +14 -42
- data/.travis.yml +11 -13
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +5 -1
- data/DEPLOYMENT.md +63 -9
- data/Dangerfile +4 -0
- data/Gemfile +11 -7
- data/LICENSE.md +1 -1
- data/MIGRATION.md +13 -0
- data/README.md +131 -63
- data/Rakefile +2 -0
- data/TUTORIAL.md +23 -0
- data/UPGRADING.md +44 -0
- data/examples/inventory/Gemfile +2 -0
- data/examples/inventory/inventorybot.rb +5 -1
- data/examples/market/Gemfile +4 -3
- data/examples/market/marketbot.rb +22 -15
- data/examples/minimal/Gemfile +3 -1
- data/examples/minimal/pongbot.rb +2 -0
- data/examples/weather/Gemfile +2 -0
- data/examples/weather/weatherbot.rb +2 -0
- data/lib/config/application.rb +4 -2
- data/lib/config/boot.rb +2 -0
- data/lib/config/environment.rb +3 -1
- data/lib/slack-ruby-bot.rb +3 -1
- data/lib/slack-ruby-bot/about.rb +3 -1
- data/lib/slack-ruby-bot/app.rb +18 -12
- data/lib/slack-ruby-bot/bot.rb +3 -1
- data/lib/slack-ruby-bot/client.rb +25 -23
- data/lib/slack-ruby-bot/commands.rb +2 -0
- data/lib/slack-ruby-bot/commands/about.rb +3 -1
- data/lib/slack-ruby-bot/commands/base.rb +13 -21
- data/lib/slack-ruby-bot/commands/help.rb +10 -8
- data/lib/slack-ruby-bot/commands/hi.rb +3 -1
- data/lib/slack-ruby-bot/commands/support/attrs.rb +2 -0
- data/lib/slack-ruby-bot/commands/support/help.rb +4 -0
- data/lib/slack-ruby-bot/commands/support/match.rb +4 -3
- data/lib/slack-ruby-bot/commands/unknown.rb +3 -1
- data/lib/slack-ruby-bot/config.rb +7 -7
- data/lib/slack-ruby-bot/hooks.rb +2 -0
- data/lib/slack-ruby-bot/hooks/hello.rb +22 -3
- data/lib/slack-ruby-bot/hooks/hook_support.rb +2 -6
- data/lib/slack-ruby-bot/hooks/message.rb +11 -10
- data/lib/slack-ruby-bot/hooks/set.rb +3 -1
- data/lib/slack-ruby-bot/mvc.rb +2 -0
- data/lib/slack-ruby-bot/mvc/controller/base.rb +4 -3
- data/lib/slack-ruby-bot/mvc/model/base.rb +2 -0
- data/lib/slack-ruby-bot/mvc/mvc.rb +2 -0
- data/lib/slack-ruby-bot/mvc/view/base.rb +2 -0
- data/lib/slack-ruby-bot/rspec.rb +3 -1
- data/lib/slack-ruby-bot/rspec/support/bots_for_tests.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +4 -1
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +3 -5
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +3 -7
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +15 -14
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +26 -19
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb +32 -0
- data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +3 -1
- data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +2 -0
- data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +2 -0
- data/lib/slack-ruby-bot/server.rb +5 -4
- data/lib/slack-ruby-bot/support/loggable.rb +2 -0
- data/lib/slack-ruby-bot/version.rb +3 -1
- data/lib/slack_ruby_bot.rb +2 -0
- data/screenshots/create-classic-app.png +0 -0
- data/slack-ruby-bot.gemspec +6 -2
- data/spec/slack-ruby-bot/app_spec.rb +64 -1
- data/spec/slack-ruby-bot/client_spec.rb +103 -28
- data/spec/slack-ruby-bot/commands/about_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/aliases_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/attachment_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/bot_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/bot_messages_spec.rb +26 -0
- data/spec/slack-ruby-bot/commands/bot_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_permitted_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_regexp_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/commands_with_expression_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/help_spec.rb +15 -13
- data/spec/slack-ruby-bot/commands/hi_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/match_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/nil_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/non_breaking_space_spec.rb +29 -0
- data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/scan_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/attrs_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/help_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/support/match_spec.rb +2 -0
- data/spec/slack-ruby-bot/commands/unknown_spec.rb +2 -0
- data/spec/slack-ruby-bot/config_spec.rb +2 -57
- data/spec/slack-ruby-bot/hooks/hello_spec.rb +51 -0
- data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +2 -5
- data/spec/slack-ruby-bot/hooks/message_spec.rb +8 -35
- data/spec/slack-ruby-bot/hooks/set_spec.rb +2 -0
- data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -0
- data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +2 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +20 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +36 -0
- data/spec/slack-ruby-bot/rspec/start_typing_spec.rb +36 -0
- data/spec/slack-ruby-bot/server_spec.rb +6 -16
- data/spec/slack-ruby-bot/support/loggable_spec.rb +2 -0
- data/spec/slack-ruby-bot/version_spec.rb +2 -0
- data/spec/spec_helper.rb +3 -6
- data/{lib/slack-ruby-bot/rspec → spec}/support/fixtures/slack/migration_in_progress.yml +0 -0
- data/{lib/slack-ruby-bot/rspec → spec}/support/vcr.rb +2 -0
- metadata +40 -27
- data/lib/initializers/giphy.rb +0 -8
- data/lib/initializers/giphy_client.rb +0 -39
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_burrito.yml +0 -69
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito.yml +0 -71
- data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito_rated_y.yml +0 -71
- data/screenshots/register-bot.png +0 -0
- data/spec/slack-ruby-bot/commands/send_gif_spec.rb +0 -25
- data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +0 -38
- data/spec/slack-ruby-bot/initializers/giphy_client_spec.rb +0 -28
- data/spec/slack-ruby-bot/initializers/giphy_spec.rb +0 -18
@@ -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
|
@@ -1,25 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe SlackRubyBot::Commands::Help do
|
2
4
|
def app
|
3
5
|
SlackRubyBot::App.new
|
4
6
|
end
|
5
7
|
it 'help' do
|
6
|
-
message =
|
7
|
-
*Weather Bot* - This bot tells you the weather.
|
8
|
+
message = <<~MSG
|
9
|
+
*Weather Bot* - This bot tells you the weather.
|
8
10
|
|
9
|
-
*Commands:*
|
10
|
-
*clouds* - Tells you how many clouds there're above you.
|
11
|
-
*command_without_description*
|
12
|
-
*What's the weather in <city>?* - Tells you the weather in a <city>.
|
11
|
+
*Commands:*
|
12
|
+
*clouds* - Tells you how many clouds there're above you.
|
13
|
+
*command_without_description*
|
14
|
+
*What's the weather in <city>?* - Tells you the weather in a <city>.
|
13
15
|
|
14
|
-
*Other commands:*
|
15
|
-
*help* - Shows help information.
|
16
|
-
*hi* - Says hello.
|
17
|
-
*hello* - Says hello.
|
16
|
+
*Other commands:*
|
17
|
+
*help* - Shows help information.
|
18
|
+
*hi* - Says hello.
|
19
|
+
*hello* - Says hello.
|
18
20
|
|
19
|
-
For getting description of the command use: *help <command>*
|
21
|
+
For getting description of the command use: *help <command>*
|
20
22
|
|
21
|
-
For more information see https://github.com/slack-ruby/slack-ruby-bot, please.
|
22
|
-
MSG
|
23
|
+
For more information see https://github.com/slack-ruby/slack-ruby-bot, please.
|
24
|
+
MSG
|
23
25
|
|
24
26
|
expect(message: "#{SlackRubyBot.config.user} help").to respond_with_slack_message(message)
|
25
27
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe SlackRubyBot::Commands do
|
4
|
+
let! :command do
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
+
command 'non_breaking_space' do |client, data, match|
|
7
|
+
client.say(channel: data.channel, text: match['expression'])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
it 'sends a message with non-breaking space after bot name' do
|
12
|
+
expect(message: "#{SlackRubyBot.config.user}\u00a0non_breaking_space message").to respond_with_slack_message('message')
|
13
|
+
end
|
14
|
+
it 'sends a message with non-breaking space after command' do
|
15
|
+
expect(message: "#{SlackRubyBot.config.user} non_breaking_space\u00a0message").to respond_with_slack_message('message')
|
16
|
+
end
|
17
|
+
it 'sends a message with all non-breaking spaces' do
|
18
|
+
expect(message: "#{SlackRubyBot.config.user}\u00a0non_breaking_space\u00a0message").to respond_with_slack_message('message')
|
19
|
+
end
|
20
|
+
it 'sends a message with trailing non-breaking spaces' do
|
21
|
+
expect(message: "#{SlackRubyBot.config.user} non_breaking_space message\u00a0").to respond_with_slack_message("message\u00a0")
|
22
|
+
end
|
23
|
+
it 'sends a message with multiple non-breaking spaces' do
|
24
|
+
expect(message: "#{SlackRubyBot.config.user} non_breaking_space message1\u00a0message2").to respond_with_slack_message("message1\u00a0message2")
|
25
|
+
end
|
26
|
+
it 'sends a message with non-breaking spaces on multiple lines' do
|
27
|
+
expect(message: "#{SlackRubyBot.config.user} non_breaking_space message1\u00a0message2\nmessage3\u00a0message4").to respond_with_slack_message("message1\u00a0message2\nmessage3\u00a0message4")
|
28
|
+
end
|
29
|
+
end
|
@@ -1,61 +1,6 @@
|
|
1
|
-
|
2
|
-
describe '.send_gifs?' do
|
3
|
-
after { ENV.delete 'SLACK_RUBY_BOT_SEND_GIFS' }
|
4
|
-
|
5
|
-
context 'without giphy is false', unless: WithGiphy.env? do
|
6
|
-
it 'by default' do
|
7
|
-
expect(SlackRubyBot::Config.send_gifs?).to be false
|
8
|
-
end
|
9
|
-
it 'when set to true' do
|
10
|
-
SlackRubyBot::Config.send_gifs = true
|
11
|
-
expect(SlackRubyBot::Config.send_gifs?).to be false
|
12
|
-
end
|
13
|
-
it 'when set to true via SLACK_RUBY_BOT_SEND_GIFS' do
|
14
|
-
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
|
15
|
-
expect(SlackRubyBot::Config.send_gifs?).to be false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
context 'with giphy', if: WithGiphy.env? do
|
19
|
-
it 'default is true' do
|
20
|
-
expect(SlackRubyBot::Config.send_gifs?).to be true
|
21
|
-
end
|
22
|
-
context 'set to false' do
|
23
|
-
it 'is false' do
|
24
|
-
SlackRubyBot::Config.send_gifs = false
|
25
|
-
expect(SlackRubyBot::Config.send_gifs?).to be false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
context 'set to false via SLACK_RUBY_BOT_SEND_GIFS' do
|
29
|
-
it 'is false' do
|
30
|
-
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'false'
|
31
|
-
expect(SlackRubyBot::Config.send_gifs?).to be false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
context 'set to true' do
|
35
|
-
it 'is true' do
|
36
|
-
SlackRubyBot::Config.send_gifs = true
|
37
|
-
expect(SlackRubyBot::Config.send_gifs?).to be true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
context 'set to true via SLACK_RUBY_BOT_SEND_GIFS' do
|
41
|
-
it 'is true' do
|
42
|
-
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
|
43
|
-
expect(SlackRubyBot::Config.send_gifs?).to be true
|
44
|
-
end
|
45
|
-
end
|
46
|
-
context 'when using both methods' do
|
47
|
-
it 'config setting takes precedence' do
|
48
|
-
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'true'
|
49
|
-
SlackRubyBot::Config.send_gifs = false
|
50
|
-
expect(SlackRubyBot::Config.send_gifs?).to be false
|
51
|
-
ENV['SLACK_RUBY_BOT_SEND_GIFS'] = 'false'
|
52
|
-
SlackRubyBot::Config.send_gifs = true
|
53
|
-
expect(SlackRubyBot::Config.send_gifs?).to be true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
1
|
+
# frozen_string_literal: true
|
58
2
|
|
3
|
+
describe SlackRubyBot::Config do
|
59
4
|
describe '#reset!' do
|
60
5
|
it 'sets all config attributes to nil' do
|
61
6
|
SlackRubyBot::Config::ATTRS.each do |attr|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe SlackRubyBot::Hooks::Hello do
|
4
|
+
let(:logger) { double(:logger, info: nil) }
|
5
|
+
let(:hello_hook) { described_class.new(logger) }
|
6
|
+
|
7
|
+
describe '#call' do
|
8
|
+
let(:team_name) { 'Example Team' }
|
9
|
+
let(:team_id) { SecureRandom.uuid }
|
10
|
+
let(:team_domain) { 'example' }
|
11
|
+
let(:team) { double(:team, name: team_name, id: team_id, domain: team_domain) }
|
12
|
+
let(:client) { instance_double(SlackRubyBot::Client, team: team) }
|
13
|
+
|
14
|
+
def receive_hello
|
15
|
+
hello_hook.call(client, double)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'logs the connection' do
|
19
|
+
expect(logger).to receive(:info).with("Successfully connected team #{team_name} (#{team_id}) to https://#{team_domain}.slack.com.")
|
20
|
+
receive_hello
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with no client' do
|
24
|
+
let(:client) { nil }
|
25
|
+
it 'does nothing' do
|
26
|
+
expect(logger).not_to receive(:info)
|
27
|
+
receive_hello
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when client has no team' do
|
32
|
+
let(:team) { nil }
|
33
|
+
it 'does nothing' do
|
34
|
+
expect(logger).not_to receive(:info)
|
35
|
+
receive_hello
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when hook is received multiple times' do
|
40
|
+
before do
|
41
|
+
receive_hello
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'logs the reconnections' do
|
45
|
+
expect(logger).to receive(:info).with(/^Successfully reconnected .+ after \S+s\.$/).twice
|
46
|
+
receive_hello
|
47
|
+
receive_hello
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe SlackRubyBot::Hooks::HookSupport do
|
2
4
|
subject do
|
3
5
|
Class.new do
|
@@ -54,11 +56,6 @@ describe SlackRubyBot::Hooks::HookSupport do
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
describe '#hooks' do
|
58
|
-
subject { super().new }
|
59
|
-
it { expect(subject.hooks).to eq subject.send(:_hooks) }
|
60
|
-
end
|
61
|
-
|
62
59
|
describe '#_hooks' do
|
63
60
|
it 'returns a SlackRubyBot::Hooks::Set instance' do
|
64
61
|
hooks_set = subject.new.send(:_hooks)
|
@@ -1,12 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
describe SlackRubyBot::Hooks::Message do
|
2
4
|
let(:message_hook) { described_class.new }
|
3
5
|
|
4
6
|
describe '#call' do
|
5
7
|
it 'doesn\'t raise an error when message is a frozen string' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
expect do
|
9
|
+
message_hook.call(
|
10
|
+
SlackRubyBot::Client.new,
|
11
|
+
Hashie::Mash.new(text: 'message'.freeze) # rubocop:disable Style/RedundantFreeze
|
12
|
+
)
|
13
|
+
end.to_not raise_error
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
@@ -30,37 +34,6 @@ describe SlackRubyBot::Hooks::Message do
|
|
30
34
|
expect(built_in_command_classes).to_not include SlackRubyBot::Commands::Unknown
|
31
35
|
end
|
32
36
|
end
|
33
|
-
describe '#message_to_self_not_allowed?' do
|
34
|
-
context 'with allow_message_loops set to true' do
|
35
|
-
before do
|
36
|
-
SlackRubyBot::Config.allow_message_loops = true
|
37
|
-
end
|
38
|
-
it do
|
39
|
-
expect(message_hook.send(:message_to_self_not_allowed?)).to be false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
context 'with allow_message_loops set to false' do
|
43
|
-
before do
|
44
|
-
SlackRubyBot::Config.allow_message_loops = false
|
45
|
-
end
|
46
|
-
it do
|
47
|
-
expect(message_hook.send(:message_to_self_not_allowed?)).to be true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
describe '#message_to_self?' do
|
52
|
-
let(:client) { Hashie::Mash.new(self: { 'id' => 'U0K8CKKT1' }) }
|
53
|
-
context 'with message to self' do
|
54
|
-
it do
|
55
|
-
expect(message_hook.send(:message_to_self?, client, Hashie::Mash.new(user: 'U0K8CKKT1'))).to be true
|
56
|
-
end
|
57
|
-
end
|
58
|
-
context 'with message to another user' do
|
59
|
-
it do
|
60
|
-
expect(message_hook.send(:message_to_self?, client, Hashie::Mash.new(user: 'U0K8CKKT2'))).to be false
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
37
|
describe '#message' do
|
65
38
|
let(:client) { Hashie::Mash.new(self: { 'id' => 'U0K8CKKT1' }) }
|
66
39
|
it 'invokes a command' do
|