Class: SlackRubyBot::Client

Inherits:
Slack::RealTime::Client
  • Object
show all
Includes:
Loggable
Defined in:
lib/slack-ruby-bot/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Loggable

included

Constructor Details

#initialize(attrs = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/slack-ruby-bot/client.rb', line 10

def initialize(attrs = {})
  super(attrs)
  @aliases = attrs[:aliases]
  @allow_message_loops = attrs[:allow_message_loops]
  @allow_bot_messages = attrs[:allow_bot_messages]
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



6
7
8
# File 'lib/slack-ruby-bot/client.rb', line 6

def aliases
  @aliases
end

#allow_bot_messagesObject

Returns the value of attribute allow_bot_messages.



7
8
9
# File 'lib/slack-ruby-bot/client.rb', line 7

def allow_bot_messages
  @allow_bot_messages
end

#allow_message_loopsObject

Returns the value of attribute allow_message_loops.



8
9
10
# File 'lib/slack-ruby-bot/client.rb', line 8

def allow_message_loops
  @allow_message_loops
end

Instance Method Details

#allow_bot_messages?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/slack-ruby-bot/client.rb', line 21

def allow_bot_messages?
  @allow_bot_messages.nil? ? SlackRubyBot::Config.allow_bot_messages? : !!@allow_bot_messages
end

#allow_message_loops?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/slack-ruby-bot/client.rb', line 17

def allow_message_loops?
  @allow_message_loops.nil? ? SlackRubyBot::Config.allow_message_loops? : !!@allow_message_loops
end

#bot_message?(data) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/slack-ruby-bot/client.rb', line 29

def bot_message?(data)
  data.subtype == 'bot_message'
end

#message_to_self?(data) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/slack-ruby-bot/client.rb', line 25

def message_to_self?(data)
  !!(self.self && self.self.id == data.user)
end

#nameObject



52
53
54
# File 'lib/slack-ruby-bot/client.rb', line 52

def name
  SlackRubyBot.config.user || self.self&.name
end

#name?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/slack-ruby-bot/client.rb', line 48

def name?(name)
  name && names.include?(name.downcase)
end

#namesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/slack-ruby-bot/client.rb', line 33

def names
  [
    SlackRubyBot::Config.user,
    self.self ? self.self.name : nil,
    aliases ? aliases.map(&:downcase) : nil,
    SlackRubyBot::Config.aliases ? SlackRubyBot::Config.aliases.map(&:downcase) : nil,
    self.self && self.self.id ? "<@#{self.self.id.downcase}>" : nil,
    SlackRubyBot::Config.user_id ? "<@#{SlackRubyBot::Config.user_id.downcase}>" : nil,
    self.self && self.self.id ? "<@#{self.self.id.downcase}>:" : nil,
    SlackRubyBot::Config.user_id ? "<@#{SlackRubyBot::Config.user_id.downcase}>:" : nil,
    self.self && self.self.name ? "#{self.self.name.downcase}:" : nil,
    SlackRubyBot::Config.user ? "#{SlackRubyBot::Config.user}:" : nil
  ].compact.flatten
end

#say(options = {}) ⇒ Object



60
61
62
63
# File 'lib/slack-ruby-bot/client.rb', line 60

def say(options = {})
  logger.warn '[DEPRECATION] `gif:` is deprecated and has no effect.' if options.key?(:gif)
  message({ text: '' }.merge(options))
end

#urlObject



56
57
58
# File 'lib/slack-ruby-bot/client.rb', line 56

def url
  SlackRubyBot.config.url || super
end