repost/repost.rb
Robert Gerus 951950a7b2 fix!
2014-03-25 18:11:04 +01:00

40 lines
1.3 KiB
Ruby

class Repost < EventMachine::IRC::Client
attr_accessor :triggers
def dispatch_raw_message(message = {})
return if Config[:ignore].include?(message[:prefix])
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