class Issola::Command::Handler

Public Class Methods

new() click to toggle source
# File lib/issola/command/handler.rb, line 4
def initialize
  @commands = {}
end

Public Instance Methods

handle(event) click to toggle source
# File lib/issola/command/handler.rb, line 18
def handle(event)
  tokens = event.message.content.split(' ')
  puts "Checking for command in message: #{ tokens.inspect }"

  # Get rid of command prefix
  key = tokens.first[1..-1]
  cmd = @commands[key]
  if cmd
    puts "Found command!"
    cmd.action.call(event)
  end
end
register() { |builder| ... } click to toggle source
# File lib/issola/command/handler.rb, line 8
def register
  builder = Builder.new

  yield builder
  raise ArgumentError, 'Unable to register command, required attribute(s) missing.' unless builder.valid?

  cmd = builder.command
  @commands[cmd.key] = cmd
end