repost/repost.rb

33 lines
1.0 KiB
Ruby
Raw Normal View History

class Repost < EventMachine::IRC::Client
attr_accessor :triggers
def dispatch_raw_message(message = {})
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)
2013-06-09 16:21:55 +00:00
# Append a Hash containing the command it should be called at and the
# and the code.
self.triggers << {:command => command, :code => code}
end
2013-06-09 16:21:55 +00:00
def load_plugins
self.triggers = []
Config[:plugins].each do |plugin|
puts "Loading plugin #{plugin}"
load File.dirname($0) + '/plugins/' + plugin + '.rb'
end if not Config[:plugins].nil?
end
def load_config(file = "config.rb")
load File.dirname($0) + "/" + file
end
end