lib/fantasy-irc/plugins.rb in fantasy-irc-0.2.1 vs lib/fantasy-irc/plugins.rb in fantasy-irc-0.2.2

- old
+ new

@@ -10,11 +10,26 @@ @plugins[plugin.name] = plugin puts "#{plugin.name} = #{plugin}" end def load name - Kernel::load "plugins/#{name}.rb" + local = File.join(File.dirname($0), "plugins") + vendor = File.join(File.dirname(__FILE__), "..", "plugins") + [*name].each do |n| + file = "#{n}.rb" + local_file = File.join(local, file) + vendor_file = File.join(vendor, file) + if File.exists?(local_file) + puts "[plugin] Loading #{file} (local)." + Kernel.load local_file + elsif File::exists?(vendor_file) + puts "[plugin] Loading #{file} (vendor)." + Kernel.load vendor_file + else + puts "[plugin] #{file} could not be found." + end + end end def command command, data, args if not args.nil? args = args.split(' ') @@ -54,10 +69,17 @@ def handle! command, data, args=[] puts "trying to handle #{command} with #{data} and #{args}" @handlers.each do |pattern, block| if command.match(pattern) then puts "#{block} handles #{command}" - break block.call data, args + begin + block.call data, args + rescue Exception => e + puts "#{block} failed with Exception #{e}" + puts e.backtrace + end + + break end end end end