Skip to content

Commit

Permalink
Removed Giphy support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jun 27, 2020
1 parent 0dffba4 commit 57470d3
Show file tree
Hide file tree
Showing 26 changed files with 30 additions and 608 deletions.
9 changes: 1 addition & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-03-31 08:37:36 -0400 using RuboCop version 0.80.1.
# on 2020-06-27 10:06:13 -0400 using RuboCop version 0.80.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -11,13 +11,6 @@ Lint/DuplicateMethods:
Exclude:
- 'lib/slack-ruby-bot/hooks/set.rb'

# Offense count: 2
# Configuration parameters: AllowComments.
Lint/SuppressedException:
Exclude:
- 'lib/initializers/giphy.rb'
- 'lib/initializers/giphy_client.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
### 0.15.1 (Next)
### 0.16.0 (Next)

* Your contribution here.
* [#263](https://github.com/slack-ruby/slack-ruby-bot/pull/263): Removed Giphy support - [@dblock](https://github.com/dblock).
* [#260](https://github.com/slack-ruby/slack-ruby-bot/pull/260): Add brief migration guide - [@wasabigeek](https://github.com/wasabigeek).
* Your contribution here.

### 0.15.0 (2020/5/8)

Expand Down
45 changes: 2 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,47 +321,6 @@ class AuthorizedBot < SlackRubyBot::Commands::Base
end
```

### Animated GIFs

The `SlackRubyBot::Client` implementation comes with GIF support. To enable it add `gem GiphyClient` (official Giphy SDK) or `gem giphy` (older SDK, deprecated) to your **Gemfile** and set a Giphy key via `ENV['GIPHY_API_KEY']`. Obtain one from [developers.giphy.com](https://developers.giphy.com).

**Note:** Bots send animated GIFs in default commands and errors.

```ruby
class Phone < SlackRubyBot::Commands::Base
command 'call'

def self.call(client, data, match)
client.say(channel: data.channel, text: 'called', gif: 'phone')
# Sends the text 'called' and a random GIF that matches the keyword 'phone'.
end
end
```

Giphy API key is set automatically via `ENV['GIPHY_API_KEY']`. You can override this manually.

```ruby
Giphy.configure do |config|
config.api_key = 'key'
end
```

With `GiphyClient` you can configure the default GIF [content rating](https://developers.giphy.com/docs/optional-settings#rating), which supports G, PG, PG-13, and R. The default value is `G`.

```ruby
Giphy.configure do |config|
config.rating = 'PG'
end
```

If you use giphy for something else but don't want your bots to send GIFs you can set `ENV['SLACK_RUBY_BOT_SEND_GIFS']` or `SlackRubyBot::Config.send_gifs` to `false`. The latter takes precedence.

```ruby
SlackRubyBot.configure do |config|
config.send_gifs = false
end
```

### Built-In Commands

Slack-ruby-bot comes with several built-in commands. You can re-define built-in commands, normally, as described above.
Expand Down Expand Up @@ -512,14 +471,14 @@ end

### Advanced Integration

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`.
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`.

```ruby
EM.run do
bot1 = SlackRubyBot::Server.new(token: token1, aliases: ['bot1'])
bot1.start_async

bot2 = SlackRubyBot::Server.new(token: token2, send_gifs: false, aliases: ['bot2'])
bot2 = SlackRubyBot::Server.new(token: token2, aliases: ['bot2'])
bot2.start_async
end
```
Expand Down
10 changes: 10 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Upgrading SlackRubyBot
======================

### Upgrading to >= 0.16.0

#### Removed GIF support

GIF, Giphy and other animated GIF support has been removed.

The `SlackRubyBot::Commands::Base#send_message`, `send_message_with_gif` and `send_gif` methods have been removed.

See [#261](https://github.com/slack-ruby/slack-ruby-bot/issues/261) for details.

### Upgrading to >= 0.15.0

#### Set up VCR explicitly
Expand Down
10 changes: 0 additions & 10 deletions lib/initializers/giphy.rb

This file was deleted.

41 changes: 0 additions & 41 deletions lib/initializers/giphy_client.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.instance
end

def self.call(client, data, _match)
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'understand')
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!")
end
end
end
24 changes: 2 additions & 22 deletions lib/slack-ruby-bot/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Client < Slack::RealTime::Client
def initialize(attrs = {})
super(attrs)
@aliases = attrs[:aliases]
@send_gifs = attrs[:send_gifs]
end

def names
Expand All @@ -31,12 +30,6 @@ def name?(name)
name && names.include?(name.downcase)
end

def send_gifs?
return false unless defined?(Giphy)

send_gifs.nil? ? SlackRubyBot::Config.send_gifs? : send_gifs
end

def name
SlackRubyBot.config.user || self.self&.name
end
Expand All @@ -46,21 +39,8 @@ def url
end

def say(options = {})
options = options.dup
# get GIF
keywords = options.delete(:gif)
# text
text = options.delete(:text)
if keywords && send_gifs?
gif = begin
Giphy.random(keywords)
rescue StandardError => e
logger.warn "Giphy.random: #{e.message}"
nil
end
end
text = [text, gif && gif.image_url.to_s].compact.join("\n")
message({ text: text }.merge(options))
logger.warn '[DEPRECATION] `gif:` is deprecated and has no effect.' if options.key?(:gif)
message({ text: '' }.merge(options))
end
end
end
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/commands/about.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Default < Base
match(/^#{bot_matcher}$/u)

def self.call(client, data, _match)
client.say(channel: data.channel, text: SlackRubyBot::ABOUT, gif: 'selfie')
client.say(channel: data.channel, text: SlackRubyBot::ABOUT)
end
end
end
Expand Down
19 changes: 0 additions & 19 deletions lib/slack-ruby-bot/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@ def inherited(subclass)
SlackRubyBot::Commands::Base.command_classes << subclass
end

def send_message(client, channel, text, options = {})
logger.warn '[DEPRECATION] `send_message` is deprecated. Please use `client.say` instead.'
if text && !text.length.empty?
client.say(options.merge(channel: channel, text: text))
else
client.say(options.merge(channel: channel, text: 'Nothing to see here.', gif: 'nothing'))
end
end

def send_message_with_gif(client, channel, text, keywords, options = {})
logger.warn '[DEPRECATION] `send_message_with_gif` is deprecated. Please use `client.say` instead.'
client.say(options.merge(channel: channel, text: text, gif: keywords))
end

def send_gif(client, channel, keywords, options = {})
logger.warn '[DEPRECATION] `send_gif` is deprecated. Please use `client.say` instead.'
client.say(options.merge(channel: channel, text: '', gif: keywords))
end

def help(&block)
Support::Help.instance.capture_help(self, &block)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/commands/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Help < Base
general_text
end

client.say(channel: data.channel, text: text, gif: 'help')
client.say(channel: data.channel, text: text)
end

class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/commands/hi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Hi < Base
end

def self.call(client, data, _match)
client.say(channel: data.channel, text: "Hi <@#{data.user}>!", gif: 'hi')
client.say(channel: data.channel, text: "Hi <@#{data.user}>!")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/commands/unknown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Unknown < Base
match(/^(?<bot>\S*)[\s]*(?<expression>.*)$/)

def self.call(client, data, _match)
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!", gif: 'understand')
client.say(channel: data.channel, text: "Sorry <@#{data.user}>, I don't understand that command!")
end
end
end
Expand Down
9 changes: 1 addition & 8 deletions lib/slack-ruby-bot/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module SlackRubyBot
module Config
extend self

ATTRS = %i[token url aliases user user_id team team_id allow_bot_messages allow_message_loops send_gifs logger].freeze
ATTRS = %i[token url aliases user user_id team team_id allow_bot_messages allow_message_loops logger].freeze
attr_accessor(*ATTRS)

def allow_bot_messages?
Expand All @@ -15,13 +15,6 @@ def allow_message_loops?
!!allow_message_loops
end

def send_gifs?
return false unless defined?(Giphy)

v = boolean_from_env('SLACK_RUBY_BOT_SEND_GIFS')
send_gifs.nil? ? (v.nil? || v) : send_gifs
end

def reset!
ATTRS.each { |attr| send("#{attr}=", nil) }
end
Expand Down
5 changes: 2 additions & 3 deletions lib/slack-ruby-bot/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module SlackRubyBot
class Server
include Loggable

attr_accessor :token, :aliases, :send_gifs
attr_accessor :token, :aliases

include SlackRubyBot::Hooks::HookSupport

Expand All @@ -13,7 +13,6 @@ class Server
def initialize(options = {})
@token = options[:token]
@aliases = options[:aliases]
@send_gifs = options[:send_gifs]

# Hook Handling
flush_hook_blocks
Expand Down Expand Up @@ -79,7 +78,7 @@ def handle_signals

def client
@client ||= begin
client = SlackRubyBot::Client.new(aliases: aliases, send_gifs: send_gifs, token: token)
client = SlackRubyBot::Client.new(aliases: aliases, token: token)
_hooks.client = client

client
Expand Down
2 changes: 1 addition & 1 deletion lib/slack-ruby-bot/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SlackRubyBot
VERSION = '0.15.1'
VERSION = '0.16.0'
end
37 changes: 0 additions & 37 deletions spec/slack-ruby-bot/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
# frozen_string_literal: true

describe SlackRubyBot::Client do
describe '#send_gifs?' do
context 'without giphy is false', unless: WithGiphy.env? do
it 'by default' do
expect(subject.send_gifs?).to be false
end

it 'when set to true' do
subject.send_gifs = true
expect(subject.send_gifs?).to be false
end

it 'when set to true via config' do
SlackRubyBot::Config.send_gifs = true
expect(SlackRubyBot::Config.send_gifs?).to be false
end
end

context 'with giphy', if: WithGiphy.env? do
it 'default is true' do
expect(subject.send_gifs?).to be true
end

it 'defaults to SlackRubyBot::Config.send_gifs? if set' do
SlackRubyBot::Config.send_gifs = false
expect(subject.send_gifs?).to be false
end

it 'client setting takes precedence' do
SlackRubyBot::Config.send_gifs = true
subject.send_gifs = false
expect(subject.send_gifs?).to be false
SlackRubyBot::Config.send_gifs = false
subject.send_gifs = true
expect(subject.send_gifs?).to be true
end
end
end
end
Loading

0 comments on commit 57470d3

Please sign in to comment.