slack-ruby-bot 0.10.5 → 0.11.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 +52 -16
- data/CHANGELOG.md +8 -0
- data/Gemfile +3 -0
- data/README.md +92 -5
- data/Rakefile +1 -1
- data/examples/inventory/Gemfile +1 -1
- data/examples/market/Gemfile +1 -1
- data/examples/market/marketbot.rb +1 -1
- data/examples/minimal/Gemfile +1 -1
- data/examples/weather/Gemfile +1 -1
- data/lib/slack-ruby-bot.rb +0 -1
- data/lib/slack-ruby-bot/app.rb +10 -8
- data/lib/slack-ruby-bot/client.rb +8 -6
- data/lib/slack-ruby-bot/commands/base.rb +41 -8
- data/lib/slack-ruby-bot/commands/help.rb +4 -4
- data/lib/slack-ruby-bot/commands/{help → support}/attrs.rb +1 -1
- data/lib/slack-ruby-bot/commands/support/help.rb +80 -0
- data/lib/slack-ruby-bot/commands/support/match.rb +22 -0
- data/lib/slack-ruby-bot/config.rb +1 -1
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +5 -3
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +5 -3
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +2 -2
- data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +2 -2
- data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +3 -1
- data/lib/slack-ruby-bot/server.rb +1 -1
- data/lib/slack-ruby-bot/version.rb +1 -1
- data/slack-ruby-bot.gemspec +2 -2
- data/spec/slack-ruby-bot/commands/attachment_spec.rb +102 -0
- data/spec/slack-ruby-bot/commands/bot_message_spec.rb +1 -1
- data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +6 -0
- data/spec/slack-ruby-bot/commands/{help → support}/attrs_spec.rb +1 -1
- data/spec/slack-ruby-bot/{support/commands_helper_spec.rb → commands/support/help_spec.rb} +23 -9
- data/spec/slack-ruby-bot/commands/support/match_spec.rb +54 -0
- data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +1 -1
- data/spec/slack-ruby-bot/hooks/message_spec.rb +1 -1
- data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -2
- data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +8 -3
- data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +11 -0
- data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +15 -0
- data/spec/slack-ruby-bot/server_spec.rb +2 -2
- metadata +28 -23
- data/lib/slack-ruby-bot/support/commands_helper.rb +0 -76
@@ -0,0 +1,54 @@
|
|
1
|
+
describe SlackRubyBot::Commands::Support::Match do
|
2
|
+
context 'initialized with invalid args' do
|
3
|
+
subject { -> { described_class.new('invalid-match-data') } }
|
4
|
+
it 'raises ArgumentError' do
|
5
|
+
expect(subject)
|
6
|
+
.to raise_error(ArgumentError, 'match_data should be a type of MatchData')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'initalized without attachment' do
|
11
|
+
subject do
|
12
|
+
match_data = /(?<group1>foo)(?<group2>bar)/.match('foobar')
|
13
|
+
described_class.new(match_data)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'responds to MatchData methods' do
|
17
|
+
MatchData.public_instance_methods(false).each do |method|
|
18
|
+
expect(subject).to respond_to(method)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#attachment' do
|
23
|
+
it { expect(subject.attachment).to be_nil }
|
24
|
+
end
|
25
|
+
describe '#attachment_field' do
|
26
|
+
it { expect(subject.attachment_field).to be_nil }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'initialized with attachment' do
|
31
|
+
let(:attachment) { Hashie::Mash.new(text: 'Some text') }
|
32
|
+
let(:attachment_field) { :text }
|
33
|
+
subject do
|
34
|
+
match_data = /(?<group1>foo)(?<group2>bar)/.match('foobar')
|
35
|
+
described_class.new(match_data, attachment, attachment_field)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'responds to MatchData methods' do
|
39
|
+
MatchData.public_instance_methods(false).each do |method|
|
40
|
+
expect(subject).to respond_to(method)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#attachment' do
|
45
|
+
it { expect(subject.attachment).not_to be_nil }
|
46
|
+
it { expect(subject.attachment).to be_kind_of(Hash) }
|
47
|
+
it { expect(subject.attachment).to eq(attachment) }
|
48
|
+
end
|
49
|
+
describe '#attachment_field' do
|
50
|
+
it { expect(subject.attachment_field).not_to be_nil }
|
51
|
+
it { expect(subject.attachment_field).to eq(:text) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -20,7 +20,7 @@ describe SlackRubyBot::Hooks::HookSupport do
|
|
20
20
|
describe 'hook code blocks' do
|
21
21
|
it "let's you define class level code blocks" do
|
22
22
|
expect(subject.hook_blocks.size).to eq(2)
|
23
|
-
expect(subject.hook_blocks.keys).to eq %w
|
23
|
+
expect(subject.hook_blocks.keys).to eq %w[hello goodbye]
|
24
24
|
|
25
25
|
expect(subject.hook_blocks['hello'].size).to eq(2)
|
26
26
|
expect(subject.hook_blocks['goodbye'].size).to eq(1)
|
@@ -14,7 +14,7 @@ describe SlackRubyBot::Hooks::Message do
|
|
14
14
|
it 'returns only built in command classes' do
|
15
15
|
expect(built_in_command_classes).to include SlackRubyBot::Commands::Hi
|
16
16
|
expect(built_in_command_classes).to include SlackRubyBot::Commands::Default
|
17
|
-
expect(built_in_command_classes).to include SlackRubyBot::Commands::
|
17
|
+
expect(built_in_command_classes).to include SlackRubyBot::Commands::Help
|
18
18
|
expect(built_in_command_classes).to_not include SlackRubyBot::Bot
|
19
19
|
end
|
20
20
|
it 'does not return unknown command class' do
|
@@ -59,7 +59,7 @@ describe SlackRubyBot::MVC::Controller::Base, 'setup' do
|
|
59
59
|
expect(message: " #{SlackRubyBot.config.user} quxo red").to respond_with_slack_message('quxo: red')
|
60
60
|
expect(model.client).to be_kind_of(SlackRubyBot::Client)
|
61
61
|
expect(model.data).to be_kind_of(Hash)
|
62
|
-
expect(model.match).to be_kind_of(
|
62
|
+
expect(model.match).to be_kind_of(SlackRubyBot::Commands::Support::Match)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'passes client, data, and match args to the view' do
|
@@ -69,7 +69,7 @@ describe SlackRubyBot::MVC::Controller::Base, 'setup' do
|
|
69
69
|
expect(message: " #{SlackRubyBot.config.user} quxo red").to respond_with_slack_message('quxo: red')
|
70
70
|
expect(view.client).to be_kind_of(SlackRubyBot::Client)
|
71
71
|
expect(view.data).to be_kind_of(Hash)
|
72
|
-
expect(view.match).to be_kind_of(
|
72
|
+
expect(view.match).to be_kind_of(SlackRubyBot::Commands::Support::Match)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
describe RSpec do
|
2
2
|
let! :command do
|
3
3
|
Class.new(SlackRubyBot::Commands::Base) do
|
4
|
-
command 'raise'
|
5
|
-
|
6
|
-
def self.call(_client, _data, match)
|
4
|
+
command 'raise' do |_client, _data, match|
|
7
5
|
raise ArgumentError, match[:command]
|
8
6
|
end
|
7
|
+
|
8
|
+
attachment 'raise' do |_client, data, _match|
|
9
|
+
raise ArgumentError, data.attachments[0].pretext
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
def app
|
@@ -14,4 +16,7 @@ describe RSpec do
|
|
14
16
|
it 'respond_with_error' do
|
15
17
|
expect(message: "#{SlackRubyBot.config.user} raise").to respond_with_error(ArgumentError, 'raise')
|
16
18
|
end
|
19
|
+
it 'respond_with_error_using_attachment_match' do
|
20
|
+
expect(attachments: { pretext: 'raise' }).to respond_with_error(ArgumentError, 'raise')
|
21
|
+
end
|
17
22
|
end
|
@@ -12,6 +12,9 @@ describe RSpec do
|
|
12
12
|
client.say(text: "response #{i}", channel: data.channel)
|
13
13
|
end
|
14
14
|
end
|
15
|
+
attachment 'respond with attachment text' do |client, data, _match|
|
16
|
+
client.say(text: data.attachments[0].text.to_s, channel: data.channel)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
@@ -46,4 +49,12 @@ describe RSpec do
|
|
46
49
|
expect(message: "#{SlackRubyBot.config.user} respond 5 times")
|
47
50
|
.not_to respond_with_slack_message('response 7')
|
48
51
|
end
|
52
|
+
it 'respond_with_single_message_using_attachment_match' do
|
53
|
+
attachment = {
|
54
|
+
pretext: 'respond with attachment text',
|
55
|
+
text: 'foobar'
|
56
|
+
}
|
57
|
+
expect(attachments: attachment)
|
58
|
+
.to respond_with_slack_message('foobar')
|
59
|
+
end
|
49
60
|
end
|
@@ -11,6 +11,11 @@ describe RSpec do
|
|
11
11
|
client.say(text: "response #{i}", channel: data.channel)
|
12
12
|
end
|
13
13
|
end
|
14
|
+
attachment 'respond with attachment title' do |client, data, _match|
|
15
|
+
data[:attachments].each do |attachment|
|
16
|
+
client.say(text: "response #{attachment.title}", channel: data.channel)
|
17
|
+
end
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
@@ -42,4 +47,14 @@ describe RSpec do
|
|
42
47
|
expect(message: "#{SlackRubyBot.config.user} respond with as_user")
|
43
48
|
.to respond_with_slack_messages(expected_responses)
|
44
49
|
end
|
50
|
+
it 'respond_with_multiple_messages_using_attachment_match' do
|
51
|
+
attachments = []
|
52
|
+
expected_responses = []
|
53
|
+
5.times do |i|
|
54
|
+
attachments.push(title: "title #{i}", pretext: 'respond with attachment title')
|
55
|
+
expected_responses.push("response title #{i}")
|
56
|
+
end
|
57
|
+
expect(attachments: attachments)
|
58
|
+
.to respond_with_slack_messages(expected_responses)
|
59
|
+
end
|
45
60
|
end
|
@@ -26,8 +26,8 @@ describe SlackRubyBot::Server do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'aliases' do
|
29
|
-
server = SlackRubyBot::Server.new(aliases: %w
|
30
|
-
expect(server.send(:client).aliases).to eq %w
|
29
|
+
server = SlackRubyBot::Server.new(aliases: %w[foo bar])
|
30
|
+
expect(server.send(:client).aliases).to eq %w[foo bar]
|
31
31
|
expect(server.send(:client).names).to include 'foo'
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.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: 2018-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.6.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rack-test
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,21 +81,21 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.51.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
|
-
version:
|
96
|
+
version: 0.51.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: vcr
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,19 +109,19 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: webmock
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
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
|
-
version: 0
|
124
|
+
version: '0'
|
125
125
|
description:
|
126
126
|
email: dblock@dblock.org
|
127
127
|
executables: []
|
@@ -169,8 +169,10 @@ files:
|
|
169
169
|
- lib/slack-ruby-bot/commands/about.rb
|
170
170
|
- lib/slack-ruby-bot/commands/base.rb
|
171
171
|
- lib/slack-ruby-bot/commands/help.rb
|
172
|
-
- lib/slack-ruby-bot/commands/help/attrs.rb
|
173
172
|
- lib/slack-ruby-bot/commands/hi.rb
|
173
|
+
- lib/slack-ruby-bot/commands/support/attrs.rb
|
174
|
+
- lib/slack-ruby-bot/commands/support/help.rb
|
175
|
+
- lib/slack-ruby-bot/commands/support/match.rb
|
174
176
|
- lib/slack-ruby-bot/commands/unknown.rb
|
175
177
|
- lib/slack-ruby-bot/config.rb
|
176
178
|
- lib/slack-ruby-bot/hooks.rb
|
@@ -196,7 +198,6 @@ files:
|
|
196
198
|
- lib/slack-ruby-bot/rspec/support/spec_helpers.rb
|
197
199
|
- lib/slack-ruby-bot/rspec/support/vcr.rb
|
198
200
|
- lib/slack-ruby-bot/server.rb
|
199
|
-
- lib/slack-ruby-bot/support/commands_helper.rb
|
200
201
|
- lib/slack-ruby-bot/support/loggable.rb
|
201
202
|
- lib/slack-ruby-bot/version.rb
|
202
203
|
- lib/slack_ruby_bot.rb
|
@@ -213,6 +214,7 @@ files:
|
|
213
214
|
- spec/slack-ruby-bot/client_spec.rb
|
214
215
|
- spec/slack-ruby-bot/commands/about_spec.rb
|
215
216
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
217
|
+
- spec/slack-ruby-bot/commands/attachment_spec.rb
|
216
218
|
- spec/slack-ruby-bot/commands/bot_message_spec.rb
|
217
219
|
- spec/slack-ruby-bot/commands/bot_spec.rb
|
218
220
|
- spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
|
@@ -226,7 +228,6 @@ files:
|
|
226
228
|
- spec/slack-ruby-bot/commands/commands_with_expression_spec.rb
|
227
229
|
- spec/slack-ruby-bot/commands/direct_messages_spec.rb
|
228
230
|
- spec/slack-ruby-bot/commands/empty_text_spec.rb
|
229
|
-
- spec/slack-ruby-bot/commands/help/attrs_spec.rb
|
230
231
|
- spec/slack-ruby-bot/commands/help_spec.rb
|
231
232
|
- spec/slack-ruby-bot/commands/hi_spec.rb
|
232
233
|
- spec/slack-ruby-bot/commands/match_spec.rb
|
@@ -239,6 +240,9 @@ files:
|
|
239
240
|
- spec/slack-ruby-bot/commands/send_gif_spec.rb
|
240
241
|
- spec/slack-ruby-bot/commands/send_message_spec.rb
|
241
242
|
- spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb
|
243
|
+
- spec/slack-ruby-bot/commands/support/attrs_spec.rb
|
244
|
+
- spec/slack-ruby-bot/commands/support/help_spec.rb
|
245
|
+
- spec/slack-ruby-bot/commands/support/match_spec.rb
|
242
246
|
- spec/slack-ruby-bot/commands/unknown_spec.rb
|
243
247
|
- spec/slack-ruby-bot/config_spec.rb
|
244
248
|
- spec/slack-ruby-bot/hooks/hook_support_spec.rb
|
@@ -249,7 +253,6 @@ files:
|
|
249
253
|
- spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb
|
250
254
|
- spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb
|
251
255
|
- spec/slack-ruby-bot/server_spec.rb
|
252
|
-
- spec/slack-ruby-bot/support/commands_helper_spec.rb
|
253
256
|
- spec/slack-ruby-bot/support/loggable_spec.rb
|
254
257
|
- spec/slack-ruby-bot/version_spec.rb
|
255
258
|
- spec/spec_helper.rb
|
@@ -273,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
276
|
version: 1.3.6
|
274
277
|
requirements: []
|
275
278
|
rubyforge_project:
|
276
|
-
rubygems_version: 2.
|
279
|
+
rubygems_version: 2.4.5.3
|
277
280
|
signing_key:
|
278
281
|
specification_version: 4
|
279
282
|
summary: The easiest way to write a Slack bot in Ruby.
|
@@ -282,6 +285,7 @@ test_files:
|
|
282
285
|
- spec/slack-ruby-bot/client_spec.rb
|
283
286
|
- spec/slack-ruby-bot/commands/about_spec.rb
|
284
287
|
- spec/slack-ruby-bot/commands/aliases_spec.rb
|
288
|
+
- spec/slack-ruby-bot/commands/attachment_spec.rb
|
285
289
|
- spec/slack-ruby-bot/commands/bot_message_spec.rb
|
286
290
|
- spec/slack-ruby-bot/commands/bot_spec.rb
|
287
291
|
- spec/slack-ruby-bot/commands/commands_command_classes_spec.rb
|
@@ -295,7 +299,6 @@ test_files:
|
|
295
299
|
- spec/slack-ruby-bot/commands/commands_with_expression_spec.rb
|
296
300
|
- spec/slack-ruby-bot/commands/direct_messages_spec.rb
|
297
301
|
- spec/slack-ruby-bot/commands/empty_text_spec.rb
|
298
|
-
- spec/slack-ruby-bot/commands/help/attrs_spec.rb
|
299
302
|
- spec/slack-ruby-bot/commands/help_spec.rb
|
300
303
|
- spec/slack-ruby-bot/commands/hi_spec.rb
|
301
304
|
- spec/slack-ruby-bot/commands/match_spec.rb
|
@@ -308,6 +311,9 @@ test_files:
|
|
308
311
|
- spec/slack-ruby-bot/commands/send_gif_spec.rb
|
309
312
|
- spec/slack-ruby-bot/commands/send_message_spec.rb
|
310
313
|
- spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb
|
314
|
+
- spec/slack-ruby-bot/commands/support/attrs_spec.rb
|
315
|
+
- spec/slack-ruby-bot/commands/support/help_spec.rb
|
316
|
+
- spec/slack-ruby-bot/commands/support/match_spec.rb
|
311
317
|
- spec/slack-ruby-bot/commands/unknown_spec.rb
|
312
318
|
- spec/slack-ruby-bot/config_spec.rb
|
313
319
|
- spec/slack-ruby-bot/hooks/hook_support_spec.rb
|
@@ -318,7 +324,6 @@ test_files:
|
|
318
324
|
- spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb
|
319
325
|
- spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb
|
320
326
|
- spec/slack-ruby-bot/server_spec.rb
|
321
|
-
- spec/slack-ruby-bot/support/commands_helper_spec.rb
|
322
327
|
- spec/slack-ruby-bot/support/loggable_spec.rb
|
323
328
|
- spec/slack-ruby-bot/version_spec.rb
|
324
329
|
- spec/spec_helper.rb
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
require_relative '../commands/help/attrs'
|
3
|
-
|
4
|
-
module SlackRubyBot
|
5
|
-
class CommandsHelper
|
6
|
-
include Singleton
|
7
|
-
attr_reader :commands_help_attrs
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@commands_help_attrs = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def capture_help(klass, &block)
|
14
|
-
k = Commands::Help::Attrs.new(klass)
|
15
|
-
k.instance_eval(&block)
|
16
|
-
@commands_help_attrs << k
|
17
|
-
end
|
18
|
-
|
19
|
-
def bot_desc_and_commands
|
20
|
-
collect_help_attrs(bot_help_attrs) do |help_attrs|
|
21
|
-
bot_commands_descs = collect_name_and_desc(help_attrs.commands)
|
22
|
-
"#{command_name_and_desc(help_attrs)}\n\n*Commands:*\n#{bot_commands_descs.join("\n")}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def other_commands_descs
|
27
|
-
collect_name_and_desc(other_commands_help_attrs)
|
28
|
-
end
|
29
|
-
|
30
|
-
def command_full_desc(name)
|
31
|
-
unescaped_name = Slack::Messages::Formatting.unescape(name)
|
32
|
-
help_attrs = find_command_help_attrs(unescaped_name)
|
33
|
-
return "There's no command *#{unescaped_name}*" unless help_attrs
|
34
|
-
return "There's no description for command *#{unescaped_name}*" if help_attrs.command_long_desc.blank?
|
35
|
-
"#{command_name_and_desc(help_attrs)}\n\n#{help_attrs.command_long_desc}"
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def find_command_help_attrs(name)
|
41
|
-
help_attrs = commands_help_attrs.find { |k| k.command_name == name }
|
42
|
-
return help_attrs if help_attrs
|
43
|
-
commands_help_attrs.each { |k| k.commands.each { |c| return c if c.command_name == name } }
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
def collect_help_attrs(help_attrs)
|
48
|
-
help_attrs_with_present_names(help_attrs).map do |ha|
|
49
|
-
yield(ha)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def collect_name_and_desc(help_attrs)
|
54
|
-
collect_help_attrs(help_attrs) do |ha|
|
55
|
-
command_name_and_desc(ha)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def command_name_and_desc(help_attrs)
|
60
|
-
desc = help_attrs.command_desc.present? ? " - #{help_attrs.command_desc}" : ''
|
61
|
-
"*#{help_attrs.command_name}*#{desc}"
|
62
|
-
end
|
63
|
-
|
64
|
-
def help_attrs_with_present_names(help_attrs)
|
65
|
-
help_attrs.select { |k| k.command_name.present? }
|
66
|
-
end
|
67
|
-
|
68
|
-
def bot_help_attrs
|
69
|
-
commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Bot) }
|
70
|
-
end
|
71
|
-
|
72
|
-
def other_commands_help_attrs
|
73
|
-
commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Commands::Base) && !k.klass.ancestors.include?(SlackRubyBot::Bot) }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|