repost/repost.rb

50 lines
1.6 KiB
Ruby
Raw Normal View History

class Repost < EventMachine::IRC::Client
2015-04-16 08:14:55 +00:00
attr_accessor :triggers, :network
def dispatch_raw_message(message = {})
message[:scope] = {
"network" => @network,
"target" => message[:params][0],
}
2015-04-16 09:45:15 +00:00
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)
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, :name => name}
end
2015-04-16 08:07:44 +00:00
def load_plugins(scope = { "network" => @network })
2013-06-09 16:21:55 +00:00
self.triggers = []
Config.lookup("plugins::list", [], scope).each do |plugin|
2013-06-09 16:21:55 +00:00
puts "Loading plugin #{plugin}"
load File.dirname($0) + '/plugins/' + plugin + '.rb'
end
2013-06-09 16:21:55 +00:00
end
end