summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-02 09:30:08 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-02 09:30:08 +0000
commita6b1cf368b1d6ab8b66a69eb63560a898b224d7e (patch)
tree99869ec09c4982f49531a34114461a02259571ea /lib/rbot
parentd73581c3424176cd83e58e8e8fdceea528b172f7 (diff)
plugins.rb: set up fast delegation hash
Delegating a message requires checking if each of the loaded plugins responds to a given method. This can be time consuming when many plugins are loaded. We set up a hash that maps each commonly delegated method to the list of plugins that respond to it.
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/plugins.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index e1cf9c9f..9880d720 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -270,6 +270,16 @@ module Plugins
attr_reader :bot
attr_reader :botmodules
+ # This is the list of patterns commonly delegated to plugins.
+ # A fast delegation lookup is enabled for them.
+ DEFAULT_DELEGATE_PATTERNS = %r{^(?:
+ connect|names|nick|
+ listen|ctcp_listen|privmsg|unreplied|
+ kick|join|part|quit|
+ save|cleanup|flush_registry|
+ set_.*|event_.*
+ )$}x
+
def initialize
@botmodules = {
:CoreBotModule => [],
@@ -278,6 +288,9 @@ module Plugins
@names_hash = Hash.new
@commandmappers = Hash.new
+ @delegate_list = Hash.new { |h, k|
+ h[k] = Array.new
+ }
@dirs = []
@@ -416,6 +429,8 @@ module Plugins
def scan
@failed.clear
@ignored.clear
+ @delegate_list.clear
+
processed = Hash.new
@bot.config['plugins.blacklist'].each { |p|
@@ -460,6 +475,11 @@ module Plugins
end
}
debug "finished loading plugins: #{status(true)}"
+ (core_modules + plugins).each { |p|
+ p.methods.grep(DEFAULT_DELEGATE_PATTERNS).each { |m|
+ @delegate_list[m.intern] << p
+ }
+ }
end
# call the save method for each active plugin