slack-ruby-bot 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c792bd3959ae8c401a12e7f6c584fdae6c6cf144
4
- data.tar.gz: 2ac80c543a90ea90f3f303cda1ef4c9d2612eafe
3
+ metadata.gz: 9e5f5c4438e5c5fa63f3b7debdcb264d1070f050
4
+ data.tar.gz: a9414930ce2d2284564db60086a85a190ece557c
5
5
  SHA512:
6
- metadata.gz: 9a2464dbe62cffb08e8e3cbddf05180c38678bef1451249bb36fb5be539dff92ccadefa30d92c99ab41d537aceed4c07fd1af6b1ccdae10a32b03932f9768582
7
- data.tar.gz: fe46f4aba9f1e5ff236447c617493010e8aa2e48133208eb2f8e614ed6143f53a23da63e86ddd54a1e4823790c12620e7d8eb60b5e23aa1072500d2098127866
6
+ metadata.gz: 5d2fb96b140f27a2ebb4195d39f87c7ac972faf15a95d6823149c5561292b8fab8543bc19c546100a0f431d25ce51db765feab3719b96ea0cd6ae7b66d1263ee
7
+ data.tar.gz: 6d55c7c74e378924db8689625e145807d6b40f50b3de3dfbef48f37e9daee0b775ff01bdcf44f648db8ba434ca324f503522e328f857d0a613e342e668f34655
@@ -1,5 +1,5 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-07-25 19:18:18 -0400 using RuboCop version 0.32.1.
2
+ # on 2015-09-23 08:45:19 -0400 using RuboCop version 0.32.1.
3
3
  # The point is for the user to remove these configuration records
4
4
  # one by one as the offenses are removed from the code base.
5
5
  # Note that changes in the inspected code, or installation of new
@@ -13,19 +13,23 @@ Lint/HandleExceptions:
13
13
  Lint/UselessAccessModifier:
14
14
  Enabled: false
15
15
 
16
- # Offense count: 2
16
+ # Offense count: 4
17
17
  Metrics/AbcSize:
18
18
  Max: 23
19
19
 
20
- # Offense count: 51
20
+ # Offense count: 1
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 7
23
+
24
+ # Offense count: 85
21
25
  # Configuration parameters: AllowURI, URISchemes.
22
26
  Metrics/LineLength:
23
27
  Max: 142
24
28
 
25
- # Offense count: 2
29
+ # Offense count: 4
26
30
  # Configuration parameters: CountComments.
27
31
  Metrics/MethodLength:
28
- Max: 18
32
+ Max: 21
29
33
 
30
34
  # Offense count: 15
31
35
  Style/Documentation:
@@ -1,9 +1,15 @@
1
+ ### 0.4.4 (Next)
2
+
3
+ * [#17](https://github.com/dblock/slack-ruby-bot/issues/17): Address bot by `name:` - [@dblock](https://githubcom/dblock).
4
+ * [#19](https://github.com/dblock/slack-ruby-bot/issues/19): Retry on `Faraday::Error::TimeoutError`, `TimeoutError` and `SSLError` - [@dblock](https://githubcom/dblock).
5
+ * [#3](https://github.com/dblock/slack-ruby-bot/issues/3): Retry on `migration_in_progress` errors during `rtm.start` - [@dblock](https://githubcom/dblock).
6
+ * Respond to direct messages without being addressed by name - [@dblock](https://githubcom/dblock).
7
+ * Added `send_gif`, to allow GIFs to be sent without text - [@maclover7](https://github.com/maclover7).
8
+
1
9
  ### 0.4.3 (8/21/2015)
2
10
 
3
11
  * [#13](https://github.com/dblock/slack-ruby-bot/issues/13): You can now address the bot by its Slack @id - [@dblock](https://githubcom/dblock).
4
12
 
5
- * Your contribution here.
6
-
7
13
  ### 0.4.2 (8/20/2015)
8
14
 
9
15
  * [#12](https://github.com/dblock/slack-ruby-bot/issues/12): Added support for bot aliases - [@dblock](https://githubcom/dblock).
data/README.md CHANGED
@@ -4,7 +4,7 @@ Slack-Ruby-Bot
4
4
  [![Gem Version](https://badge.fury.io/rb/slack-ruby-bot.svg)](http://badge.fury.io/rb/slack-ruby-bot)
5
5
  [![Build Status](https://travis-ci.org/dblock/slack-ruby-bot.png)](https://travis-ci.org/dblock/slack-ruby-bot)
6
6
 
7
- A generic Slack bot framework written in Ruby on top of [slack-ruby-client](https://github.com/dblock/slack-ruby-client). This library does all the heavy lifting, such as message parsing, so you can focus on implementing slack bot commands. It also attempts to itroduce the bare minimum number of requirements or any sorts of limitations. It's a Slack bot boilerplate.
7
+ A generic Slack bot framework written in Ruby on top of [slack-ruby-client](https://github.com/dblock/slack-ruby-client). This library does all the heavy lifting, such as message parsing, so you can focus on implementing slack bot commands. It also attempts to introduce the bare minimum number of requirements or any sorts of limitations. It's a Slack bot boilerplate.
8
8
 
9
9
  ## Usage
10
10
 
@@ -56,7 +56,7 @@ The following examples of production-grade bots based on slack-ruby-bot are list
56
56
 
57
57
  ### Commands and Operators
58
58
 
59
- Bots are addressed by name and respond to commands and operators. By default a command class responds, case-insensitively, to its name and Slack ID. A class called `Phone` that inherits from `SlackRubyBot::Commands::Base` responds to `phone` and `Phone` and calls the `call` method when implemented.
59
+ Bots are addressed by name, they respond to commands and operators. 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.
60
60
 
61
61
  ```ruby
62
62
  class Phone < SlackRubyBot::Commands::Base
@@ -91,7 +91,7 @@ class Phone < SlackRubyBot::Commands::Base
91
91
  end
92
92
  ```
93
93
 
94
- Command match data includes `match['bot']`, `match['command']` and `match['expression']`. The `bot` match always checks against the `SlackRubyBot::Config.user` setting.
94
+ Command match data includes `match['bot']`, `match['command']` and `match['expression']`. The `bot` match always checks against the `SlackRubyBot::Config.user` and `SlackRubyBot::Config.user_id` values obtained when the bot starts.
95
95
 
96
96
  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`.
97
97
 
@@ -107,7 +107,7 @@ Operator match data includes `match['operator']` and `match['expression']`. The
107
107
 
108
108
  ### Bot Aliases
109
109
 
110
- A bot will always respond to its name and Slack ID, but you can specify multiple aliases via the `SLACK_RUBY_BOT_ALIASES` environment variable or via an explicit configuration.
110
+ A bot will always respond to its name (eg. `rubybot`) and Slack ID (eg. `@rubybot`), but you can specify multiple aliases via the `SLACK_RUBY_BOT_ALIASES` environment variable or via an explicit configuration.
111
111
 
112
112
  ```
113
113
  SLACK_RUBY_BOT_ALIASES=:pp: table-tennis
@@ -123,13 +123,17 @@ This is particularly fun with emoji.
123
123
 
124
124
  ![](screenshots/aliases.gif)
125
125
 
126
+ Bots also will respond to a direct message, with or without the bot name in the message itself.
127
+
128
+ ![](screenshots/dms.gif)
129
+
126
130
  ### Generic Routing
127
131
 
128
132
  Commands and operators are generic versions of bot routes. You can respond to just about anything by defining a custom route.
129
133
 
130
134
  ```ruby
131
135
  class Weather < SlackRubyBot::Commands::Base
132
- match /^How is the weather in (<?location>\w*)\?$/ do |client, data, match|
136
+ match /^How is the weather in (?<location>\w*)\?$/ do |client, data, match|
133
137
  send_message client, data.channel, "The weather in #{match[:location]} is nice."
134
138
  end
135
139
  end
@@ -147,6 +151,10 @@ Send text using a RealTime client to a channel.
147
151
 
148
152
  Send text along with a random animated GIF based on a keyword.
149
153
 
154
+ ## send_gif(client, channel, keyword)
155
+
156
+ Send a random animated GIF based on a keyword.
157
+
150
158
  ### Built-In Commands
151
159
 
152
160
  Slack-ruby-bot comes with several built-in commands. You can re-define built-in commands, normally, as described above.
@@ -163,6 +171,28 @@ Politely says 'hi' back.
163
171
 
164
172
  Get help.
165
173
 
174
+ ### Hooks
175
+
176
+ Hooks are event handlers and respond to Slack RTM API [events](https://api.slack.com/events), such as [hello](lib/slack-ruby-bot/hooks/hello.rb) or [message](lib/slack-ruby-bot/hooks/message.rb). You can implement your own by extending [SlackRubyBot::Hooks::Base](lib/slack-ruby-bot/hooks/base.rb).
177
+
178
+ For example, the following hook handles [user_change](https://api.slack.com/events/user_change), an event sent when a team member updates their profile or data. This can be useful to update the local user cache when a user is renamed.
179
+
180
+ ```ruby
181
+ module MyBot
182
+ module Hooks
183
+ module UserChange
184
+ extend SlackRubyBot::Hooks::Base
185
+
186
+ def user_change(client, data)
187
+ # data['user']['id'] contains the user ID
188
+ # data['user']['name'] contains the new user name
189
+ ...
190
+ end
191
+ end
192
+ end
193
+ end
194
+ ```
195
+
166
196
  ### RSpec Shared Behaviors
167
197
 
168
198
  Slack-ruby-bot ships with a number of shared RSpec behaviors that can be used in your RSpec tests. Require 'slack-ruby-bot/rspec' in your `spec_helper.rb`.
@@ -124,6 +124,14 @@ Create a `.env` file with the API token from above and make sure to add it to `.
124
124
  SLACK_API_TOKEN=...
125
125
  ```
126
126
 
127
+ ### Procfile
128
+
129
+ Create a `Procfile` which `foreman` will use when you run the `foreman start` command below.
130
+
131
+ ```
132
+ web: bundle exec puma -p $PORT
133
+ ```
134
+
127
135
  ### Run the Bot
128
136
 
129
137
  Run `foreman start`. Your bot should be running.
@@ -0,0 +1 @@
1
+ console: bundle exec ruby pongbot.rb
@@ -43,8 +43,25 @@ module SlackRubyBot
43
43
 
44
44
  def start!
45
45
  loop do
46
- client.start!
47
- @client = nil
46
+ begin
47
+ client.start!
48
+ rescue Slack::Web::Api::Error => e
49
+ logger.error e
50
+ case e.message
51
+ when 'migration_in_progress'
52
+ sleep 1 # ignore, try again
53
+ else
54
+ raise e
55
+ end
56
+ rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::SSLError => e
57
+ logger.error e
58
+ sleep 1 # ignore, try again
59
+ rescue StandardError => e
60
+ logger.error e
61
+ raise e
62
+ ensure
63
+ @client = nil
64
+ end
48
65
  end
49
66
  end
50
67
 
@@ -12,14 +12,20 @@ module SlackRubyBot
12
12
  end
13
13
 
14
14
  def self.send_message_with_gif(client, channel, text, keywords, options = {})
15
- gif = begin
16
- Giphy.random(keywords)
17
- rescue StandardError => e
18
- logger.warn "Giphy.random: #{e.message}"
19
- nil
20
- end
21
- text = text + "\n" + gif.image_url.to_s if gif
22
- send_message client, channel, text, options
15
+ get_gif_and_send({
16
+ client: client,
17
+ channel: channel,
18
+ text: text,
19
+ keywords: keywords
20
+ }.merge(options))
21
+ end
22
+
23
+ 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))
23
29
  end
24
30
 
25
31
  def self.logger
@@ -48,7 +54,7 @@ module SlackRubyBot
48
54
 
49
55
  def self.invoke(client, data)
50
56
  self.finalize_routes!
51
- expression = data.text
57
+ expression = parse(data)
52
58
  called = false
53
59
  routes.each_pair do |route, method|
54
60
  match = route.match(expression)
@@ -74,14 +80,40 @@ module SlackRubyBot
74
80
 
75
81
  private
76
82
 
77
- def self.send_client_message(client, data)
78
- client.message(data)
83
+ def self.parse(data)
84
+ text = data.text
85
+ return text unless data.channel && data.channel[0] == 'D' && data.user && data.user != SlackRubyBot.config.user_id
86
+ SlackRubyBot.config.names.each do |name|
87
+ text.downcase.tap do |td|
88
+ return text if td == name || td.starts_with?("#{name} ")
89
+ end
90
+ end
91
+ "#{SlackRubyBot.config.user} #{text}"
79
92
  end
80
93
 
81
94
  def self.finalize_routes!
82
95
  return if self.routes && self.routes.any?
83
96
  command default_command_name
84
97
  end
98
+
99
+ def self.get_gif_and_send(options = {})
100
+ options = options.dup
101
+ gif = begin
102
+ keywords = options.delete(:keywords)
103
+ Giphy.random(keywords)
104
+ rescue StandardError => e
105
+ logger.warn "Giphy.random: #{e.message}"
106
+ nil
107
+ end
108
+ client = options.delete(:client)
109
+ text = options.delete(:text)
110
+ text = [text, gif && gif.image_url.to_s].compact.join("\n")
111
+ send_client_message(client, { text: text }.merge(options))
112
+ end
113
+
114
+ def self.send_client_message(client, data)
115
+ client.message(data)
116
+ end
85
117
  end
86
118
  end
87
119
  end
@@ -11,7 +11,7 @@ module SlackRubyBot
11
11
  attr_accessor :team_id
12
12
 
13
13
  def names
14
- [user, aliases, "<@#{user_id.downcase}>", "<@#{user_id.downcase}>:"].compact.flatten
14
+ [user, aliases, "<@#{user_id.downcase}>", "<@#{user_id.downcase}>:", "#{user}:"].compact.flatten
15
15
  end
16
16
 
17
17
  def name?(name)
@@ -4,52 +4,11 @@ http_interactions:
4
4
  method: post
5
5
  uri: https://slack.com/api/auth.test
6
6
  body:
7
- encoding: UTF-8
8
7
  string: token=token
9
- headers:
10
- Accept:
11
- - application/json; charset=utf-8
12
- User-Agent:
13
- - Slack Ruby Gem 1.1.1
14
- Content-Type:
15
- - application/x-www-form-urlencoded
16
- Accept-Encoding:
17
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
8
  response:
19
9
  status:
20
10
  code: 200
21
11
  message: OK
22
- headers:
23
- Access-Control-Allow-Origin:
24
- - '*'
25
- Cache-Control:
26
- - private, no-cache, no-store, must-revalidate
27
- Content-Type:
28
- - application/json; charset=utf-8
29
- Date:
30
- - Tue, 28 Apr 2015 12:55:23 GMT
31
- Expires:
32
- - Mon, 26 Jul 1997 05:00:00 GMT
33
- Pragma:
34
- - no-cache
35
- Server:
36
- - Apache
37
- Strict-Transport-Security:
38
- - max-age=31536000; includeSubDomains; preload
39
- Vary:
40
- - Accept-Encoding
41
- X-Accepted-Oauth-Scopes:
42
- - identify
43
- X-Content-Type-Options:
44
- - nosniff
45
- X-Oauth-Scopes:
46
- - identify,read,post,client
47
- X-Xss-Protection:
48
- - '0'
49
- Content-Length:
50
- - '128'
51
- Connection:
52
- - keep-alive
53
12
  body:
54
13
  encoding: UTF-8
55
14
  string: '{"ok":true,"url":"https:\/\/rubybot.slack.com\/","team":"team_name","user":"user_name","team_id":"TDEADBEEF","user_id":"UBAADFOOD"}'
@@ -0,0 +1,30 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://slack.com/api/rtm.start
6
+ body:
7
+ string: token=token
8
+ response:
9
+ status:
10
+ code: 200
11
+ message: OK
12
+ body:
13
+ encoding: UTF-8
14
+ string: '{"ok":false,"error":"migration_in_progress"}'
15
+ http_version:
16
+ recorded_at: Tue, 28 Apr 2015 12:55:22 GMT
17
+ - request:
18
+ method: post
19
+ uri: https://slack.com/api/rtm.start
20
+ body:
21
+ string: token=token
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ body:
27
+ encoding: UTF-8
28
+ string: '{"ok":false,"error":"unknown"}'
29
+ http_version:
30
+ recorded_at: Tue, 28 Apr 2015 12:55:22 GMT
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBot
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
Binary file
@@ -5,4 +5,27 @@ describe SlackRubyBot::App do
5
5
  SlackRubyBot::App.new
6
6
  end
7
7
  it_behaves_like 'a slack ruby bot'
8
+ context 'retries on rtm.start errors' do
9
+ let(:client) { Slack::RealTime::Client.new }
10
+ let(:logger) { subject.send :logger }
11
+ before do
12
+ allow(subject).to receive(:sleep)
13
+ expect(Slack::RealTime::Client).to receive(:new).twice.and_return(client)
14
+ expect(logger).to receive(:error).twice
15
+ end
16
+ it 'migration_in_progress', vcr: { cassette_name: 'migration_in_progress' } do
17
+ expect do
18
+ subject.send :start!
19
+ end.to raise_error Slack::Web::Api::Error, 'unknown'
20
+ end
21
+ [Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError, Faraday::Error::SSLError].each do |err|
22
+ it "#{err}" do
23
+ expect(client).to receive(:start!) { fail err, 'Faraday' }
24
+ expect(client).to receive(:start!) { fail 'unknown' }
25
+ expect do
26
+ subject.send :start!
27
+ end.to raise_error 'unknown'
28
+ end
29
+ end
30
+ end
8
31
  end
@@ -10,6 +10,9 @@ describe SlackRubyBot::Commands::Default do
10
10
  it 'upcase' do
11
11
  expect(message: SlackRubyBot.config.user.upcase).to respond_with_slack_message(SlackRubyBot::ABOUT)
12
12
  end
13
+ it 'name:' do
14
+ expect(message: "#{SlackRubyBot.config.user}:").to respond_with_slack_message(SlackRubyBot::ABOUT)
15
+ end
13
16
  it 'id' do
14
17
  expect(message: "<@#{SlackRubyBot.config.user_id}>").to respond_with_slack_message(SlackRubyBot::ABOUT)
15
18
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackRubyBot do
4
+ def app
5
+ SlackRubyBot::App.new
6
+ end
7
+ context 'it responds to direct messages' do
8
+ it 'with bot name' do
9
+ expect(message: "#{SlackRubyBot.config.user} hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
10
+ end
11
+ it 'with bot name capitalized' do
12
+ expect(message: "#{SlackRubyBot.config.user.upcase} hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
13
+ end
14
+ it 'with bot user id' do
15
+ expect(message: "<@#{SlackRubyBot.config.user_id}> hi", channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
16
+ end
17
+ it 'without bot name' do
18
+ expect(message: 'hi', channel: 'DEADBEEF').to respond_with_slack_message('Hi <@user>!')
19
+ end
20
+ end
21
+ context 'it responds to direct name calling' do
22
+ it 'with bot name' do
23
+ expect(message: "#{SlackRubyBot.config.user}", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
24
+ end
25
+ it 'with bot name capitalized' do
26
+ expect(message: "#{SlackRubyBot.config.user.upcase}", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
27
+ end
28
+ it 'with bot user id' do
29
+ expect(message: "<@#{SlackRubyBot.config.user_id}>", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
30
+ end
31
+ it 'with bot user id and a colon' do
32
+ expect(message: "<@#{SlackRubyBot.config.user_id}>:", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
33
+ end
34
+ it 'with bot user id and a colon and a space' do
35
+ expect(message: "<@#{SlackRubyBot.config.user_id}>: ", channel: 'DEADBEEF').to respond_with_slack_message(SlackRubyBot::ABOUT)
36
+ end
37
+ end
38
+ end
@@ -7,6 +7,9 @@ describe SlackRubyBot::Commands::Hi do
7
7
  it 'says hi' do
8
8
  expect(message: "#{SlackRubyBot.config.user} hi").to respond_with_slack_message('Hi <@user>!')
9
9
  end
10
+ it 'says hi to bot:' do
11
+ expect(message: "#{SlackRubyBot.config.user}: hi").to respond_with_slack_message('Hi <@user>!')
12
+ end
10
13
  it 'says hi to @bot' do
11
14
  expect(message: "<@#{SlackRubyBot.config.user_id}> hi").to respond_with_slack_message('Hi <@user>!')
12
15
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackRubyBot::Commands do
4
+ let! :command do
5
+ Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'send_gif_spec' do |client, data, _match|
7
+ send_gif client, data.channel, 'dummy'
8
+ end
9
+ end
10
+ end
11
+ def app
12
+ SlackRubyBot::App.new
13
+ end
14
+ let(:client) { app.send(:client) }
15
+ let(:gif_image_url) { 'http://media2.giphy.com/media/pzOijFsdDrsS4/giphy.gif' }
16
+ it 'sends a gif' do
17
+ gif = Giphy::RandomGif.new('image_url' => gif_image_url)
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)
20
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
21
+ end
22
+ it 'eats up the error' do
23
+ expect(Giphy).to receive(:random) { fail 'oh no!' }
24
+ expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '')
25
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
26
+ end
27
+ it 'eats up nil gif' do
28
+ expect(Giphy).to receive(:random).and_return(nil)
29
+ expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: '')
30
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_gif_spec message", channel: 'channel', user: 'user')
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackRubyBot::Commands do
4
+ let! :command do
5
+ Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'send_message_spec' do |client, data, match|
7
+ send_message client, data.channel, match['expression']
8
+ end
9
+ end
10
+ end
11
+ def app
12
+ SlackRubyBot::App.new
13
+ end
14
+ let(:client) { app.send(:client) }
15
+ it 'sends a message' do
16
+ expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
17
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_spec message", channel: 'channel', user: 'user')
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe SlackRubyBot::Commands do
4
+ let! :command do
5
+ Class.new(SlackRubyBot::Commands::Base) do
6
+ command 'send_message_with_gif_spec' do |client, data, match|
7
+ send_message_with_gif client, data.channel, match['expression'], 'dummy'
8
+ end
9
+ end
10
+ end
11
+ def app
12
+ SlackRubyBot::App.new
13
+ end
14
+ let(:client) { app.send(:client) }
15
+ let(:gif_image_url) { 'http://media2.giphy.com/media/pzOijFsdDrsS4/giphy.gif' }
16
+ it 'sends a message with gif' do
17
+ gif = Giphy::RandomGif.new('image_url' => gif_image_url)
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}")
20
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
21
+ end
22
+ it 'eats up the error' do
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')
25
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
26
+ end
27
+ it 'eats up nil gif' do
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')
30
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
31
+ end
32
+ 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.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -187,6 +187,7 @@ files:
187
187
  - UPGRADING.md
188
188
  - examples/minimal/Gemfile
189
189
  - examples/minimal/Gemfile.lock
190
+ - examples/minimal/Procfile
190
191
  - examples/minimal/pongbot.rb
191
192
  - examples/weather/Gemfile
192
193
  - examples/weather/weatherbot.rb
@@ -210,6 +211,7 @@ files:
210
211
  - lib/slack-ruby-bot/hooks/message.rb
211
212
  - lib/slack-ruby-bot/rspec.rb
212
213
  - lib/slack-ruby-bot/rspec/support/fixtures/slack/auth_test.yml
214
+ - lib/slack-ruby-bot/rspec/support/fixtures/slack/migration_in_progress.yml
213
215
  - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/it_behaves_like_a_slack_bot.rb
214
216
  - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_error.rb
215
217
  - lib/slack-ruby-bot/rspec/support/slack-ruby-bot/respond_with_slack_message.rb
@@ -220,6 +222,7 @@ files:
220
222
  - lib/slack_ruby_bot.rb
221
223
  - screenshots/aliases.gif
222
224
  - screenshots/demo.gif
225
+ - screenshots/dms.gif
223
226
  - screenshots/register-bot.png
224
227
  - screenshots/weather.gif
225
228
  - slack-ruby-bot.gemspec
@@ -230,6 +233,7 @@ files:
230
233
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
231
234
  - spec/slack-ruby-bot/commands/commands_spec.rb
232
235
  - spec/slack-ruby-bot/commands/commands_with_block_spec.rb
236
+ - spec/slack-ruby-bot/commands/direct_messages_spec.rb
233
237
  - spec/slack-ruby-bot/commands/empty_text_spec.rb
234
238
  - spec/slack-ruby-bot/commands/help_spec.rb
235
239
  - spec/slack-ruby-bot/commands/hi_spec.rb
@@ -237,6 +241,9 @@ files:
237
241
  - spec/slack-ruby-bot/commands/not_implemented_spec.rb
238
242
  - spec/slack-ruby-bot/commands/operators_spec.rb
239
243
  - spec/slack-ruby-bot/commands/operators_with_block_spec.rb
244
+ - spec/slack-ruby-bot/commands/send_gif_spec.rb
245
+ - spec/slack-ruby-bot/commands/send_message_spec.rb
246
+ - spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb
240
247
  - spec/slack-ruby-bot/commands/unknown_spec.rb
241
248
  - spec/slack-ruby-bot/rspec/respond_with_error_spec.rb
242
249
  - spec/slack-ruby-bot/version_spec.rb
@@ -261,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
268
  version: 1.3.6
262
269
  requirements: []
263
270
  rubyforge_project:
264
- rubygems_version: 2.2.2
271
+ rubygems_version: 2.4.8
265
272
  signing_key:
266
273
  specification_version: 4
267
274
  summary: The easiest way to write a Slack bot in Ruby.
@@ -273,6 +280,7 @@ test_files:
273
280
  - spec/slack-ruby-bot/commands/commands_spaces_spec.rb
274
281
  - spec/slack-ruby-bot/commands/commands_spec.rb
275
282
  - spec/slack-ruby-bot/commands/commands_with_block_spec.rb
283
+ - spec/slack-ruby-bot/commands/direct_messages_spec.rb
276
284
  - spec/slack-ruby-bot/commands/empty_text_spec.rb
277
285
  - spec/slack-ruby-bot/commands/help_spec.rb
278
286
  - spec/slack-ruby-bot/commands/hi_spec.rb
@@ -280,6 +288,9 @@ test_files:
280
288
  - spec/slack-ruby-bot/commands/not_implemented_spec.rb
281
289
  - spec/slack-ruby-bot/commands/operators_spec.rb
282
290
  - spec/slack-ruby-bot/commands/operators_with_block_spec.rb
291
+ - spec/slack-ruby-bot/commands/send_gif_spec.rb
292
+ - spec/slack-ruby-bot/commands/send_message_spec.rb
293
+ - spec/slack-ruby-bot/commands/send_message_with_gif_spec.rb
283
294
  - spec/slack-ruby-bot/commands/unknown_spec.rb
284
295
  - spec/slack-ruby-bot/rspec/respond_with_error_spec.rb
285
296
  - spec/slack-ruby-bot/version_spec.rb