slack-ruby-bot 0.5.3 → 0.5.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: ff5cb3cefc95c4a84d5cbe3e99f5975496d9cdf5
4
- data.tar.gz: a74bb7b70b4c750b12a038658ee88c8f3890b7dc
3
+ metadata.gz: eba2b910b92cbe628a3fb697a08dd62d0af70e5b
4
+ data.tar.gz: 470fb9481c91e1203ca4ef6ed320f86d3edfbb9d
5
5
  SHA512:
6
- metadata.gz: 801999251e958c05df6f87fe890d03a16e4412e2dfd68e1fc1bde87ab03426ba86057ab20aeb8859b7717aeb484940cb477296ee04de04d2a05c76cad280a442
7
- data.tar.gz: 58cee5862ee3f9879e1f5a04af69a9558eba67c81a444a9e8348372a08c4ff340f945614fd1e5a5a816dcfdc8ad83a3b017a66f9fc3d85ed53608c9ab4df3db3
6
+ metadata.gz: 5147a284b8b37f26417bddb8dc96c8a656e3426b108592b06d0815afb42725ba894dee61a72cc8d56526f0c184b76df160ed64f40fb20a8c0004f8377b9ef288
7
+ data.tar.gz: 96dc0cce71969ab11ef68f30f970876859d21c8a7aedf09222139bb80d6159c215a6218a1999fea8d4708423078af54137a2826e88051c2394e1574e9e2f58fe
@@ -1,5 +1,5 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-12-26 16:43:10 -0500 using RuboCop version 0.32.1.
2
+ # on 2016-01-03 14:51:05 -0700 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
@@ -26,7 +26,7 @@ Metrics/ClassLength:
26
26
  Metrics/CyclomaticComplexity:
27
27
  Max: 8
28
28
 
29
- # Offense count: 102
29
+ # Offense count: 104
30
30
  # Configuration parameters: AllowURI, URISchemes.
31
31
  Metrics/LineLength:
32
32
  Max: 145
@@ -44,6 +44,10 @@ Metrics/PerceivedComplexity:
44
44
  Style/Documentation:
45
45
  Enabled: false
46
46
 
47
+ # Offense count: 2
48
+ Style/DoubleNegation:
49
+ Enabled: false
50
+
47
51
  # Offense count: 1
48
52
  # Configuration parameters: Exclude.
49
53
  Style/FileName:
@@ -1,3 +1,7 @@
1
+ ### 0.5.4 (1/3/2016)
2
+
3
+ * Enable setting `send_gifs` per instance of `SlackRubyBot::Server` - [@dblock](https://github.com/dblock).
4
+
1
5
  ### 0.5.3 (12/28/2015)
2
6
 
3
7
  * [#36](https://github.com/dblock/slack-ruby-bot/issues/36): Fix: non-English bot aliases now work - [@dblock](https://github.com/dblock).
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors
3
+ Copyright (c) 2015-2016 Daniel Doubrovkine, Artsy and Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
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.3.
20
+ You're reading the documentation for the **stable** release of slack-ruby-bot, 0.5.4.
21
21
 
22
22
  ## Usage
23
23
 
@@ -229,7 +229,7 @@ end
229
229
 
230
230
  ### Advanced Integration
231
231
 
232
- You may want to integrate a bot or multiple bots into other systems, in which case a globally configured bot may not work for you. You may create instances of [SlackRubyBot::Server](lib/slack-ruby-bot/server.rb) which accepts `token` and `aliases`.
232
+ You may want to integrate a bot or multiple bots into other systems, in which case a globally configured bot may not work for you. You may create instances of [SlackRubyBot::Server](lib/slack-ruby-bot/server.rb) which accepts `token`, `aliases` and `send_gifs`.
233
233
 
234
234
  ```ruby
235
235
  EM.run do
@@ -237,7 +237,7 @@ EM.run do
237
237
  bot1.auth!
238
238
  bot1.start_async
239
239
 
240
- bot2 = SlackRubyBot::Server.new(token: token2, aliases: ['bot2'])
240
+ bot2 = SlackRubyBot::Server.new(token: token2, send_gifs: false, aliases: ['bot2'])
241
241
  bot2.auth!
242
242
  bot2.start_async
243
243
  end
@@ -263,6 +263,6 @@ See [CHANGELOG](CHANGELOG.md) for a history of changes and [UPGRADING](UPGRADING
263
263
 
264
264
  ## Copyright and License
265
265
 
266
- Copyright (c) 2015, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
266
+ Copyright (c) 2015-2016, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
267
267
 
268
268
  This project is licensed under the [MIT License](LICENSE.md).
@@ -1,6 +1,6 @@
1
1
  module SlackRubyBot
2
2
  class App < Server
3
- def initialize
3
+ def initialize(options = {})
4
4
  SlackRubyBot.configure do |config|
5
5
  config.token = ENV['SLACK_API_TOKEN'] || fail("Missing ENV['SLACK_API_TOKEN'].")
6
6
  config.aliases = ENV['SLACK_RUBY_BOT_ALIASES'].split(' ') if ENV['SLACK_RUBY_BOT_ALIASES']
@@ -8,6 +8,7 @@ module SlackRubyBot
8
8
  Slack.configure do |config|
9
9
  config.token = SlackRubyBot.config.token
10
10
  end
11
+ super
11
12
  end
12
13
 
13
14
  def config
@@ -2,10 +2,12 @@ module SlackRubyBot
2
2
  class Client < Slack::RealTime::Client
3
3
  attr_accessor :auth
4
4
  attr_accessor :aliases
5
+ attr_accessor :send_gifs
5
6
 
6
7
  def initialize(attrs = {})
7
8
  super(attrs)
8
9
  @aliases = attrs[:aliases]
10
+ @send_gifs = attrs.key?(:send_gifs) ? !!attrs[:send_gifs] : true
9
11
  end
10
12
 
11
13
  def names
@@ -27,6 +29,10 @@ module SlackRubyBot
27
29
  name && names.include?(name.downcase)
28
30
  end
29
31
 
32
+ def send_gifs?
33
+ send_gifs
34
+ end
35
+
30
36
  def name
31
37
  SlackRubyBot.config.user || (auth && auth['user'])
32
38
  end
@@ -101,13 +101,13 @@ module SlackRubyBot
101
101
  def self.get_gif_and_send(options = {})
102
102
  options = options.dup
103
103
  keywords = options.delete(:keywords)
104
+ client = options.delete(:client)
104
105
  gif = begin
105
106
  Giphy.random(keywords)
106
107
  rescue StandardError => e
107
108
  logger.warn "Giphy.random: #{e.message}"
108
109
  nil
109
- end if SlackRubyBot::Config.send_gifs?
110
- client = options.delete(:client)
110
+ end if SlackRubyBot::Config.send_gifs? && client.send_gifs?
111
111
  text = options.delete(:text)
112
112
  text = [text, gif && gif.image_url.to_s].compact.join("\n")
113
113
  send_client_message(client, { text: text }.merge(options))
@@ -3,6 +3,7 @@ module SlackRubyBot
3
3
  cattr_accessor :hooks
4
4
  attr_accessor :token
5
5
  attr_accessor :aliases
6
+ attr_accessor :send_gifs
6
7
 
7
8
  include SlackRubyBot::Hooks::Hello
8
9
  include SlackRubyBot::Hooks::Message
@@ -10,6 +11,7 @@ module SlackRubyBot
10
11
  def initialize(options = {})
11
12
  @token = options[:token]
12
13
  @aliases = options[:aliases]
14
+ @send_gifs = options.key?(:send_gifs) ? !!options[:send_gifs] : true
13
15
  end
14
16
 
15
17
  def run
@@ -83,7 +85,7 @@ module SlackRubyBot
83
85
 
84
86
  def client
85
87
  @client ||= begin
86
- client = SlackRubyBot::Client.new(aliases: aliases, token: token)
88
+ client = SlackRubyBot::Client.new(aliases: aliases, send_gifs: send_gifs, token: token)
87
89
  client.on :close do |_data|
88
90
  @client = nil
89
91
  restart! unless @stopping
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBot
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.4'
3
3
  end
@@ -30,7 +30,20 @@ describe SlackRubyBot::Commands do
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
33
- context 'set to false' do
33
+ context 'set to false via client' do
34
+ before do
35
+ client.send_gifs = false
36
+ end
37
+ it 'does not send a gif' do
38
+ expect(Giphy).to_not receive(:random)
39
+ expect(SlackRubyBot::Commands::Base).to receive(:send_client_message).with(client, channel: 'channel', text: 'message')
40
+ app.send(:message, client, text: "#{SlackRubyBot.config.user} send_message_with_gif_spec message", channel: 'channel', user: 'user')
41
+ end
42
+ after do
43
+ client.send_gifs = true
44
+ end
45
+ end
46
+ context 'set to false via config' do
34
47
  before do
35
48
  SlackRubyBot::Config.send_gifs = false
36
49
  end
@@ -1,9 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SlackRubyBot::Server do
4
+ let(:logger) { subject.send :logger }
5
+ let(:client) { Slack::RealTime::Client.new }
6
+ context 'with a token and disabled GIFs' do
7
+ subject do
8
+ SlackRubyBot::Server.new(token: 'token', send_gifs: false)
9
+ end
10
+ before do
11
+ allow(subject).to receive(:sleep)
12
+ allow(logger).to receive(:error)
13
+ end
14
+ it 'sets GIFs' do
15
+ expect(subject.send(:client).send_gifs?).to be false
16
+ end
17
+ end
4
18
  context 'with a token and aliases' do
5
- let(:client) { Slack::RealTime::Client.new }
6
- let(:logger) { subject.send :logger }
7
19
  subject do
8
20
  SlackRubyBot::Server.new(token: 'token', aliases: %w(foo bar))
9
21
  end
@@ -15,26 +27,27 @@ describe SlackRubyBot::Server do
15
27
  expect(subject.send(:client).aliases).to eq %w(foo bar)
16
28
  expect(subject.send(:client).names).to include 'foo'
17
29
  end
30
+ it 'sets GIFs' do
31
+ expect(subject.send(:client).send_gifs?).to be true
32
+ end
18
33
  it 'creates a client with a token' do
19
34
  expect(client).to receive(:start!) { fail 'expected' }
20
- expect(Slack::RealTime::Client).to receive(:new).with(token: 'token', aliases: %w(foo bar)).and_return(client)
35
+ expect(Slack::RealTime::Client).to receive(:new).with(token: 'token', send_gifs: true, aliases: %w(foo bar)).and_return(client)
21
36
  expect { subject.start! }.to raise_error RuntimeError, 'expected'
22
37
  end
23
38
  it 'asynchronously creates a client with a token' do
24
39
  expect(client).to receive(:start_async) { fail 'expected' }
25
- expect(Slack::RealTime::Client).to receive(:new).with(token: 'token', aliases: %w(foo bar)).and_return(client)
40
+ expect(Slack::RealTime::Client).to receive(:new).with(token: 'token', send_gifs: true, aliases: %w(foo bar)).and_return(client)
26
41
  expect { subject.start_async }.to raise_error RuntimeError, 'expected'
27
42
  end
28
43
  it 'stops client' do
29
- expect(Slack::RealTime::Client).to receive(:new).with(token: 'token', aliases: %w(foo bar)).and_return(client)
44
+ expect(Slack::RealTime::Client).to receive(:new).with(token: 'token', send_gifs: true, aliases: %w(foo bar)).and_return(client)
30
45
  expect(subject.send(:client)).to_not be nil
31
46
  expect(client).to receive(:started?).and_return(true)
32
47
  subject.stop!
33
48
  end
34
49
  end
35
50
  context 'retries on rtm.start errors' do
36
- let(:client) { Slack::RealTime::Client.new }
37
- let(:logger) { subject.send :logger }
38
51
  before do
39
52
  allow(subject).to receive(:auth!)
40
53
  allow(subject).to receive(:sleep)
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.3
4
+ version: 0.5.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-12-28 00:00:00.000000000 Z
11
+ date: 2016-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie