]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
plugins: make delegate() aware of ignored and fake messages
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 12 Apr 2008 20:07:10 +0000 (22:07 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 12 Apr 2008 20:23:11 +0000 (22:23 +0200)
By convention, ignored messages will only be delegated to plugins with
negative priority, while fake messages will only be delegated to plugins
with positive priority.

lib/rbot/plugins.rb

index 9dccf9124f7996ee5b429dc39a06d105884d4a45..8c077beadd652254f0a8a37df1ac573af11e7067 100644 (file)
@@ -792,9 +792,27 @@ module Plugins
 
     # see if each plugin handles +method+, and if so, call it, passing
     # +message+ as a parameter.  botmodules are called in order of priority
-    # from lowest to highest.  +DEPRECATED+ please use delegate_event.
+    # from lowest to highest.
+    #
+    # If the passed +message+ is marked as +#ignored?+, it will only be
+    # delegated to plugins with negative priority. Conversely, if it's
+    # a fake message  (see BotModule#fake_message), it will only be
+    # delegated to plugins with positive priority.
+    #
+    # For delegation with more extensive options, see delegate_event
+    #
     def delegate(method, *args)
-      delegate_event(method, :args => args)
+      opts = {:args => args}
+      m = args.first
+      if BasicUserMessage === m
+        # ignored messages should not be delegated
+        # to plugins with positive priority
+        opts[:below] = 0 if m.ignored?
+        # fake messages should not be delegated
+        # to plugins with negative priority
+        opts[:above] = 0 if m.recurse_depth > 0
+      end
+      delegate_event(method, opts)
     end
 
     # see if each plugin handles +method+, and if so, call it, passing