Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Giphy support #263

Merged
merged 2 commits into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ matrix:
- rvm: 2.3.0
env: CONCURRENCY=async-websocket
- rvm: 2.6.5
env: CONCURRENCY=celluloid-io WITH_GIPHY=true
- rvm: 2.6.5
env: CONCURRENCY=faye-websocket WITH_GIPHY=true
- rvm: 2.6.5
env: CONCURRENCY=celluloid-io WITH_GIPHY_CLIENT=true
env: CONCURRENCY=celluloid-io
- rvm: 2.6.5
env: CONCURRENCY=faye-websocket WITH_GIPHY_CLIENT=true
env: CONCURRENCY=faye-websocket
- rvm: 2.6.5
env: CONCURRENCY=async-websocket WITH_GIPHY_CLIENT=true
env: CONCURRENCY=async-websocket
- rvm: ruby-head
- rvm: jruby-head
allow_failures:
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
4 changes: 0 additions & 4 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ Set the SLACK_API_TOKEN environment variable using the token received above.
heroku config:add SLACK_API_TOKEN=...
```

#### GIPHY_API_KEY

The bot replies with animated GIFs. While it's currently not necessary, you may need to set GIPHY_API_KEY in the future, see [github.com/Giphy/GiphyAPI](https://github.com/Giphy/GiphyAPI) for details.

#### SLACK_RUBY_BOT_ALIASES

Optional names for this bot.
Expand Down
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ if ENV.key?('CONCURRENCY')
end
end

gem 'giphy', require: false if ENV.key?('WITH_GIPHY')
gem 'GiphyClient', require: false if ENV.key?('WITH_GIPHY_CLIENT')

group :test do
gem 'slack-ruby-danger', '~> 0.1.0', require: false
end
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
11 changes: 11 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Upgrading SlackRubyBot
======================

### Upgrading to >= 0.16.0

#### Removed GIF support

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
message_command = SlackRubyBot::Hooks::Message.new
channel, user, message, attachments = parse(actual)

allow(Giphy).to receive(:random) if defined?(Giphy)

begin
expect do
message_command.call(client, Hashie::Mash.new(text: message, channel: channel, user: user, attachments: attachments))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
message_command = SlackRubyBot::Hooks::Message.new
channel, user, message, attachments = parse(actual)

allow(Giphy).to receive(:random) if defined?(Giphy)

allow(client).to receive(:message) do |options|
@messages ||= []
@messages.push options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
message_command = SlackRubyBot::Hooks::Message.new
channel, user, message, attachments = parse(actual)

allow(Giphy).to receive(:random) if defined?(Giphy)

@messages ||= []
allow(client).to receive(:message) do |options|
@messages.push options
Expand Down
Loading