slack-ruby-bot 0.9.0 → 0.10.0
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 +23 -22
- data/CHANGELOG.md +10 -0
- data/Dangerfile +1 -1
- data/Gemfile +4 -1
- data/README.md +1 -1
- data/TUTORIAL.md +9 -2
- data/examples/minimal/pongbot.rb +2 -0
- data/lib/slack-ruby-bot/bot.rb +1 -1
- data/lib/slack-ruby-bot/commands/base.rb +8 -1
- data/lib/slack-ruby-bot/commands/help/attrs.rb +4 -4
- data/lib/slack-ruby-bot/commands/unknown.rb +1 -1
- data/lib/slack-ruby-bot/hooks/hello.rb +1 -1
- data/lib/slack-ruby-bot/hooks/message.rb +1 -1
- data/lib/slack-ruby-bot/support/commands_helper.rb +4 -4
- data/lib/slack-ruby-bot/version.rb +1 -1
- data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +39 -0
- data/spec/slack-ruby-bot/support/commands_helper_spec.rb +36 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8e23b1dde8a7cb5147d728f4a0269e36f91fb27
|
4
|
+
data.tar.gz: b5355a6b7a7cf15868390e97c0aa423881373f6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 726e80f25e3bc5310298205bdea44759b830974a87d7f0723c444ee956113a40d9fdf67c6ca2a9f21138379e28c0cea6e38e3d5efa3796d2334f0f27e8fb1e40
|
7
|
+
data.tar.gz: 9235ebff49dc787ab29514b8c2351fbbad318a097a144168ac18d768b2aeceb743ec4d62767cf5c76d9f7063f56123b6288c530cf8a1b89176c871a963f76c6d
|
data/.rubocop_todo.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
#
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2016-09-24 09:10:21 -0400 using RuboCop version 0.38.0.
|
3
4
|
# The point is for the user to remove these configuration records
|
4
5
|
# one by one as the offenses are removed from the code base.
|
5
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -7,48 +8,48 @@
|
|
7
8
|
|
8
9
|
# Offense count: 1
|
9
10
|
Lint/HandleExceptions:
|
10
|
-
|
11
|
+
Exclude:
|
12
|
+
- 'lib/initializers/giphy.rb'
|
11
13
|
|
12
|
-
# Offense count:
|
14
|
+
# Offense count: 5
|
13
15
|
Metrics/AbcSize:
|
14
|
-
Max:
|
15
|
-
|
16
|
-
# Offense count: 1
|
17
|
-
# Configuration parameters: CountComments.
|
18
|
-
Metrics/ClassLength:
|
19
|
-
Max: 102
|
16
|
+
Max: 36
|
20
17
|
|
21
18
|
# Offense count: 2
|
22
19
|
Metrics/CyclomaticComplexity:
|
23
|
-
Max:
|
20
|
+
Max: 11
|
24
21
|
|
25
|
-
# Offense count:
|
26
|
-
# Configuration parameters: AllowURI, URISchemes.
|
22
|
+
# Offense count: 156
|
23
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
24
|
+
# URISchemes: http, https
|
27
25
|
Metrics/LineLength:
|
28
|
-
Max:
|
26
|
+
Max: 147
|
29
27
|
|
30
|
-
# Offense count:
|
28
|
+
# Offense count: 6
|
31
29
|
# Configuration parameters: CountComments.
|
32
30
|
Metrics/MethodLength:
|
33
31
|
Max: 27
|
34
32
|
|
35
33
|
# Offense count: 2
|
36
34
|
Metrics/PerceivedComplexity:
|
37
|
-
Max:
|
35
|
+
Max: 11
|
38
36
|
|
39
|
-
# Offense count:
|
37
|
+
# Offense count: 26
|
40
38
|
Style/Documentation:
|
41
39
|
Enabled: false
|
42
40
|
|
43
|
-
# Offense count:
|
41
|
+
# Offense count: 1
|
44
42
|
Style/DoubleNegation:
|
45
|
-
|
43
|
+
Exclude:
|
44
|
+
- 'lib/slack-ruby-bot/commands/base.rb'
|
46
45
|
|
47
46
|
# Offense count: 1
|
48
|
-
# Configuration parameters:
|
47
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
49
48
|
Style/FileName:
|
50
|
-
|
49
|
+
Exclude:
|
50
|
+
- 'lib/slack-ruby-bot.rb'
|
51
51
|
|
52
52
|
# Offense count: 1
|
53
53
|
Style/ModuleFunction:
|
54
|
-
|
54
|
+
Exclude:
|
55
|
+
- 'lib/slack-ruby-bot/config.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 0.10.0 (2/9/2017)
|
2
|
+
|
3
|
+
* [#111](https://github.com/slack-ruby/slack-ruby-bot/pull/111): Default keyword for GIFs in invalid commands has been changed from `idiot` to `understand` - [@dblock](https://github.com/dblock).
|
4
|
+
* [#98](https://github.com/slack-ruby/slack-ruby-bot/pull/98): Fixed a couple of problems in TUTORIAL.md - [@edruder](https://github.com/edruder).
|
5
|
+
* [#95](https://github.com/slack-ruby/slack-ruby-bot/pull/95): Log team name and ID on successful connection - [@dblock](https://github.com/dblock).
|
6
|
+
* [#94](https://github.com/slack-ruby/slack-ruby-bot/pull/94): Use the slack-ruby-danger gem - [@dblock](https://github.com/dblock).
|
7
|
+
* [#86](https://github.com/dblock/slack-ruby-bot/pull/86): Fix: help statements from classes that do not directly inherit from `Base` appear in `bot help` - [@maclover7](https://github.com/maclover7).
|
8
|
+
* [#96](https://github.com/slack-ruby/slack-ruby-bot/pull/96): Support help statements in anonymous command and bot classes - [@dblock](https://github.com/dblock).
|
9
|
+
* [#75](https://github.com/slack-ruby/slack-ruby-bot/pull/101): Fix: Guarantee order of commands based on load order - [@gconklin](https://github.com/gconklin).
|
10
|
+
|
1
11
|
### 0.9.0 (8/29/2016)
|
2
12
|
|
3
13
|
* [#89](https://github.com/slack-ruby/slack-ruby-bot/pull/89): Drop giphy dependency - [@tmsrjs](https://github.com/tmsrjs).
|
data/Dangerfile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
danger.import_dangerfile(gem: 'slack-ruby-danger')
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ 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. 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, 0.10.0. See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
data/TUTORIAL.md
CHANGED
@@ -19,6 +19,7 @@ gem 'slack-ruby-bot'
|
|
19
19
|
gem 'puma'
|
20
20
|
gem 'sinatra'
|
21
21
|
gem 'dotenv'
|
22
|
+
gem 'celluloid-io'
|
22
23
|
|
23
24
|
group :development, :test do
|
24
25
|
gem 'rake'
|
@@ -172,15 +173,18 @@ require 'slack-mathbot'
|
|
172
173
|
|
173
174
|
#### Test the Bot Application
|
174
175
|
|
175
|
-
Create a test for the bot application itself in `spec/slack-mathbot/
|
176
|
+
Create a test for the bot application itself in `spec/slack-mathbot/bot_spec.rb`.
|
176
177
|
|
177
178
|
```ruby
|
178
179
|
require 'spec_helper'
|
179
180
|
|
180
|
-
describe SlackMathbot::
|
181
|
+
describe SlackMathbot::Bot do
|
181
182
|
def app
|
182
183
|
SlackMathbot::Bot.instance
|
183
184
|
end
|
185
|
+
|
186
|
+
subject { app }
|
187
|
+
|
184
188
|
it_behaves_like 'a slack ruby bot'
|
185
189
|
end
|
186
190
|
```
|
@@ -196,6 +200,9 @@ describe SlackMathbot::Commands::Calculate do
|
|
196
200
|
def app
|
197
201
|
SlackMathbot::Bot.instance
|
198
202
|
end
|
203
|
+
|
204
|
+
subject { app }
|
205
|
+
|
199
206
|
it 'returns 4' do
|
200
207
|
expect(message: "#{SlackRubyBot.config.user} calculate 2+2", channel: 'channel').to respond_with_slack_message('4')
|
201
208
|
end
|
data/examples/minimal/pongbot.rb
CHANGED
data/lib/slack-ruby-bot/bot.rb
CHANGED
@@ -11,7 +11,7 @@ module SlackRubyBot
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.call(client, data, _match)
|
14
|
-
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: '
|
14
|
+
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'understand')
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -5,6 +5,13 @@ module SlackRubyBot
|
|
5
5
|
class_attribute :routes
|
6
6
|
|
7
7
|
class << self
|
8
|
+
attr_reader :command_classes
|
9
|
+
|
10
|
+
def inherited(subclass)
|
11
|
+
@command_classes ||= []
|
12
|
+
@command_classes << subclass
|
13
|
+
end
|
14
|
+
|
8
15
|
def send_message(client, channel, text, options = {})
|
9
16
|
logger.warn '[DEPRECATION] `send_message` is deprecated. Please use `client.say` instead.'
|
10
17
|
if text && !text.length.empty?
|
@@ -25,7 +32,7 @@ module SlackRubyBot
|
|
25
32
|
end
|
26
33
|
|
27
34
|
def help(&block)
|
28
|
-
CommandsHelper.instance.capture_help(
|
35
|
+
CommandsHelper.instance.capture_help(self, &block)
|
29
36
|
end
|
30
37
|
|
31
38
|
def default_command_name
|
@@ -3,10 +3,10 @@ module SlackRubyBot
|
|
3
3
|
module Help
|
4
4
|
class Attrs
|
5
5
|
attr_accessor :command_name, :command_desc, :command_long_desc
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :klass, :commands
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(klass)
|
9
|
+
@klass = klass
|
10
10
|
@commands = []
|
11
11
|
end
|
12
12
|
|
@@ -23,7 +23,7 @@ module SlackRubyBot
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def command(title, &block)
|
26
|
-
@commands << self.class.new(
|
26
|
+
@commands << self.class.new(klass).tap do |k|
|
27
27
|
k.title(title)
|
28
28
|
k.instance_eval(&block)
|
29
29
|
end
|
@@ -4,7 +4,7 @@ module SlackRubyBot
|
|
4
4
|
match(/^(?<bot>\S*)[\s]*(?<expression>.*)$/)
|
5
5
|
|
6
6
|
def self.call(client, data, _match)
|
7
|
-
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: '
|
7
|
+
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'understand')
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -9,7 +9,7 @@ module SlackRubyBot
|
|
9
9
|
|
10
10
|
def call(client, _data)
|
11
11
|
return unless client && client.team
|
12
|
-
logger.info "Successfully connected to https://#{client.team.domain}.slack.com."
|
12
|
+
logger.info "Successfully connected team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com."
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -10,8 +10,8 @@ module SlackRubyBot
|
|
10
10
|
@commands_help_attrs = []
|
11
11
|
end
|
12
12
|
|
13
|
-
def capture_help(
|
14
|
-
k = Commands::Help::Attrs.new(
|
13
|
+
def capture_help(klass, &block)
|
14
|
+
k = Commands::Help::Attrs.new(klass)
|
15
15
|
k.instance_eval(&block)
|
16
16
|
@commands_help_attrs << k
|
17
17
|
end
|
@@ -66,11 +66,11 @@ module SlackRubyBot
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def bot_help_attrs
|
69
|
-
commands_help_attrs.select { |k| k.
|
69
|
+
commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Bot) }
|
70
70
|
end
|
71
71
|
|
72
72
|
def other_commands_help_attrs
|
73
|
-
commands_help_attrs.select { |k| k.
|
73
|
+
commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Commands::Base) && !k.klass.ancestors.include?(SlackRubyBot::Bot) }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SlackRubyBot::Commands::Base do
|
4
|
+
let! :command1 do
|
5
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
6
|
+
command 'command'
|
7
|
+
|
8
|
+
def self.call(client, data, match)
|
9
|
+
client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let! :command2 do
|
15
|
+
Class.new(SlackRubyBot::Commands::Base) do
|
16
|
+
command 'command'
|
17
|
+
|
18
|
+
def self.call(client, data, match)
|
19
|
+
client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def app
|
25
|
+
SlackRubyBot::App.new
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#command_classes' do
|
29
|
+
it 'returns all registered command classes' do
|
30
|
+
expect(SlackRubyBot::Commands::Base.command_classes).to include command1
|
31
|
+
expect(SlackRubyBot::Commands::Base.command_classes).to include command2
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns command1 before command2' do
|
35
|
+
command_classes = SlackRubyBot::Commands::Base.command_classes
|
36
|
+
expect(command_classes.find_index(command1)).to be < command_classes.find_index(command2)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SlackRubyBot::CommandsHelper do
|
4
|
-
let(:
|
5
|
-
let(:
|
4
|
+
let(:bot_class) { Testing::WeatherBot }
|
5
|
+
let(:command_class) { Testing::HelloCommand }
|
6
6
|
let(:commands_helper) { described_class.instance }
|
7
7
|
|
8
8
|
describe '#capture_help' do
|
9
9
|
let(:help_attrs) { commands_helper.commands_help_attrs }
|
10
|
-
let(:bot_help_attrs) { help_attrs.find { |k| k.
|
11
|
-
let(:command_help_attrs) { help_attrs.find { |k| k.
|
10
|
+
let(:bot_help_attrs) { help_attrs.find { |k| k.klass == bot_class } }
|
11
|
+
let(:command_help_attrs) { help_attrs.find { |k| k.klass == command_class } }
|
12
12
|
|
13
13
|
it 'should save bot class name' do
|
14
14
|
expect(bot_help_attrs).to be
|
@@ -62,7 +62,8 @@ describe SlackRubyBot::CommandsHelper do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
describe '#bot_desc_and_commands' do
|
65
|
-
let(:
|
65
|
+
let(:bot_desc_and_commands) { commands_helper.bot_desc_and_commands }
|
66
|
+
let(:bot_desc) { bot_desc_and_commands.first }
|
66
67
|
|
67
68
|
it 'returns bot name and description' do
|
68
69
|
expect(bot_desc).to include('*Weather Bot* - This bot tells you the weather.')
|
@@ -81,15 +82,43 @@ describe SlackRubyBot::CommandsHelper do
|
|
81
82
|
it 'do not show description for command without description' do
|
82
83
|
expect(bot_desc).to include("*command_without_description*\n")
|
83
84
|
end
|
85
|
+
|
86
|
+
context 'subclasses' do
|
87
|
+
let(:another_bot_base) { Class.new(SlackRubyBot::Bot) }
|
88
|
+
let!(:another_bot) do
|
89
|
+
Class.new(another_bot_base) do
|
90
|
+
help do
|
91
|
+
title 'Creating your own base class works too!'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'expose help commands' do
|
97
|
+
expect(bot_desc_and_commands).to include("*Creating your own base class works too!*\n\n*Commands:*\n")
|
98
|
+
end
|
99
|
+
end
|
84
100
|
end
|
85
101
|
|
86
102
|
describe '#other_commands_descs' do
|
87
|
-
let(:
|
88
|
-
let(:
|
103
|
+
let(:another_command_base) { Class.new(SlackRubyBot::Commands::Base) }
|
104
|
+
let!(:another_command) do
|
105
|
+
Class.new(another_command_base) do
|
106
|
+
help do
|
107
|
+
title 'Creating your own base class works too!'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
let(:other_commands_descs) { commands_helper.other_commands_descs }
|
113
|
+
let(:hello_command_desc) { other_commands_descs.find { |desc| desc =~ /\*hello\*/ } }
|
89
114
|
|
90
115
|
it 'returns command name and description' do
|
91
116
|
expect(hello_command_desc).to eq('*hello* - Says hello.')
|
92
117
|
end
|
118
|
+
|
119
|
+
it 'includes commands who do not directly inherit from provided base class' do
|
120
|
+
expect(other_commands_descs).to include('*Creating your own base class works too!*')
|
121
|
+
end
|
93
122
|
end
|
94
123
|
|
95
124
|
describe '#command_full_desc' 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.
|
4
|
+
version: 0.10.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:
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
205
205
|
- spec/slack-ruby-bot/commands/bot_message_spec.rb
|
206
206
|
- spec/slack-ruby-bot/commands/bot_spec.rb
|
207
|
+
- spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
|
207
208
|
- spec/slack-ruby-bot/commands/commands_precedence_spec.rb
|
208
209
|
- spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
|
209
210
|
- spec/slack-ruby-bot/commands/commands_spaces_spec.rb
|
@@ -267,6 +268,7 @@ test_files:
|
|
267
268
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
268
269
|
- spec/slack-ruby-bot/commands/bot_message_spec.rb
|
269
270
|
- spec/slack-ruby-bot/commands/bot_spec.rb
|
271
|
+
- spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
|
270
272
|
- spec/slack-ruby-bot/commands/commands_precedence_spec.rb
|
271
273
|
- spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
|
272
274
|
- spec/slack-ruby-bot/commands/commands_spaces_spec.rb
|