]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
patch from Alexey Froloff:
authorTom Gilbert <tom@linuxbrit.co.uk>
Wed, 10 Aug 2005 23:04:16 +0000 (23:04 +0000)
committerTom Gilbert <tom@linuxbrit.co.uk>
Wed, 10 Aug 2005 23:04:16 +0000 (23:04 +0000)
  Do not try to load same plugin from different locations.  Added
  ability to disable system-wide plugins - create
  PLUGIN.rb.disabled in user's plugins directory.

  For example, to disable freshmeat plugin installed in
  /usr/share/rbot/plugins/freshmeat.rb one can create empty file
  ~/.rbot/plugins/freshmeat.rb.disabled

lib/rbot/plugins.rb

index bffba2273994e98d658bee176583c54c080f3509..893bb4142650da70c11f6f3137db7314a8c6e9d3 100644 (file)
@@ -173,14 +173,20 @@ module Plugins
 
     # load plugins from pre-assigned list of directories
     def scan
+      processed = Array.new
       dirs = Array.new
       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}"
 
@@ -193,6 +199,7 @@ module Plugins
               plugin_string = IO.readlines(tmpfilename).join("")
               debug "loading plugin #{tmpfilename}"
               plugin_module.module_eval(plugin_string)
+              processed << file
             rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err
               puts "warning: plugin #{tmpfilename} load failed: " + err
               puts err.backtrace.join("\n")