2013-05-29 14:46:16 +00:00
|
|
|
class Repost < EventMachine::IRC::Client
|
|
|
|
|
|
|
|
attr_accessor :triggers
|
|
|
|
|
|
|
|
def dispatch_raw_message(message = {})
|
2014-03-25 17:11:04 +00:00
|
|
|
return if Config[:ignore].include?(message[:prefix])
|
2013-05-29 14:46:16 +00:00
|
|
|
self.triggers.each do |trigger|
|
2013-05-30 06:38:37 +00:00
|
|
|
# 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.
|
2014-03-09 09:53:37 +00:00
|
|
|
begin
|
|
|
|
trigger[:code].call(message) if message[:command] == trigger[:command]
|
|
|
|
rescue => e
|
|
|
|
puts "inspect!"
|
|
|
|
puts e.inspect
|
|
|
|
puts "backtrace!"
|
|
|
|
puts e.backtrace
|
|
|
|
end
|
2013-05-29 14:46:16 +00:00
|
|
|
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.
|
2013-05-29 14:46:16 +00:00
|
|
|
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
|
|
|
|
|
2013-06-09 17:03:52 +00:00
|
|
|
def load_config(file = "config.rb")
|
|
|
|
load File.dirname($0) + "/" + file
|
|
|
|
end
|
|
|
|
|
2013-05-29 14:46:16 +00:00
|
|
|
end
|