slack-ruby-bot 0.5.5 → 0.6.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +22 -24
  4. data/TUTORIAL.md +7 -7
  5. data/UPGRADING.md +105 -0
  6. data/examples/minimal/pongbot.rb +1 -1
  7. data/examples/weather/weatherbot.rb +1 -1
  8. data/lib/slack-ruby-bot/bot.rb +7 -1
  9. data/lib/slack-ruby-bot/client.rb +23 -0
  10. data/lib/slack-ruby-bot/commands/about.rb +1 -1
  11. data/lib/slack-ruby-bot/commands/base.rb +7 -32
  12. data/lib/slack-ruby-bot/commands/help.rb +1 -1
  13. data/lib/slack-ruby-bot/commands/hi.rb +1 -1
  14. data/lib/slack-ruby-bot/commands/unknown.rb +1 -1
  15. data/lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb +1 -1
  16. data/lib/slack-ruby-bot/version.rb +1 -1
  17. data/spec/slack-ruby-bot/commands/bot_spec.rb +6 -3
  18. data/spec/slack-ruby-bot/commands/commands_precedence_spec.rb +2 -2
  19. data/spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb +1 -1
  20. data/spec/slack-ruby-bot/commands/commands_spaces_spec.rb +1 -1
  21. data/spec/slack-ruby-bot/commands/commands_spec.rb +1 -1
  22. data/spec/slack-ruby-bot/commands/commands_with_block_spec.rb +2 -2
  23. data/spec/slack-ruby-bot/commands/empty_text_spec.rb +2 -2
  24. data/spec/slack-ruby-bot/commands/match_spec.rb +1 -1
  25. data/spec/slack-ruby-bot/commands/message_loop_spec.rb +2 -2
  26. data/spec/slack-ruby-bot/commands/nil_message_spec.rb +1 -1
  27. data/spec/slack-ruby-bot/commands/operators_spec.rb +1 -1
  28. data/spec/slack-ruby-bot/commands/operators_with_block_spec.rb +2 -2
  29. data/spec/slack-ruby-bot/commands/send_gif_spec.rb +4 -4
  30. data/spec/slack-ruby-bot/commands/send_message_spec.rb +2 -2
  31. data/spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb +7 -7
  32. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d913551cd5d7c5dd77eca6b408afc4f429db43dc
4
- data.tar.gz: 5e96cb15043a4cf9cd39a661182ba0a1320872a6
3
+ metadata.gz: 6b27b94f1f7396de181c038e27e4896b1754dc4b
4
+ data.tar.gz: aae8cf08bbc1839ee45efa03fb752080290c3216
5
5
  SHA512:
6
- metadata.gz: e01fadbae26b2a4bb53794dbe587b635b72ec30dc1b1d18cab3a71adbf061446084890ad9851c9814336ed09c6f48589fa76a82498010ce5f00ebb21dacb3034
7
- data.tar.gz: 19df60970882c526023310c6b33aae3f7c8236f71aa59aae0ec741290bc0fb6ffb27a2ddef1bd757483a49ad73109661cc3ddf620531b806a67157d9829b8bf7
6
+ metadata.gz: 96b648ba4ab3cc77c37bc351f5cdb77efd92b427763e0f90627d8e2d1389035cf3ff7fb06ef0a59f7be70fe7e06cd95af3cfd67adb007a2f9bef769b0387e9e3
7
+ data.tar.gz: 3a8d709cda131675445dc986ecb67d7e62f63a17bae29820a89622f4dff2701d3d7f2b701ee416e2cde9b67577b38e51f628bb14d4ad48514d0b46516f390a7b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.6.0 (1/9/2016)
2
+
3
+ * Deprecated `SlackRubyBot::Base#send_message`, `send_message_with_gif` and `send_gif` in favor of `client.say` - [@dblock](https://github.com/dblock).
4
+
1
5
  ### 0.5.5 (1/4/2016)
2
6
 
3
7
  * Added `SlackRubyBot::Bot` DSL sugar - [@dblock](https://github.com/dblock).
data/README.md CHANGED
@@ -17,7 +17,7 @@ A generic Slack bot framework written in Ruby on top of [slack-ruby-client](http
17
17
 
18
18
  ## Stable Release
19
19
 
20
- You're reading the documentation for the **stable** release of slack-ruby-bot, 0.5.5.
20
+ You're reading the documentation for the **stable** release of slack-ruby-bot, 0.6.0. See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING.md) for how to upgrade to more recent versions.
21
21
 
22
22
  ## Usage
23
23
 
@@ -38,7 +38,7 @@ require 'slack-ruby-bot'
38
38
 
39
39
  class PongBot < SlackRubyBot::Bot
40
40
  command 'ping' do |client, data, match|
41
- client.message text: 'pong', channel: data.channel
41
+ client.say(text: 'pong', channel: data.channel)
42
42
  end
43
43
  end
44
44
 
@@ -65,13 +65,13 @@ The following examples of bots based on slack-ruby-bot are listed in growing ord
65
65
 
66
66
  ### Commands and Operators
67
67
 
68
- Bots are addressed by name, they respond to commands and operators.
69
-
70
- You can combine multiple commands and use a block to implement them.
68
+ Bots are addressed by name, they respond to commands and operators. You can combine multiple commands.
71
69
 
72
70
  ```ruby
73
- command 'call', '呼び出し' do |client, data, match|
74
- send_message client, data.channel, 'called'
71
+ class CallBot < SlackRubyBot::Bot
72
+ command 'call', '呼び出し' do |client, data, match|
73
+ client.say(channel: data.channel, text: 'called')
74
+ end
75
75
  end
76
76
  ```
77
77
 
@@ -80,8 +80,10 @@ Command match data includes `match['bot']`, `match['command']` and `match['expre
80
80
  Operators are 1-letter long and are similar to commands. They don't require addressing a bot nor separating an operator from its arguments. The following class responds to `=2+2`.
81
81
 
82
82
  ```ruby
83
- operator '=' do |data, match|
84
- # implementation detail
83
+ class MathBot < SlackRubyBot::Bot
84
+ operator '=' do |client, data, match|
85
+ # implementation detail
86
+ end
85
87
  end
86
88
  ```
87
89
 
@@ -116,7 +118,7 @@ Commands and operators are generic versions of bot routes. You can respond to ju
116
118
  ```ruby
117
119
  class Weather < SlackRubyBot::Bot
118
120
  match /^How is the weather in (?<location>\w*)\?$/ do |client, data, match|
119
- send_message client, data.channel, "The weather in #{match[:location]} is nice."
121
+ client.say(channel: data.channel, text: "The weather in #{match[:location]} is nice.")
120
122
  end
121
123
  end
122
124
  ```
@@ -125,14 +127,14 @@ end
125
127
 
126
128
  ### SlackRubyBot::Commands::Base
127
129
 
128
- The `SlackRubyBot::Bot` class is just sugare deriving from `SlackRubyBot::Commands::Base`. You can divide the bot implementation into subclasses of `SlackRubyBot::Commands::Base` manually. By default a command class responds, case-insensitively, to its name. A class called `Phone` that inherits from `SlackRubyBot::Commands::Base` responds to `phone` and `Phone` and calls the `call` method when implemented.
130
+ The `SlackRubyBot::Bot` class is DSL sugar deriving from `SlackRubyBot::Commands::Base`. For more involved bots you can organize the bot implementation into subclasses of `SlackRubyBot::Commands::Base` manually. By default a command class responds, case-insensitively, to its name. A class called `Phone` that inherits from `SlackRubyBot::Commands::Base` responds to `phone` and `Phone` and calls the `call` method when implemented.
129
131
 
130
132
  ```ruby
131
133
  class Phone < SlackRubyBot::Commands::Base
132
134
  command 'call'
133
135
 
134
136
  def self.call(client, data, match)
135
- send_message client, data.channel, 'called'
137
+ client.say(channel: data.channel, text: 'called')
136
138
  end
137
139
  end
138
140
  ```
@@ -145,24 +147,16 @@ class Phone < SlackRubyBot::Commands::Base
145
147
  command '呼び出し'
146
148
 
147
149
  def self.call(client, data, match)
148
- send_message client, data.channel, 'called'
150
+ client.say(channel: data.channel, text: 'called')
149
151
  end
150
152
  end
151
153
  ```
152
154
 
153
- Other available functions include the following.
154
-
155
- #### send_message(client, channel, text)
156
-
157
- Send text using a RealTime client to a channel.
155
+ The `SlackRubyBot::Client` implementation comes with GIF support.
158
156
 
159
- #### send_message_with_gif(client, channel, text, keyword)
157
+ #### say(channel: ..., text: ..., gif: ...)
160
158
 
161
- Send text along with a random animated GIF based on a keyword.
162
-
163
- ## send_gif(client, channel, keyword)
164
-
165
- Send a random animated GIF based on a keyword.
159
+ Sends text and/or a random GIF that matches a keyword using a RealTime client to a channel.
166
160
 
167
161
  ### Built-In Commands
168
162
 
@@ -248,6 +242,10 @@ Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in
248
242
  * [respond with slack message](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb): The bot responds with a message.
249
243
  * [respond with error](lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb): An exception is raised inside a bot command.
250
244
 
245
+ ### Useful Libraries
246
+
247
+ * [newrelic-slack-ruby-bot](https://github.com/dblock/newrelic-slack-ruby-bot): NewRelic instrumentation for slack-ruby-bot.
248
+
251
249
  ## Contributing
252
250
 
253
251
  See [CONTRIBUTING](CONTRIBUTING.md).
data/TUTORIAL.md CHANGED
@@ -34,11 +34,11 @@ Run `bundle install` to get all the gems.
34
34
 
35
35
  #### Application
36
36
 
37
- Create a folder called `slack-mathbot` and inside of it create `app.rb`.
37
+ Create a folder called `slack-mathbot` and inside of it create `bot.rb`.
38
38
 
39
39
  ```ruby
40
40
  module SlackMathbot
41
- class App < SlackRubyBot::App
41
+ class Bot < SlackRubyBot::Bot
42
42
  end
43
43
  end
44
44
  ```
@@ -52,7 +52,7 @@ module SlackMathbot
52
52
  module Commands
53
53
  class Calculate < SlackRubyBot::Commands::Base
54
54
  command 'calculate' do |client, data, _match|
55
- send_message client, data.channel, '4'
55
+ client.say(chanbel: data.channel, text: '4')
56
56
  end
57
57
  end
58
58
  end
@@ -66,7 +66,7 @@ Create a `slack-mathbot.rb` at the root and require the above files.
66
66
  ```ruby
67
67
  require 'slack-ruby-bot'
68
68
  require 'slack-mathbot/commands/calculate'
69
- require 'slack-mathbot/app'
69
+ require 'slack-mathbot/bot'
70
70
  ```
71
71
 
72
72
  #### Web Server
@@ -99,7 +99,7 @@ Thread.abort_on_exception = true
99
99
 
100
100
  Thread.new do
101
101
  begin
102
- SlackMathbot::App.instance.run
102
+ SlackMathbot::Bot.run
103
103
  rescue Exception => e
104
104
  STDERR.puts "ERROR: #{e}"
105
105
  STDERR.puts e.backtrace
@@ -175,7 +175,7 @@ require 'spec_helper'
175
175
 
176
176
  describe SlackMathbot::App do
177
177
  def app
178
- SlackMathbot::App.new
178
+ SlackMathbot::Bot.instance
179
179
  end
180
180
  it_behaves_like 'a slack ruby bot'
181
181
  end
@@ -190,7 +190,7 @@ require 'spec_helper'
190
190
 
191
191
  describe SlackMathbot::Commands::Calculate do
192
192
  def app
193
- SlackMathbot::App.new
193
+ SlackMathbot::Bot.instance
194
194
  end
195
195
  it 'returns 4' do
196
196
  expect(message: "#{SlackRubyBot.config.user} calculate 2+2", channel: 'channel').to respond_with_slack_message('4')
data/UPGRADING.md CHANGED
@@ -1,6 +1,111 @@
1
1
  Upgrading SlackRubyBot
2
2
  ======================
3
3
 
4
+ ### Upgrading to >= 0.6.0
5
+
6
+ While entirely compatible with the 0.5.x series, a number of methods have been deprecated and will be removed in the next release.
7
+
8
+ #### Replace SlackRubyBot::Commands::Base#call with command, operator or match
9
+
10
+ Prefer `command`, `operator` or `match` with a block instead of implementing a `self.call` method.
11
+
12
+ Before:
13
+
14
+ ```ruby
15
+ require 'slack-ruby-bot'
16
+
17
+ class Bot < SlackRubyBot::Bot
18
+ command 'ping'
19
+
20
+ def self.call(client, data, match)
21
+ ...
22
+ end
23
+ end
24
+ ```
25
+
26
+ After:
27
+
28
+ ```ruby
29
+ require 'slack-ruby-bot'
30
+
31
+ class Bot < SlackRubyBot::Bot
32
+ command 'ping' do |client, data, match|
33
+ ...
34
+ end
35
+ end
36
+ ```
37
+
38
+ #### Replace send_message, send_message_with_gif and send_gif with client.say
39
+
40
+ Use `client.say` instead of `send_message`, `send_message_with_gif` and `send_gif` in commands.
41
+
42
+ Before:
43
+
44
+ ```ruby
45
+ class Bot < SlackRubyBot::Bot
46
+ command 'one' do |client, data, match|
47
+ send_message client, data.channel, 'Text.'
48
+ end
49
+
50
+ command 'two' do |client, data, match|
51
+ send_message_with_gif client, data.channel, "Text.", 'keyword'
52
+ end
53
+
54
+ command 'three' do |client, data, match|
55
+ send_gif client, data.channel, 'keyword'
56
+ end
57
+ end
58
+ ```
59
+
60
+ After:
61
+
62
+ ```ruby
63
+ class Bot < SlackRubyBot::Bot
64
+ command 'one' do |client, data, match|
65
+ client.say(channel: data.channel, text: 'Text.')
66
+ end
67
+
68
+ command 'two' do |client, data, match|
69
+ client.say(channel: data.channel, text: 'Text.', gif: 'keyword')
70
+ end
71
+
72
+ command 'three' do |client, data, match|
73
+ client.say(channel: data.channel, gif: 'keyword')
74
+ end
75
+ end
76
+ ```
77
+
78
+ #### For basic bots replace SlackRubyBot::App with SlackRubyBot::Bot and implement commands inline
79
+
80
+ Before:
81
+
82
+ ```ruby
83
+ module PongBot
84
+ class App < SlackRubyBot::App
85
+ end
86
+
87
+ class Ping < SlackRubyBot::Commands::Base
88
+ command 'ping' do |client, data, _match|
89
+ client.message(text: 'pong', channel: data.channel)
90
+ end
91
+ end
92
+ end
93
+
94
+ PongBot::App.instance.run
95
+ ```
96
+
97
+ After:
98
+
99
+ ```ruby
100
+ class Bot < SlackRubyBot::Bot
101
+ command 'ping' do |client, data, _match|
102
+ client.say(text: 'pong', channel: data.channel)
103
+ end
104
+ end
105
+
106
+ Bot.run
107
+ ```
108
+
4
109
  ### Upgrading to >= 0.4.0
5
110
 
6
111
  This version uses [slack-ruby-client](https://github.com/dblock/slack-ruby-client) instead of [slack-ruby-gem](https://github.com/aki017/slack-ruby-gem).
@@ -2,7 +2,7 @@ require 'slack-ruby-bot'
2
2
 
3
3
  class Bot < SlackRubyBot::Bot
4
4
  command 'ping' do |client, data, _match|
5
- client.message text: 'pong', channel: data.channel
5
+ client.say(text: 'pong', channel: data.channel)
6
6
  end
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ require 'slack-ruby-bot'
2
2
 
3
3
  class WeatherBot < SlackRubyBot::Bot
4
4
  match(/^How is the weather in (?<location>\w*)\?$/i) do |client, data, match|
5
- send_message client, data.channel, "The weather in #{match[:location]} is nice."
5
+ client.say(channel: data.channel, text: "The weather in #{match[:location]} is nice.")
6
6
  end
7
7
  end
8
8
 
@@ -1,7 +1,13 @@
1
1
  module SlackRubyBot
2
2
  class Bot < SlackRubyBot::Commands::Base
3
+ delegate :client, to: :instance
4
+
3
5
  def self.run
4
- SlackRubyBot::App.instance.run
6
+ instance.run
7
+ end
8
+
9
+ def self.instance
10
+ SlackRubyBot::App.instance
5
11
  end
6
12
  end
7
13
  end
@@ -40,5 +40,28 @@ module SlackRubyBot
40
40
  def url
41
41
  SlackRubyBot.config.url || (auth && auth['url'])
42
42
  end
43
+
44
+ def logger
45
+ @logger ||= begin
46
+ $stdout.sync = true
47
+ Logger.new(STDOUT)
48
+ end
49
+ end
50
+
51
+ def say(options = {})
52
+ options = options.dup
53
+ # get GIF
54
+ keywords = options.delete(:gif)
55
+ # text
56
+ text = options.delete(:text)
57
+ gif = begin
58
+ Giphy.random(keywords)
59
+ rescue StandardError => e
60
+ logger.warn "Giphy.random: #{e.message}"
61
+ nil
62
+ end if SlackRubyBot::Config.send_gifs? && send_gifs? && keywords
63
+ text = [text, gif && gif.image_url.to_s].compact.join("\n")
64
+ message({ text: text }.merge(options))
65
+ end
43
66
  end
44
67
  end
@@ -5,7 +5,7 @@ module SlackRubyBot
5
5
  match(/^(?<bot>[[:alnum:][:punct:]@<>]*)$/u)
6
6
 
7
7
  def self.call(client, data, _match)
8
- send_message_with_gif client, data.channel, SlackRubyBot::ABOUT, 'selfie'
8
+ client.say(channel: data.channel, text: SlackRubyBot::ABOUT, gif: 'selfie')
9
9
  end
10
10
  end
11
11
  end
@@ -4,28 +4,22 @@ module SlackRubyBot
4
4
  class_attribute :routes
5
5
 
6
6
  def self.send_message(client, channel, text, options = {})
7
+ logger.warn '[DEPRECATION] `send_message` is deprecated. Please use `client.say` instead.'
7
8
  if text && text.length > 0
8
- send_client_message(client, { channel: channel, text: text }.merge(options))
9
+ client.say(options.merge(channel: channel, text: text))
9
10
  else
10
- send_message_with_gif client, channel, 'Nothing to see here.', 'nothing', options
11
+ client.say(options.merge(channel: channel, text: 'Nothing to see here.', gif: 'nothing'))
11
12
  end
12
13
  end
13
14
 
14
15
  def self.send_message_with_gif(client, channel, text, keywords, options = {})
15
- get_gif_and_send({
16
- client: client,
17
- channel: channel,
18
- text: text,
19
- keywords: keywords
20
- }.merge(options))
16
+ logger.warn '[DEPRECATION] `send_message_with_gif` is deprecated. Please use `client.say` instead.'
17
+ client.say(options.merge(channel: channel, text: text, gif: keywords))
21
18
  end
22
19
 
23
20
  def self.send_gif(client, channel, keywords, options = {})
24
- get_gif_and_send({
25
- client: client,
26
- channel: channel,
27
- keywords: keywords
28
- }.merge(options))
21
+ logger.warn '[DEPRECATION] `send_gif` is deprecated. Please use `client.say` instead.'
22
+ client.say(options.merge(channel: channel, text: '', gif: keywords))
29
23
  end
30
24
 
31
25
  def self.logger
@@ -97,25 +91,6 @@ module SlackRubyBot
97
91
  return if self.routes && self.routes.any?
98
92
  command default_command_name
99
93
  end
100
-
101
- def self.get_gif_and_send(options = {})
102
- options = options.dup
103
- keywords = options.delete(:keywords)
104
- client = options.delete(:client)
105
- gif = begin
106
- Giphy.random(keywords)
107
- rescue StandardError => e
108
- logger.warn "Giphy.random: #{e.message}"
109
- nil
110
- end if SlackRubyBot::Config.send_gifs? && client.send_gifs?
111
- text = options.delete(:text)
112
- text = [text, gif && gif.image_url.to_s].compact.join("\n")
113
- send_client_message(client, { text: text }.merge(options))
114
- end
115
-
116
- def self.send_client_message(client, data)
117
- client.message(data)
118
- end
119
94
  end
120
95
  end
121
96
  end
@@ -2,7 +2,7 @@ module SlackRubyBot
2
2
  module Commands
3
3
  class Help < Base
4
4
  def self.call(client, data, _match)
5
- send_message_with_gif client, data.channel, 'See https://github.com/dblock/slack-ruby-bot, please.', 'help'
5
+ client.say(channel: data.channel, text: 'See https://github.com/dblock/slack-ruby-bot, please.', gif: 'help')
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module SlackRubyBot
2
2
  module Commands
3
3
  class Hi < Base
4
4
  def self.call(client, data, _match)
5
- send_message_with_gif client, data.channel, "Hi <@#{data.user}>!", 'hi'
5
+ client.say(channel: data.channel, text: "Hi <@#{data.user}>!", gif: 'hi')
6
6
  end
7
7
  end
8
8
  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
- send_message_with_gif client, data.channel, "Sorry <@#{data.user}>, I don't understand that command!", 'idiot'
7
+ client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'idiot')
8
8
  end
9
9
  end
10
10
  end
@@ -5,7 +5,7 @@ RSpec::Matchers.define :respond_with_slack_message do |expected|
5
5
  channel, user, message = parse(actual)
6
6
  allow(Giphy).to receive(:random)
7
7
  client = app.send(:client)
8
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: channel, text: expected)
8
+ expect(client).to receive(:message).with(channel: channel, text: expected)
9
9
  app.send(:message, client, text: message, channel: channel, user: user)
10
10
  true
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBot
2
- VERSION = '0.5.5'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -4,16 +4,19 @@ describe SlackRubyBot::Bot do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Bot) do
6
6
  command 'bot_spec' do |client, data, match|
7
- send_message client, data.channel, match['expression']
7
+ client.say(channel: data.channel, text: match['expression'])
8
8
  end
9
9
  end
10
10
  end
11
11
  def app
12
- SlackRubyBot::App.new
12
+ SlackRubyBot::Bot.instance
13
13
  end
14
14
  let(:client) { app.send(:client) }
15
15
  it 'sends a message' do
16
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
16
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
17
17
  app.send(:message, client, text: "#{SlackRubyBot.config.user} bot_spec message", channel: 'channel', user: 'user')
18
18
  end
19
+ it 'sends a message' do
20
+ expect(message: "#{SlackRubyBot.config.user} bot_spec message").to respond_with_slack_message('message')
21
+ end
19
22
  end
@@ -4,11 +4,11 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command 'tomato' do |client, data, match|
7
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
7
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
8
8
  end
9
9
 
10
10
  command 'tomatoes' do |client, data, match|
11
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
11
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
12
12
  end
13
13
  end
14
14
  end
@@ -4,7 +4,7 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command '(' do |client, data, match|
7
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
7
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command 'space' do |client, data, match|
7
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
7
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
8
8
  end
9
9
  end
10
10
  end
@@ -7,7 +7,7 @@ describe SlackRubyBot::Commands do
7
7
  command 'saybye'
8
8
 
9
9
  def self.call(client, data, match)
10
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
10
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
11
11
  end
12
12
  end
13
13
  end
@@ -4,11 +4,11 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command 'sayhi' do |client, data, match|
7
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
7
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
8
8
  end
9
9
 
10
10
  command 'one', 'two' do |client, data, match|
11
- send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
11
+ client.say(channel: data.channel, text: "#{match[:command]}: #{match[:expression]}")
12
12
  end
13
13
  end
14
14
  end
@@ -6,7 +6,7 @@ describe SlackRubyBot::Commands do
6
6
  command 'empty_text'
7
7
 
8
8
  def self.call(client, data, _match)
9
- send_message client, data.channel, nil
9
+ client.say(channel: data.channel)
10
10
  end
11
11
  end
12
12
  end
@@ -16,7 +16,7 @@ describe SlackRubyBot::Commands do
16
16
  let(:client) { app.send(:client) }
17
17
  it 'sends default text' do
18
18
  allow(Giphy).to receive(:random)
19
- expect(SlackRubyBot::Commands::Base).to receive(:send_message_with_gif).with(client, 'channel', 'Nothing to see here.', 'nothing', {})
19
+ expect(client).to receive(:message).with(channel: 'channel', text: '')
20
20
  app.send(:message, client, text: "#{SlackRubyBot.config.user} empty_text", channel: 'channel', user: 'user')
21
21
  end
22
22
  end
@@ -4,7 +4,7 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  match(/^Reticulate (?<spline_name>\w*)$/) do |client, data, match|
7
- send_message client, data.channel, "Reticulated #{match[:spline_name]}."
7
+ client.say(channel: data.channel, text: "Reticulated #{match[:spline_name]}.")
8
8
  end
9
9
  end
10
10
  end
@@ -11,7 +11,7 @@ describe SlackRubyBot::App do
11
11
  end
12
12
  context 'default' do
13
13
  it 'does not respond to self' do
14
- expect(SlackRubyBot::Commands::Base).to_not receive(:send_client_message)
14
+ expect(client).to_not receive(:message)
15
15
  subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
16
16
  end
17
17
  end
@@ -27,7 +27,7 @@ describe SlackRubyBot::App do
27
27
  end
28
28
  end
29
29
  it 'responds to self' do
30
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message)
30
+ expect(client).to receive(:message)
31
31
  subject.send(:message, client, text: "#{SlackRubyBot.config.user} hi", channel: 'channel', user: 'UDEADBEEF')
32
32
  end
33
33
  end
@@ -16,7 +16,7 @@ describe SlackRubyBot::Commands do
16
16
  let(:client) { app.send(:client) }
17
17
  it 'ignores nil messages' do
18
18
  allow(Giphy).to receive(:random)
19
- expect(SlackRubyBot::Commands::Base).to_not receive(:send_message_with_gif)
19
+ expect(client).to_not receive(:message)
20
20
  app.send(:message, client, text: nil, channel: 'channel', user: 'user')
21
21
  end
22
22
  end
@@ -7,7 +7,7 @@ describe SlackRubyBot::Commands do
7
7
  operator '-'
8
8
 
9
9
  def self.call(client, data, match)
10
- send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
10
+ client.say(channel: data.channel, text: "#{match[:operator]}: #{match[:expression]}")
11
11
  end
12
12
  end
13
13
  end
@@ -4,11 +4,11 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  operator '=' do |client, data, match|
7
- send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
7
+ client.say(channel: data.channel, text: "#{match[:operator]}: #{match[:expression]}")
8
8
  end
9
9
 
10
10
  operator '+', '-' do |client, data, match|
11
- send_message client, data.channel, "#{match[:operator]}: #{match[:expression]}"
11
+ client.say(channel: data.channel, text: "#{match[:operator]}: #{match[:expression]}")
12
12
  end
13
13
  end
14
14
  end
@@ -4,7 +4,7 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command 'send_gif_spec' do |client, data, _match|
7
- send_gif client, data.channel, 'dummy'
7
+ client.say(channel: data.channel, gif: 'dummy')
8
8
  end
9
9
  end
10
10
  end
@@ -16,17 +16,17 @@ describe SlackRubyBot::Commands do
16
16
  it 'sends a gif' do
17
17
  gif = Giphy::RandomGif.new('image_url' => gif_image_url)
18
18
  expect(Giphy).to receive(:random).and_return(gif)
19
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: gif_image_url)
19
+ expect(client).to receive(:message).with(channel: 'channel', text: gif_image_url)
20
20
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
21
21
  end
22
22
  it 'eats up the error' do
23
23
  expect(Giphy).to receive(:random) { fail 'oh no!' }
24
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '')
24
+ expect(client).to receive(:message).with(channel: 'channel', text: '')
25
25
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
26
26
  end
27
27
  it 'eats up nil gif' do
28
28
  expect(Giphy).to receive(:random).and_return(nil)
29
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '')
29
+ expect(client).to receive(:message).with(channel: 'channel', text: '')
30
30
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
31
31
  end
32
32
  end
@@ -4,7 +4,7 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command 'send_message_spec' do |client, data, match|
7
- send_message client, data.channel, match['expression']
7
+ client.say(channel: data.channel, text: match['expression'])
8
8
  end
9
9
  end
10
10
  end
@@ -13,7 +13,7 @@ describe SlackRubyBot::Commands do
13
13
  end
14
14
  let(:client) { app.send(:client) }
15
15
  it 'sends a message' do
16
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
16
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
17
17
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_spec message", channel: 'channel', user: 'user')
18
18
  end
19
19
  end
@@ -4,7 +4,7 @@ describe SlackRubyBot::Commands do
4
4
  let! :command do
5
5
  Class.new(SlackRubyBot::Commands::Base) do
6
6
  command 'send_message_with_gif_spec' do |client, data, match|
7
- send_message_with_gif client, data.channel, match['expression'], 'dummy'
7
+ client.say(channel: data.channel, text: match['expression'], gif: 'dummy')
8
8
  end
9
9
  end
10
10
  end
@@ -16,17 +16,17 @@ describe SlackRubyBot::Commands do
16
16
  it 'sends a message with gif' do
17
17
  gif = Giphy::RandomGif.new('image_url' => gif_image_url)
18
18
  expect(Giphy).to receive(:random).and_return(gif)
19
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: "message\n#{gif_image_url}")
19
+ expect(client).to receive(:message).with(channel: 'channel', text: "message\n#{gif_image_url}")
20
20
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
21
21
  end
22
22
  it 'eats up the error' do
23
23
  expect(Giphy).to receive(:random) { fail 'oh no!' }
24
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
24
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
25
25
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
26
26
  end
27
27
  it 'eats up nil gif' do
28
28
  expect(Giphy).to receive(:random).and_return(nil)
29
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
29
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
30
30
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
31
31
  end
32
32
  context 'send_gifs' do
@@ -36,7 +36,7 @@ describe SlackRubyBot::Commands do
36
36
  end
37
37
  it 'does not send a gif' do
38
38
  expect(Giphy).to_not receive(:random)
39
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
39
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
40
40
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
41
41
  end
42
42
  after do
@@ -49,7 +49,7 @@ describe SlackRubyBot::Commands do
49
49
  end
50
50
  it 'does not send a gif' do
51
51
  expect(Giphy).to_not receive(:random)
52
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
52
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
53
53
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
54
54
  end
55
55
  after do
@@ -62,7 +62,7 @@ describe SlackRubyBot::Commands do
62
62
  end
63
63
  it 'does not send a gif' do
64
64
  expect(Giphy).to_not receive(:random)
65
- expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
65
+ expect(client).to receive(:message).with(channel: 'channel', text: 'message')
66
66
  app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
67
67
  end
68
68
  after 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.5.5
4
+ version: 0.6.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: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie