repost/repost.rb

23 lines
843 B
Ruby

class Repost < EventMachine::IRC::Client
attr_accessor :triggers
def dispatch_raw_message(message = {})
self.triggers = [] if self.triggers.nil?
self.triggers.each do |trigger|
# Having per-command lists of blocks of code to call would be
# faster, but it's not a problem for now. Might refactor this loop
# and register_trigger() method if it comes to that.
trigger[:code].call(message) if message[:command] == trigger[:command]
end
end
def register_trigger(command, &code)
# Make sure the Array of triggers is not empty and then append to it a
# Hash containing the command it should be called at and the code
self.triggers = [] if self.triggers.nil?
self.triggers << {:command => command, :code => code}
end
end