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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.gitignore +3 -2
  4. data/.rubocop.yml +14 -1
  5. data/.rubocop_todo.yml +14 -42
  6. data/.travis.yml +11 -13
  7. data/CHANGELOG.md +33 -0
  8. data/CONTRIBUTING.md +5 -1
  9. data/DEPLOYMENT.md +63 -9
  10. data/Dangerfile +4 -0
  11. data/Gemfile +11 -7
  12. data/LICENSE.md +1 -1
  13. data/MIGRATION.md +13 -0
  14. data/README.md +131 -63
  15. data/Rakefile +2 -0
  16. data/TUTORIAL.md +23 -0
  17. data/UPGRADING.md +44 -0
  18. data/examples/inventory/Gemfile +2 -0
  19. data/examples/inventory/inventorybot.rb +5 -1
  20. data/examples/market/Gemfile +4 -3
  21. data/examples/market/marketbot.rb +22 -15
  22. data/examples/minimal/Gemfile +3 -1
  23. data/examples/minimal/pongbot.rb +2 -0
  24. data/examples/weather/Gemfile +2 -0
  25. data/examples/weather/weatherbot.rb +2 -0
  26. data/lib/config/application.rb +4 -2
  27. data/lib/config/boot.rb +2 -0
  28. data/lib/config/environment.rb +3 -1
  29. data/lib/slack-ruby-bot.rb +3 -1
  30. data/lib/slack-ruby-bot/about.rb +3 -1
  31. data/lib/slack-ruby-bot/app.rb +18 -12
  32. data/lib/slack-ruby-bot/bot.rb +3 -1
  33. data/lib/slack-ruby-bot/client.rb +25 -23
  34. data/lib/slack-ruby-bot/commands.rb +2 -0
  35. data/lib/slack-ruby-bot/commands/about.rb +3 -1
  36. data/lib/slack-ruby-bot/commands/base.rb +13 -21
  37. data/lib/slack-ruby-bot/commands/help.rb +10 -8
  38. data/lib/slack-ruby-bot/commands/hi.rb +3 -1
  39. data/lib/slack-ruby-bot/commands/support/attrs.rb +2 -0
  40. data/lib/slack-ruby-bot/commands/support/help.rb +4 -0
  41. data/lib/slack-ruby-bot/commands/support/match.rb +4 -3
  42. data/lib/slack-ruby-bot/commands/unknown.rb +3 -1
  43. data/lib/slack-ruby-bot/config.rb +7 -7
  44. data/lib/slack-ruby-bot/hooks.rb +2 -0
  45. data/lib/slack-ruby-bot/hooks/hello.rb +22 -3
  46. data/lib/slack-ruby-bot/hooks/hook_support.rb +2 -6
  47. data/lib/slack-ruby-bot/hooks/message.rb +11 -10
  48. data/lib/slack-ruby-bot/hooks/set.rb +3 -1
  49. data/lib/slack-ruby-bot/mvc.rb +2 -0
  50. data/lib/slack-ruby-bot/mvc/controller/base.rb +4 -3
  51. data/lib/slack-ruby-bot/mvc/model/base.rb +2 -0
  52. data/lib/slack-ruby-bot/mvc/mvc.rb +2 -0
  53. data/lib/slack-ruby-bot/mvc/view/base.rb +2 -0
  54. data/lib/slack-ruby-bot/rspec.rb +3 -1
  55. data/lib/slack-ruby-bot/rspec/support/bots_for_tests.rb +2 -0
  56. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb +4 -1
  57. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/not_respond.rb +3 -5
  58. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb +3 -7
  59. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +15 -14
  60. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_messages.rb +26 -19
  61. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/start_typing.rb +32 -0
  62. data/lib/slack-ruby-bot/rspec/support/slack_api_key.rb +3 -1
  63. data/lib/slack-ruby-bot/rspec/support/slack_ruby_bot_configure.rb +2 -0
  64. data/lib/slack-ruby-bot/rspec/support/spec_helpers.rb +2 -0
  65. data/lib/slack-ruby-bot/server.rb +5 -4
  66. data/lib/slack-ruby-bot/support/loggable.rb +2 -0
  67. data/lib/slack-ruby-bot/version.rb +3 -1
  68. data/lib/slack_ruby_bot.rb +2 -0
  69. data/screenshots/create-classic-app.png +0 -0
  70. data/slack-ruby-bot.gemspec +6 -2
  71. data/spec/slack-ruby-bot/app_spec.rb +64 -1
  72. data/spec/slack-ruby-bot/client_spec.rb +103 -28
  73. data/spec/slack-ruby-bot/commands/about_spec.rb +2 -0
  74. data/spec/slack-ruby-bot/commands/aliases_spec.rb +2 -0
  75. data/spec/slack-ruby-bot/commands/attachment_spec.rb +2 -0
  76. data/spec/slack-ruby-bot/commands/bot_message_spec.rb +2 -0
  77. data/spec/slack-ruby-bot/commands/bot_messages_spec.rb +26 -0
  78. data/spec/slack-ruby-bot/commands/bot_spec.rb +2 -0
  79. data/spec/slack-ruby-bot/commands/commands_command_classes_spec.rb +2 -0
  80. data/spec/slack-ruby-bot/commands/commands_permitted_spec.rb +2 -0
  81. data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -0
  82. data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +2 -0
  83. data/spec/slack-ruby-bot/commands/commands_regexp_spec.rb +2 -0
  84. data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +2 -0
  85. data/spec/slack-ruby-bot/commands/commands_spec.rb +2 -0
  86. data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -0
  87. data/spec/slack-ruby-bot/commands/commands_with_expression_spec.rb +2 -0
  88. data/spec/slack-ruby-bot/commands/direct_messages_spec.rb +2 -0
  89. data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -0
  90. data/spec/slack-ruby-bot/commands/help_spec.rb +15 -13
  91. data/spec/slack-ruby-bot/commands/hi_spec.rb +2 -0
  92. data/spec/slack-ruby-bot/commands/match_spec.rb +2 -0
  93. data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -0
  94. data/spec/slack-ruby-bot/commands/nil_message_spec.rb +2 -0
  95. data/spec/slack-ruby-bot/commands/non_breaking_space_spec.rb +29 -0
  96. data/spec/slack-ruby-bot/commands/not_implemented_spec.rb +2 -0
  97. data/spec/slack-ruby-bot/commands/operators_spec.rb +2 -0
  98. data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -0
  99. data/spec/slack-ruby-bot/commands/scan_spec.rb +2 -0
  100. data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -0
  101. data/spec/slack-ruby-bot/commands/support/attrs_spec.rb +2 -0
  102. data/spec/slack-ruby-bot/commands/support/help_spec.rb +2 -0
  103. data/spec/slack-ruby-bot/commands/support/match_spec.rb +2 -0
  104. data/spec/slack-ruby-bot/commands/unknown_spec.rb +2 -0
  105. data/spec/slack-ruby-bot/config_spec.rb +2 -57
  106. data/spec/slack-ruby-bot/hooks/hello_spec.rb +51 -0
  107. data/spec/slack-ruby-bot/hooks/hook_support_spec.rb +2 -5
  108. data/spec/slack-ruby-bot/hooks/message_spec.rb +8 -35
  109. data/spec/slack-ruby-bot/hooks/set_spec.rb +2 -0
  110. data/spec/slack-ruby-bot/mvc/controller/controller_to_command_spec.rb +2 -0
  111. data/spec/slack-ruby-bot/rspec/respond_with_error_spec.rb +2 -0
  112. data/spec/slack-ruby-bot/rspec/respond_with_slack_message_spec.rb +20 -0
  113. data/spec/slack-ruby-bot/rspec/respond_with_slack_messages_spec.rb +36 -0
  114. data/spec/slack-ruby-bot/rspec/start_typing_spec.rb +36 -0
  115. data/spec/slack-ruby-bot/server_spec.rb +6 -16
  116. data/spec/slack-ruby-bot/support/loggable_spec.rb +2 -0
  117. data/spec/slack-ruby-bot/version_spec.rb +2 -0
  118. data/spec/spec_helper.rb +3 -6
  119. data/{lib/slack-ruby-bot/rspec → spec}/support/fixtures/slack/migration_in_progress.yml +0 -0
  120. data/{lib/slack-ruby-bot/rspec → spec}/support/vcr.rb +2 -0
  121. metadata +40 -27
  122. data/lib/initializers/giphy.rb +0 -8
  123. data/lib/initializers/giphy_client.rb +0 -39
  124. data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_burrito.yml +0 -69
  125. data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito.yml +0 -71
  126. data/lib/slack-ruby-bot/rspec/support/fixtures/slack/giphy_client_burrito_rated_y.yml +0 -71
  127. data/screenshots/register-bot.png +0 -0
  128. data/spec/slack-ruby-bot/commands/send_gif_spec.rb +0 -25
  129. data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +0 -38
  130. data/spec/slack-ruby-bot/initializers/giphy_client_spec.rb +0 -28
  131. data/spec/slack-ruby-bot/initializers/giphy_spec.rb +0 -18
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler'
3
5
  require 'bundler/gem_tasks'
@@ -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.
@@ -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!`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gem 'celluloid-io'
@@ -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
- STDERR.puts route.inspect
248
+ warn route.inspect
245
249
  end
246
250
  end
247
251
 
@@ -1,5 +1,6 @@
1
- source 'http://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
+ source 'http://rubygems.org'
3
4
  gem 'faye-websocket'
4
- gem 'slack-ruby-bot', path: '../..'
5
- gem 'yahoo-finance'
5
+ gem 'iex-ruby-client'
6
+ gem 'slack-ruby-bot'
@@ -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
- YahooFinance::Client.new.quotes(stocks, %i[name symbol last_trade_price change change_in_percent]).each do |quote|
9
- next if quote.symbol == 'N/A'
10
- client.web_client.chat_postMessage(
11
- channel: data.channel,
12
- as_user: true,
13
- attachments: [
14
- {
15
- fallback: "#{quote.name} (#{quote.symbol}): $#{quote.last_trade_price}",
16
- title: "#{quote.name} (#{quote.symbol})",
17
- text: "$#{quote.last_trade_price} (#{quote.change_in_percent})",
18
- color: quote.change.to_f > 0 ? '#00FF00' : '#FF0000'
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
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
- gem 'celluloid-io'
5
+ gem 'async-websocket', '~> 0.8.0'
4
6
  gem 'slack-ruby-bot', path: '../..'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'slack-ruby-bot'
2
4
 
3
5
  class Bot < SlackRubyBot::Bot
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gem 'celluloid-io'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'slack-ruby-bot'
2
4
 
3
5
  SlackRubyBot::Client.logger.level = Logger::WARN
@@ -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('../../initializers', __FILE__) + '/**/*.rb'].each do |file|
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('../application', __FILE__)
12
+ require File.expand_path('application', __dir__)
11
13
 
12
14
  require 'slack_ruby_bot'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'logger'
3
5
  require 'active_support'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV['RACK_ENV'] ||= 'development'
2
4
 
3
- require File.expand_path('../application', __FILE__)
5
+ require File.expand_path('application', __dir__)
@@ -1,4 +1,6 @@
1
- require File.expand_path('../config/environment', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('config/environment', __dir__)
2
4
 
3
5
  require 'slack-ruby-bot/version'
4
6
  require 'slack-ruby-bot/support/loggable'
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SlackRubyBot
2
- ABOUT = <<-ABOUT.freeze
4
+ ABOUT = <<-ABOUT
3
5
  #{SlackRubyBot::VERSION}
4
6
  https://github.com/slack-ruby/slack-ruby-bot
5
7
  https://twitter.com/dblockdotorg
@@ -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 ||= new
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
@@ -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!", gif: 'understand')
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 :send_gifs
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
- @send_gifs = attrs[:send_gifs]
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 || (self.self && self.self.name)
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
- options = options.dup
47
- # get GIF
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
  require 'slack-ruby-bot/commands/base'
2
4
  require 'slack-ruby-bot/commands/about'
3
5
  require 'slack-ruby-bot/commands/help'
@@ -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, gif: 'selfie')
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}[\\s]+(?<command>#{values})([\\s]+(?<expression>.*)|)$", Regexp::IGNORECASE | Regexp::MULTILINE), &block
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 && routes.any?
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