module SlackRubyBot::Hooks::Message
Public Instance Methods
message(client, data)
click to toggle source
# File lib/slack-ruby-bot/hooks/message.rb, line 6 def message(client, data) data = Hashie::Mash.new(data) return if !SlackRubyBot::Config.allow_message_loops? && (client.self && client.self['id'] == data.user) data.text.strip! if data.text 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 43 def built_in_command_classes command_classes.select do |k| k.name && 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 32 def child_command_classes command_classes.reject do |k| k.name && 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 23 def command_classes SlackRubyBot::Commands::Base.descendants end