Class: SlackRubyBot::Client
- Inherits:
-
Slack::RealTime::Client
- Object
- Slack::RealTime::Client
- SlackRubyBot::Client
- Includes:
- Loggable
- Defined in:
- lib/slack-ruby-bot/client.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#send_gifs ⇒ Object
Returns the value of attribute send_gifs.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Client
constructor
A new instance of Client.
- #name ⇒ Object
- #name?(name) ⇒ Boolean
- #names ⇒ Object
- #say(options = {}) ⇒ Object
- #send_gifs? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/slack-ruby-bot/client.rb', line 8 def initialize(attrs = {}) super(attrs) @aliases = attrs[:aliases] @send_gifs = attrs.key?(:send_gifs) ? !!attrs[:send_gifs] : true end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
5 6 7 |
# File 'lib/slack-ruby-bot/client.rb', line 5 def aliases @aliases end |
#auth ⇒ Object
Returns the value of attribute auth.
4 5 6 |
# File 'lib/slack-ruby-bot/client.rb', line 4 def auth @auth end |
#send_gifs ⇒ Object
Returns the value of attribute send_gifs.
6 7 8 |
# File 'lib/slack-ruby-bot/client.rb', line 6 def send_gifs @send_gifs end |
Instance Method Details
#name ⇒ Object
37 38 39 |
# File 'lib/slack-ruby-bot/client.rb', line 37 def name SlackRubyBot.config.user || (auth && auth['user']) end |
#name?(name) ⇒ Boolean
29 30 31 |
# File 'lib/slack-ruby-bot/client.rb', line 29 def name?(name) name && names.include?(name.downcase) end |
#names ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/slack-ruby-bot/client.rb', line 14 def names [ SlackRubyBot::Config.user, auth ? auth['user'] : nil, aliases, SlackRubyBot::Config.aliases, auth ? "<@#{auth['user_id'].downcase}>" : nil, SlackRubyBot::Config.user_id ? "<@#{SlackRubyBot::Config.user_id.downcase}>" : nil, auth ? "<@#{auth['user_id'].downcase}>:" : nil, SlackRubyBot::Config.user_id ? "<@#{SlackRubyBot::Config.user_id.downcase}>:" : nil, auth ? "#{auth['user']}:" : nil, SlackRubyBot::Config.user ? "#{SlackRubyBot::Config.user}:" : nil ].compact.flatten end |
#say(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/slack-ruby-bot/client.rb', line 45 def say( = {}) = .dup # get GIF keywords = .delete(:gif) # text text = .delete(:text) gif = begin Giphy.random(keywords) rescue StandardError => e logger.warn "Giphy.random: #{e.}" nil end if SlackRubyBot::Config.send_gifs? && send_gifs? && keywords text = [text, gif && gif.image_url.to_s].compact.join("\n") ({ text: text }.merge()) end |
#send_gifs? ⇒ Boolean
33 34 35 |
# File 'lib/slack-ruby-bot/client.rb', line 33 def send_gifs? send_gifs end |
#url ⇒ Object
41 42 43 |
# File 'lib/slack-ruby-bot/client.rb', line 41 def url SlackRubyBot.config.url || (auth && auth['url']) end |