X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fplugins.rb;h=06cc09e7527b8a3ad14feaea6ac144b7215b33e8;hb=HEAD;hp=0e7e9d6f4a4163465aa6a2df810b913554d2198d;hpb=2700d5d2817671329261b22f8edc3a27b1f52595;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 0e7e9d6f..06cc09e7 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -161,6 +161,9 @@ module Plugins # the message map handler attr_reader :handler + # the directory in which the plugin is located + attr_reader :plugin_path + # Initialise your bot module. Always call super if you override this method, # as important variables are set up for you: # @@ -191,6 +194,7 @@ module Plugins @registry = @bot.registry_factory.create(@bot.path, self.class.to_s.gsub(/^.*::/, '')) @manager.add_botmodule(self) + @plugin_path = @manager.next_plugin_path if self.respond_to?('set_language') self.set_language(@bot.lang.language) end @@ -215,6 +219,7 @@ module Plugins @registry.flush end + # Method called to cleanup before the plugin is unloaded. If you overload # this method to handle additional cleanup tasks, remember to call super() # so that the default cleanup actions are taken care of as well. @@ -410,6 +415,10 @@ module Plugins attr_reader :botmodules attr_reader :maps + attr_reader :core_module_dirs + attr_reader :plugin_dirs + attr_reader :next_plugin_path + # This is the list of patterns commonly delegated to plugins. # A fast delegation lookup is enabled for them. DEFAULT_DELEGATE_PATTERNS = %r{^(?: @@ -579,6 +588,10 @@ module Plugins ([str, err.inspect] + err.backtrace).join("\n") end + def get_plugin(name) + plugins.find { |plugin| plugin.name == name } + end + # This method is the one that actually loads a module from the # file _fname_ # @@ -602,8 +615,14 @@ module Plugins begin plugin_string = IO.read(fname) debug "loading #{desc}#{fname}" + + # set path of the plugin that will be loaded next (see BotModule#initialize) + @next_plugin_path = File.dirname fname + plugin_module.module_eval(plugin_string, fname) + @next_plugin_path = nil + return :loaded rescue Exception => err # rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err @@ -634,6 +653,10 @@ module Plugins # idiotic approaches if err.class.respond_to? :from_message newerr = err.class.from_message(msg) + elsif ([:file, :line, :column, :offset, :problem, :context] & err.methods).length == 6 + # Another ‘brillian’ overload, this time from Psych::SyntaxError + # In this case we'll just leave the message as-is + newerr = err.dup else raise aerr_in_err end @@ -650,7 +673,6 @@ module Plugins return newerr end end - private :load_botmodule_file # add one or more directories to the list of directories to # load core modules from @@ -998,7 +1020,7 @@ module Plugins sort_modules unless @sorted_modules opts = {} - opts.merge(args.pop) if args.last.class == Hash + opts.merge!(args.pop) if args.last.class == Hash m = args.first if BasicUserMessage === m