Module: Events

Defined in:
lib/advanced_ruby_command_handler/defaults/events/message.rb

Class Method Summary collapse

Class Method Details

.message(command_handler) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/advanced_ruby_command_handler/defaults/events/message.rb', line 4

def self.message(command_handler)
  Event.new(:message, command_handler.client) do |message|
    next unless message.content.start_with?(ENV["BOT_BASE_PREFIX"])

    args = message.content.slice(ENV["BOT_BASE_PREFIX"].size, message.content.size).strip.split(/\s+/)
    command = command_handler.find_command(args.shift)

    next unless command

    command.run.call(command_handler.client, message.message)
    Logger.check("Command #{command.name} used!")
  end
end