diff options
author | doki_pen <rcorsaro@optaros.com> | 2008-04-12 11:38:50 -0400 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-04-12 21:50:34 +0200 |
commit | 014d7d1078fd070055db76a89cdfadb8f107541d (patch) | |
tree | 5547256e2c3be91dae3c1607682bb9a50d08b7c4 /lib/rbot/plugins.rb | |
parent | 2e87853789cc18c6a3450f9c79da32f94920d376 (diff) |
event delegation thresholds
Diffstat (limited to 'lib/rbot/plugins.rb')
-rw-r--r-- | lib/rbot/plugins.rb | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 9277d183..9dccf912 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -791,14 +791,32 @@ module Plugins end # see if each plugin handles +method+, and if so, call it, passing - # +message+ as a parameter + # +message+ as a parameter. botmodules are called in order of priority + # from lowest to highest. +DEPRECATED+ please use delegate_event. def delegate(method, *args) + delegate_event(method, :args => args) + end + + # see if each plugin handles +method+, and if so, call it, passing + # +opts[:args]+ as a parameter. +opts[:above]+ and +opts[:below]+ + # are used for a threshold of botmodule priorities that will be called. + # If :above is defined, only botmodules with a priority above the value + # will be called, for example. botmodules are called in order of + # priority from lowest to hightest. + def delegate_event(method, o={}) # if the priorities order of the delegate list is dirty, # meaning some modules have been added or priorities have been # changed, then the delegate list will need to be sorted before # delegation. This should always be true for the first delegation. sort_modules unless @sorted_modules - + + # set defaults + opts = {:args => []}.merge(o) + + above = opts[:above] + below = opts[:below] + args = opts[:args] + # debug "Delegating #{method.inspect}" ret = Array.new if method.match(DEFAULT_DELEGATE_PATTERNS) @@ -808,7 +826,10 @@ module Plugins return [] unless @delegate_list.has_key?(m) @delegate_list[m].each { |p| begin - ret.push p.send(method, *args) + prio = p.priority + unless (above and above >= prio) or (below and below <= prio) + ret.push p.send(method, *(args||[])) + end rescue Exception => err raise if err.kind_of?(SystemExit) error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err) @@ -821,7 +842,10 @@ module Plugins if(p.respond_to? method) begin # debug "#{p.botmodule_class} #{p.name} responds" - ret.push p.send(method, *args) + prio = p.priority + unless (above and above >= prio) or (below and below <= prio) + ret.push p.send(method, *(args||[])) + end rescue Exception => err raise if err.kind_of?(SystemExit) error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err) |