class SlackRubyBot::Hooks::Message

Public Instance Methods

call(client, data) click to toggle source
# File lib/slack-ruby-bot/hooks/message.rb, line 6
def call(client, data)
  return if !client.allow_message_loops? && client.message_to_self?(data)
  return if !client.allow_bot_messages? && client.bot_message?(data)

  prepare!(data)

  result = child_command_classes.detect { |d| d.invoke(client, data) }
  result ||= built_in_command_classes.detect { |d| d.invoke(client, data) }
  result ||= SlackRubyBot::Commands::Unknown.tap { |d| d.invoke(client, data) }
  result
end

Private Instance Methods

built_in_command_classes() click to toggle source

All built-in commands.

@return [Array] Built-in descendants of SlackRubyBot::Commands::Base.

# File lib/slack-ruby-bot/hooks/message.rb, line 49
def built_in_command_classes
  command_classes.select do |k|
    k.name&.starts_with?('SlackRubyBot::Commands::') && k != SlackRubyBot::Commands::Unknown
  end
end
child_command_classes() click to toggle source

All non-built-in, ie. custom commands.

@return [Array] Non-built-in descendants of SlackRubyBot::Commands::Base.

# File lib/slack-ruby-bot/hooks/message.rb, line 38
def child_command_classes
  command_classes.reject do |k|
    k.name&.starts_with?('SlackRubyBot::Commands::')
  end
end
command_classes() click to toggle source

All commands.

@return [Array] Descendants of SlackRubyBot::Commands::Base.

# File lib/slack-ruby-bot/hooks/message.rb, line 29
def command_classes
  SlackRubyBot::Commands::Base.command_classes
end
prepare!(data) click to toggle source
# File lib/slack-ruby-bot/hooks/message.rb, line 20
def prepare!(data)
  data.text = data.text.strip if data.text
end