repost/repost.rb
2014-03-09 10:53:37 +01:00

39 lines
1.2 KiB
Ruby

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.
begin
trigger[:code].call(message) if message[:command] == trigger[:command]
rescue => e
puts "inspect!"
puts e.inspect
puts "backtrace!"
puts e.backtrace
end
end
end
def register_trigger(command, &code)
# Append a Hash containing the command it should be called at and the
# and the code.
self.triggers << {:command => command, :code => code}
end
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