X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fplugins.rb;h=54b814e0eb400c89e5c58c09c0f017a3141ce93d;hb=8836539ba33a7507c23af1f410dbf78d36503148;hp=e525ebfc9a6f2486a94fbf69e52f163d88c15dce;hpb=55f4e1bc913137ca8c4012525c1a29b56885dd64;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index e525ebfc..54b814e0 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -8,8 +8,8 @@ module Plugins # # map(template, options):: # map is the new, cleaner way to respond to specific message formats - # without littering your plugin code with regexps - # examples: + # without littering your plugin code with regexps. examples: + # # plugin.map 'karmastats', :action => 'karma_stats' # # # while in the plugin... @@ -78,6 +78,9 @@ module Plugins # topic(TopicMessage):: # Called when a user (or the bot) changes a channel # topic + # + # connect():: Called when a server is joined successfully, but + # before autojoin channels are joined (no params) # # save:: Called when you are required to save your plugin's # state, if you maintain data between sessions @@ -96,6 +99,10 @@ module Plugins @registry = BotRegistryAccessor.new(@bot, self.class.to_s.gsub(/^.*::/, "")) end + def flush_registry + @registry.flush + end + def map(*args) @handler.map(*args) # register this map @@ -170,16 +177,22 @@ module Plugins # load plugins from pre-assigned list of directories def scan + processed = Array.new dirs = Array.new - dirs << Config::DATADIR + "/plugins" + dirs << Config::datadir + "/plugins" dirs += @dirs - dirs.each {|dir| + dirs.reverse.each {|dir| if(FileTest.directory?(dir)) d = Dir.new(dir) d.sort.each {|file| next if(file =~ /^\./) + next if(processed.include?(file)) + if(file =~ /^(.+\.rb)\.disabled$/) + processed << $1 + next + end next unless(file =~ /\.rb$/) - @tmpfilename = "#{dir}/#{file}" + tmpfilename = "#{dir}/#{file}" # create a new, anonymous module to "house" the plugin # the idea here is to prevent namespace pollution. perhaps there @@ -187,11 +200,13 @@ module Plugins plugin_module = Module.new begin - plugin_string = IO.readlines(@tmpfilename).join("") - debug "loading module: #{@tmpfilename}" + plugin_string = IO.readlines(tmpfilename).join("") + debug "loading plugin #{tmpfilename}" plugin_module.module_eval(plugin_string) - rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err - puts "warning: plugin #{@tmpfilename} load failed: " + err + processed << file + rescue Exception => err + # rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err + puts "warning: plugin #{tmpfilename} load failed: " + err puts err.backtrace.join("\n") end } @@ -201,6 +216,7 @@ module Plugins # call the save method for each active plugin def save + delegate 'flush_registry' delegate 'save' end @@ -240,7 +256,8 @@ module Plugins if(@@plugins.has_key?(key)) begin return @@plugins[key].help(key, params) - rescue TimeoutError, StandardError, NameError, SyntaxError => err + rescue Exception => err + #rescue TimeoutError, StandardError, NameError, SyntaxError => err puts "plugin #{@@plugins[key].name} help() failed: " + err puts err.backtrace.join("\n") end @@ -257,7 +274,8 @@ module Plugins if(p.respond_to? method) begin p.send method, *args - rescue TimeoutError, StandardError, NameError, SyntaxError => err + rescue Exception => err + #rescue TimeoutError, StandardError, NameError, SyntaxError => err puts "plugin #{p.name} #{method}() failed: " + err puts err.backtrace.join("\n") end @@ -274,7 +292,8 @@ module Plugins @@bot.auth.allow?(m.plugin, m.source, m.replyto)) begin @@plugins[m.plugin].privmsg(m) - rescue TimeoutError, StandardError, NameError, SyntaxError => err + rescue Exception => err + #rescue TimeoutError, StandardError, NameError, SyntaxError => err puts "plugin #{@@plugins[m.plugin].name} privmsg() failed: " + err puts err.backtrace.join("\n") end