49 lines
1.6 KiB
Ruby
49 lines
1.6 KiB
Ruby
class Repost < EventMachine::IRC::Client
|
|
|
|
attr_accessor :triggers, :network
|
|
|
|
def dispatch_raw_message(message = {})
|
|
message[:scope] = {
|
|
"network" => @network,
|
|
"target" => message[:params][0],
|
|
}
|
|
|
|
message[:scope]["person"] = if message[:prefix] then
|
|
message[:prefix].split("/").last
|
|
else
|
|
message[:prefix]
|
|
end
|
|
|
|
return if Config.lookup("ignore", [], message[:scope]).include? message[:prefix]
|
|
self.triggers.each do |trigger|
|
|
Config.lookup("plugins::disabled", [], message[:scope]).include? trigger[:name]
|
|
|
|
# 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, name, &code)
|
|
# Append a Hash containing the command it should be called at and the
|
|
# and the code.
|
|
self.triggers << {:command => command, :code => code, :name => name}
|
|
end
|
|
|
|
def load_plugins(scope = { "network" => @network })
|
|
self.triggers = []
|
|
Config.lookup("plugins::list", [], scope).each do |plugin|
|
|
puts "Loading plugin #{plugin}"
|
|
load File.dirname($0) + '/plugins/' + plugin + '.rb'
|
|
end
|
|
end
|
|
|
|
end
|