]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
plugins: refactor common code in #map() and #map!() to auxiliary #do_map() method
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 13 Dec 2007 10:33:19 +0000 (10:33 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 13 Dec 2007 10:33:19 +0000 (10:33 +0000)
lib/rbot/plugins.rb

index 12fade3e211cb64db61d4f3bf094297238d90503..81e29bd189bed04d925ff14e73a7cd52e848f2a8 100644 (file)
@@ -204,15 +204,7 @@ module Plugins
     # responds to appropriately-formed messages on Irc.
     #
     def map(*args)
-      @handler.map(self, *args)
-      # register this map
-      name = @handler.last.items[0]
-      self.register name, :auth => nil
-      unless self.respond_to?('privmsg')
-        def self.privmsg(m) #:nodoc:
-          handle(m)
-        end
-      end
+      do_map(false, *args)
     end
 
     # call-seq: map!(template, options)
@@ -221,10 +213,15 @@ module Plugins
     # as an alternative name for the plugin.
     #
     def map!(*args)
+      do_map(true, *args)
+    end
+
+    # Auxiliary method called by #map and #map!
+    def do_map(silent, *args)
       @handler.map(self, *args)
       # register this map
       name = @handler.last.items[0]
-      self.register name, :auth => nil, :hidden => true
+      self.register name, :auth => nil, :hidden => silent
       unless self.respond_to?('privmsg')
         def self.privmsg(m) #:nodoc:
           handle(m)