summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-02-27 21:30:40 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-28 01:43:45 +0100
commitbe5d914984e767ce1a718b84d0bad1c88d9f8ea3 (patch)
treee9934232ccd9e792890e261dff35ef10abf98fa5 /lib/rbot
parent978ea255291ea27fef7d5d685a49eb0d52d4e9c9 (diff)
plugins: refactor plugin scanning
Refactor plugin scanning for cleaner distinction between core modules and plugins.
Diffstat (limited to 'lib/rbot')
-rwxr-xr-x[-rw-r--r--]lib/rbot/plugins.rb66
1 files changed, 39 insertions, 27 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 5c5cdddc..00fc4234 100644..100755
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -600,27 +600,31 @@ module Plugins
debug "Core module and plugin loading paths cleared"
end
- # load plugins from pre-assigned list of directories
- def scan
- @failed.clear
- @ignored.clear
- @delegate_list.clear
-
+ def scan_botmodules(opts={})
+ type = opts[:type]
processed = Hash.new
- @bot.config['plugins.blacklist'].each { |p|
- pn = p + ".rb"
- processed[pn.intern] = :blacklisted
- }
+ case type
+ when :core
+ dirs = @core_module_dirs
+ when :plugins
+ dirs = @plugin_dirs
- dirs = @core_module_dirs + @plugin_dirs
- dirs.each {|dir|
- if(FileTest.directory?(dir))
- d = Dir.new(dir)
- d.sort.each {|file|
+ @bot.config['plugins.blacklist'].each { |p|
+ pn = p + ".rb"
+ processed[pn.intern] = :blacklisted
+ }
+ end
- next if(file =~ /^\./)
+ dirs.each do |dir|
+ next unless FileTest.directory?(dir)
+ d = Dir.new(dir)
+ d.sort.each do |file|
+ next unless file =~ /\.rb$/
+ next if file =~ /^\./
+ case type
+ when :plugins
if processed.has_key?(file.intern)
@ignored << {:name => file, :dir => dir, :reason => processed[file.intern]}
next
@@ -635,20 +639,28 @@ module Plugins
@ignored << {:name => $1, :dir => dir, :reason => processed[$1.intern]}
next
end
+ end
+
+ did_it = load_botmodule_file("#{dir}/#{file}", "plugin")
+ case did_it
+ when Symbol
+ processed[file.intern] = did_it
+ when Exception
+ @failed << { :name => file, :dir => dir, :reason => did_it }
+ end
+ end
+ end
+ end
- next unless(file =~ /\.rb$/)
+ # load plugins from pre-assigned list of directories
+ def scan
+ @failed.clear
+ @ignored.clear
+ @delegate_list.clear
- did_it = load_botmodule_file("#{dir}/#{file}", "plugin")
- case did_it
- when Symbol
- processed[file.intern] = did_it
- when Exception
- @failed << { :name => file, :dir => dir, :reason => did_it }
- end
+ scan_botmodules(:type => :core)
+ scan_botmodules(:type => :plugins)
- }
- end
- }
debug "finished loading plugins: #{status(true)}"
(core_modules + plugins).each { |p|
p.methods.grep(DEFAULT_DELEGATE_PATTERNS).each { |m|