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
data/Rakefile
CHANGED
data/TUTORIAL.md
CHANGED
@@ -36,6 +36,10 @@ end
|
|
36
36
|
|
37
37
|
Run `bundle install` to get all the gems.
|
38
38
|
|
39
|
+
##### Passenger
|
40
|
+
|
41
|
+
To use passenger standalone change `gem 'puma'` to `gem 'passenger'`
|
42
|
+
|
39
43
|
#### Application
|
40
44
|
|
41
45
|
Create a folder called `slack-mathbot` and inside of it create `bot.rb`.
|
@@ -141,6 +145,25 @@ Create a `Procfile` which `foreman` will use when you run the `foreman start` co
|
|
141
145
|
web: bundle exec puma -p $PORT
|
142
146
|
```
|
143
147
|
|
148
|
+
#### Passenger
|
149
|
+
|
150
|
+
If you want to use passenger locally change it to:
|
151
|
+
|
152
|
+
```
|
153
|
+
web: bundle exec passenger -p $PORT
|
154
|
+
```
|
155
|
+
|
156
|
+
Add the following folders to your project root: 'tmp/', 'log/', 'public/'
|
157
|
+
Passenger will automatically save the local logs to these folders.
|
158
|
+
|
159
|
+
Optional: Change the port in a `Passenger.json`
|
160
|
+
|
161
|
+
```
|
162
|
+
{
|
163
|
+
"port": "1234"
|
164
|
+
}
|
165
|
+
```
|
166
|
+
|
144
167
|
### Run the Bot
|
145
168
|
|
146
169
|
Run `foreman start`. Your bot should be running.
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,50 @@
|
|
1
1
|
Upgrading SlackRubyBot
|
2
2
|
======================
|
3
3
|
|
4
|
+
### Upgrading to >= 0.16.0
|
5
|
+
|
6
|
+
#### Removed GIF support
|
7
|
+
|
8
|
+
GIF, Giphy and other animated GIF support has been removed. Remove `gif` options from all `client.say(gif: 'keyword')` method calls, the `GIPHY_API_KEY` ENV var, `gem 'giphy'` or `gem 'GiphyClient'`, and any references to `send_gifs`. The previously deprecated `SlackRubyBot::Commands::Base#send_message`, `send_message_with_gif` and `send_gif` methods have also been removed.
|
9
|
+
|
10
|
+
See [#261](https://github.com/slack-ruby/slack-ruby-bot/issues/261) for details.
|
11
|
+
|
12
|
+
#### Removed deprecated `server.hooks`
|
13
|
+
|
14
|
+
The previously deprecated `SlackRubyBot::Server#hooks` has been removed.
|
15
|
+
|
16
|
+
See [#266](https://github.com/slack-ruby/slack-ruby-bot/issues/266) for details.
|
17
|
+
|
18
|
+
### Upgrading to >= 0.15.0
|
19
|
+
|
20
|
+
#### Set up VCR explicitly
|
21
|
+
|
22
|
+
Requiring `slack-ruby-bot/rspec` will no longer set up [VCR](https://rubygems.org/gems/vcr) anymore. If your spec suite implicitly relies on this you would need to set up VCR explicitly in your spec suite. Just follow standard VCR documentation.
|
23
|
+
|
24
|
+
See [#258](https://github.com/slack-ruby/slack-ruby-bot/pull/258) for more information.
|
25
|
+
|
26
|
+
### Upgrading to >= 0.14.0
|
27
|
+
|
28
|
+
#### Bot Messages Disabled
|
29
|
+
|
30
|
+
By default bots will no longer respond to other bots. This caused confusing "I don't understand this command." errors when DMing the bot and rendering URLs that were being sent back as DMs. If you wish to restore the old behavior, set `allow_bot_messages` to `true`.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
SlackRubyBot.configure do |config|
|
34
|
+
config.allow_bot_messages = true
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
See [#250](https://github.com/slack-ruby/slack-ruby-bot/pull/250) for more information.
|
39
|
+
|
40
|
+
### Upgrading to >= 0.13.0
|
41
|
+
|
42
|
+
#### Minimum Ruby Version
|
43
|
+
|
44
|
+
Ruby 2.3 or later is now required.
|
45
|
+
|
46
|
+
See [#246](https://github.com/slack-ruby/slack-ruby-bot/pull/246) for more information.
|
47
|
+
|
4
48
|
### Upgrading to >= 0.12.0
|
5
49
|
|
6
50
|
#### Remove any references to `SlackRubyBot::Server#restart!`
|
data/examples/inventory/Gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'slack-ruby-bot'
|
2
4
|
require 'sqlite3'
|
3
5
|
|
@@ -56,6 +58,7 @@ class InventoryController < SlackRubyBot::MVC::Controller::Base
|
|
56
58
|
def notify_admin
|
57
59
|
row = _row.first
|
58
60
|
return if row[:quantity].to_i.zero?
|
61
|
+
|
59
62
|
view.email_admin("Inventory item #{row[:name]} needs to be refilled.")
|
60
63
|
view.say(channel: data.channel, text: "Administrator notified via email to refill #{row[:name]}.")
|
61
64
|
end
|
@@ -93,6 +96,7 @@ class InventoryModel < SlackRubyBot::MVC::Model::Base
|
|
93
96
|
count = 0
|
94
97
|
count += 1 while results.next
|
95
98
|
return if count < 4
|
99
|
+
|
96
100
|
add_item "'Audi',3,52642"
|
97
101
|
add_item "'Mercedes',1,57127"
|
98
102
|
add_item "'Skoda',5,9000"
|
@@ -241,7 +245,7 @@ class InventoryBot < SlackRubyBot::Bot
|
|
241
245
|
view = InventoryView.new
|
242
246
|
@controller = InventoryController.new(model, view)
|
243
247
|
@controller.class.command_class.routes.each do |route|
|
244
|
-
|
248
|
+
warn route.inspect
|
245
249
|
end
|
246
250
|
end
|
247
251
|
|
data/examples/market/Gemfile
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'iex-ruby-client'
|
1
4
|
require 'slack-ruby-bot'
|
2
|
-
require 'yahoo-finance'
|
3
5
|
|
4
6
|
SlackRubyBot::Client.logger.level = Logger::WARN
|
5
7
|
|
6
8
|
class MarketBot < SlackRubyBot::Bot
|
7
9
|
scan(/([A-Z]{2,5}+)/) do |client, data, stocks|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
stocks.each do |stock|
|
11
|
+
begin
|
12
|
+
quote = IEX::Resources::Quote.get(stock.first)
|
13
|
+
|
14
|
+
client.web_client.chat_postMessage(
|
15
|
+
channel: data.channel,
|
16
|
+
as_user: true,
|
17
|
+
attachments: [
|
18
|
+
{
|
19
|
+
fallback: "#{quote.company_name} (#{quote.symbol}): $#{quote.latest_price}",
|
20
|
+
title: "#{quote.company_name} (#{quote.symbol})",
|
21
|
+
text: "$#{quote.latest_price} (#{quote.change_percent})",
|
22
|
+
color: quote.change.to_f > 0 ? '#00FF00' : '#FF0000'
|
23
|
+
}
|
24
|
+
]
|
25
|
+
)
|
26
|
+
rescue IEX::Errors::SymbolNotFoundError
|
27
|
+
logger.warn "no stock found for symbol #{stock}"
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
data/examples/minimal/Gemfile
CHANGED
data/examples/minimal/pongbot.rb
CHANGED
data/examples/weather/Gemfile
CHANGED
data/lib/config/application.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
|
2
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
5
|
|
4
6
|
require 'boot'
|
5
7
|
|
6
|
-
Dir[File.expand_path('
|
8
|
+
Dir[File.expand_path('../initializers', __dir__) + '/**/*.rb'].sort.each do |file|
|
7
9
|
require file
|
8
10
|
end
|
9
11
|
|
10
|
-
require File.expand_path('
|
12
|
+
require File.expand_path('application', __dir__)
|
11
13
|
|
12
14
|
require 'slack_ruby_bot'
|
data/lib/config/boot.rb
CHANGED
data/lib/config/environment.rb
CHANGED
data/lib/slack-ruby-bot.rb
CHANGED
data/lib/slack-ruby-bot/about.rb
CHANGED
data/lib/slack-ruby-bot/app.rb
CHANGED
@@ -1,22 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackRubyBot
|
2
4
|
class App < Server
|
3
|
-
def initialize(options = {})
|
4
|
-
SlackRubyBot.configure do |config|
|
5
|
-
config.token = ENV['SLACK_API_TOKEN'] || raise("Missing ENV['SLACK_API_TOKEN'].")
|
6
|
-
config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV['SLACK_RUBY_BOT_ALIASES']
|
7
|
-
end
|
8
|
-
Slack.configure do |config|
|
9
|
-
config.token = SlackRubyBot.config.token
|
10
|
-
end
|
11
|
-
super
|
12
|
-
end
|
13
|
-
|
14
5
|
def config
|
15
6
|
SlackRubyBot.config
|
16
7
|
end
|
17
8
|
|
18
9
|
def self.instance
|
19
|
-
@instance ||=
|
10
|
+
@instance ||= begin
|
11
|
+
configure!
|
12
|
+
new(token: SlackRubyBot.config.token)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure!
|
17
|
+
SlackRubyBot.configure do |config|
|
18
|
+
config.token = ENV['SLACK_API_TOKEN'] if ENV.key?('SLACK_API_TOKEN')
|
19
|
+
raise('Missing Slack API Token.') unless config.token.present?
|
20
|
+
|
21
|
+
config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV.key?('SLACK_RUBY_BOT_ALIASES')
|
22
|
+
end
|
23
|
+
Slack.configure do |config|
|
24
|
+
config.token = SlackRubyBot.config.token
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
private
|
data/lib/slack-ruby-bot/bot.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackRubyBot
|
2
4
|
class Bot < SlackRubyBot::Commands::Base
|
3
5
|
delegate :client, to: :instance
|
@@ -11,7 +13,7 @@ module SlackRubyBot
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.call(client, data, _match)
|
14
|
-
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!"
|
16
|
+
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!")
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -1,13 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackRubyBot
|
2
4
|
class Client < Slack::RealTime::Client
|
3
5
|
include Loggable
|
4
6
|
attr_accessor :aliases
|
5
|
-
attr_accessor :
|
7
|
+
attr_accessor :allow_bot_messages
|
8
|
+
attr_accessor :allow_message_loops
|
6
9
|
|
7
10
|
def initialize(attrs = {})
|
8
11
|
super(attrs)
|
9
12
|
@aliases = attrs[:aliases]
|
10
|
-
@
|
13
|
+
@allow_message_loops = attrs[:allow_message_loops]
|
14
|
+
@allow_bot_messages = attrs[:allow_bot_messages]
|
15
|
+
end
|
16
|
+
|
17
|
+
def allow_message_loops?
|
18
|
+
@allow_message_loops.nil? ? SlackRubyBot::Config.allow_message_loops? : !!@allow_message_loops
|
19
|
+
end
|
20
|
+
|
21
|
+
def allow_bot_messages?
|
22
|
+
@allow_bot_messages.nil? ? SlackRubyBot::Config.allow_bot_messages? : !!@allow_bot_messages
|
23
|
+
end
|
24
|
+
|
25
|
+
def message_to_self?(data)
|
26
|
+
!!(self.self && self.self.id == data.user)
|
27
|
+
end
|
28
|
+
|
29
|
+
def bot_message?(data)
|
30
|
+
data.subtype == 'bot_message'
|
11
31
|
end
|
12
32
|
|
13
33
|
def names
|
@@ -29,13 +49,8 @@ module SlackRubyBot
|
|
29
49
|
name && names.include?(name.downcase)
|
30
50
|
end
|
31
51
|
|
32
|
-
def send_gifs?
|
33
|
-
return false unless defined?(Giphy)
|
34
|
-
send_gifs.nil? ? SlackRubyBot::Config.send_gifs? : send_gifs
|
35
|
-
end
|
36
|
-
|
37
52
|
def name
|
38
|
-
SlackRubyBot.config.user ||
|
53
|
+
SlackRubyBot.config.user || self.self&.name
|
39
54
|
end
|
40
55
|
|
41
56
|
def url
|
@@ -43,21 +58,8 @@ module SlackRubyBot
|
|
43
58
|
end
|
44
59
|
|
45
60
|
def say(options = {})
|
46
|
-
|
47
|
-
|
48
|
-
keywords = options.delete(:gif)
|
49
|
-
# text
|
50
|
-
text = options.delete(:text)
|
51
|
-
if keywords && send_gifs?
|
52
|
-
gif = begin
|
53
|
-
Giphy.random(keywords)
|
54
|
-
rescue StandardError => e
|
55
|
-
logger.warn "Giphy.random: #{e.message}"
|
56
|
-
nil
|
57
|
-
end
|
58
|
-
end
|
59
|
-
text = [text, gif && gif.image_url.to_s].compact.join("\n")
|
60
|
-
message({ text: text }.merge(options))
|
61
|
+
logger.warn '[DEPRECATION] `gif:` is deprecated and has no effect.' if options.key?(:gif)
|
62
|
+
message({ text: '' }.merge(options))
|
61
63
|
end
|
62
64
|
end
|
63
65
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackRubyBot
|
2
4
|
module Commands
|
3
5
|
class Default < Base
|
@@ -5,7 +7,7 @@ module SlackRubyBot
|
|
5
7
|
match(/^#{bot_matcher}$/u)
|
6
8
|
|
7
9
|
def self.call(client, data, _match)
|
8
|
-
client.say(channel: data.channel, text: SlackRubyBot::ABOUT
|
10
|
+
client.say(channel: data.channel, text: SlackRubyBot::ABOUT)
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'support/match'
|
2
4
|
require_relative 'support/help'
|
3
5
|
|
@@ -14,25 +16,6 @@ module SlackRubyBot
|
|
14
16
|
SlackRubyBot::Commands::Base.command_classes << subclass
|
15
17
|
end
|
16
18
|
|
17
|
-
def send_message(client, channel, text, options = {})
|
18
|
-
logger.warn '[DEPRECATION] `send_message` is deprecated. Please use `client.say` instead.'
|
19
|
-
if text && !text.length.empty?
|
20
|
-
client.say(options.merge(channel: channel, text: text))
|
21
|
-
else
|
22
|
-
client.say(options.merge(channel: channel, text: 'Nothing to see here.', gif: 'nothing'))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def send_message_with_gif(client, channel, text, keywords, options = {})
|
27
|
-
logger.warn '[DEPRECATION] `send_message_with_gif` is deprecated. Please use `client.say` instead.'
|
28
|
-
client.say(options.merge(channel: channel, text: text, gif: keywords))
|
29
|
-
end
|
30
|
-
|
31
|
-
def send_gif(client, channel, keywords, options = {})
|
32
|
-
logger.warn '[DEPRECATION] `send_gif` is deprecated. Please use `client.say` instead.'
|
33
|
-
client.say(options.merge(channel: channel, text: '', gif: keywords))
|
34
|
-
end
|
35
|
-
|
36
19
|
def help(&block)
|
37
20
|
Support::Help.instance.capture_help(self, &block)
|
38
21
|
end
|
@@ -48,31 +31,37 @@ module SlackRubyBot
|
|
48
31
|
|
49
32
|
def command(*values, &block)
|
50
33
|
values = values.map { |value| value.is_a?(Regexp) ? value.source : Regexp.escape(value) }.join('|')
|
51
|
-
match Regexp.new("^#{bot_matcher}[
|
34
|
+
match Regexp.new("^#{bot_matcher}[[:space:]]+(?<command>#{values})([[:space:]]+(?<expression>.*)|)$", Regexp::IGNORECASE | Regexp::MULTILINE), &block
|
52
35
|
end
|
53
36
|
|
54
37
|
def invoke(client, data)
|
55
38
|
finalize_routes!
|
56
39
|
expression, text = parse(client, data)
|
57
40
|
return false unless expression || data.attachments
|
41
|
+
|
58
42
|
routes.each_pair do |route, options|
|
59
43
|
match_method = options[:match_method]
|
60
44
|
case match_method
|
61
45
|
when :match
|
62
46
|
next unless expression
|
47
|
+
|
63
48
|
match = route.match(expression)
|
64
49
|
match ||= route.match(text) if text
|
65
50
|
next unless match
|
66
51
|
next if match.names.include?('bot') && !client.name?(match['bot'])
|
52
|
+
|
67
53
|
match = Support::Match.new(match)
|
68
54
|
when :scan
|
69
55
|
next unless expression
|
56
|
+
|
70
57
|
match = expression.scan(route)
|
71
58
|
next unless match.any?
|
72
59
|
when :attachment
|
73
60
|
next unless data.attachments && !data.attachments.empty?
|
61
|
+
|
74
62
|
match, attachment, field = match_attachments(data, route, options[:fields_to_scan])
|
75
63
|
next unless match
|
64
|
+
|
76
65
|
match = Support::Match.new(match, attachment, field)
|
77
66
|
end
|
78
67
|
call_command(client, data, match, options[:block])
|
@@ -122,6 +111,7 @@ module SlackRubyBot
|
|
122
111
|
text = data.text
|
123
112
|
return text unless direct_message?(data) && message_from_another_user?(data)
|
124
113
|
return text if message_begins_with_bot_mention?(text, client.names)
|
114
|
+
|
125
115
|
["#{client.name} #{text}", text]
|
126
116
|
end
|
127
117
|
|
@@ -139,7 +129,8 @@ module SlackRubyBot
|
|
139
129
|
end
|
140
130
|
|
141
131
|
def finalize_routes!
|
142
|
-
return if routes
|
132
|
+
return if routes&.any?
|
133
|
+
|
143
134
|
command command_name_from_class
|
144
135
|
end
|
145
136
|
|
@@ -148,6 +139,7 @@ module SlackRubyBot
|
|
148
139
|
data.attachments.each do |attachment|
|
149
140
|
fields_to_scan.each do |field|
|
150
141
|
next unless attachment[field]
|
142
|
+
|
151
143
|
match = route.match(attachment[field])
|
152
144
|
return match, attachment, field if match
|
153
145
|
end
|