]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
plugins: allow plugins whitelisting
authorRaine Virta <rane@kapsi.fi>
Fri, 27 Feb 2009 23:34:50 +0000 (01:34 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 28 Feb 2009 00:43:45 +0000 (01:43 +0100)
If the whitelist is not empty, only load the specified plugins.

lib/rbot/plugins.rb

index 00fc423457a6a39bd82117e25202b00408baaaec..e7905c505ad35dc4977b31ee24f8421eb11e67a8 100755 (executable)
@@ -10,6 +10,9 @@ class Bot
     Config.register Config::ArrayValue.new('plugins.blacklist',
       :default => [], :wizard => false, :requires_rescan => true,
       :desc => "Plugins that should not be loaded")
+    Config.register Config::ArrayValue.new('plugins.whitelist',
+      :default => [], :wizard => false, :requires_rescan => true,
+      :desc => "Only whitelisted plugins will be loaded unless the list is empty")
 module Plugins
   require 'rbot/messagemapper'
 
@@ -614,6 +617,10 @@ module Plugins
           pn = p + ".rb"
           processed[pn.intern] = :blacklisted
         }
+
+        whitelist = @bot.config['plugins.whitelist'].map { |p|
+          p + ".rb"
+        }
       end
 
       dirs.each do |dir|
@@ -625,7 +632,10 @@ module Plugins
 
           case type
           when :plugins
-            if processed.has_key?(file.intern)
+            if !whitelist.empty? && !whitelist.include?(file)
+              @ignored << {:name => file, :dir => dir, :reason => :"not whitelisted" }
+              next
+            elsif processed.has_key?(file.intern)
               @ignored << {:name => file, :dir => dir, :reason => processed[file.intern]}
               next
             end