]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/plugins.rb
* handle invites properly -- forgot more than half the files :/
[user/henk/code/ruby/rbot.git] / lib / rbot / plugins.rb
index 5ad1ebb1d32628e957695ed1a484050018eda108..9d633c1b838c9bb4365a1dc1d904aeb5cdb8c443 100644 (file)
@@ -95,6 +95,9 @@ module Plugins
                          Called when a user (or the bot) is kicked from a
                          channel the bot is in.
 
+  invite(InviteMessage)::
+                         Called when the bot is invited to a channel.
+
   join(JoinMessage)::
                          Called when a user (or the bot) joins a channel
 
@@ -204,15 +207,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 +216,17 @@ 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
+      map = @handler.last
+      name = map.items[0]
+      self.register name, :auth => nil, :hidden => silent
+      @manager.register_map(self, map)
       unless self.respond_to?('privmsg')
         def self.privmsg(m) #:nodoc:
           handle(m)
@@ -338,6 +340,7 @@ module Plugins
     include Singleton
     attr_reader :bot
     attr_reader :botmodules
+    attr_reader :maps
 
     # This is the list of patterns commonly delegated to plugins.
     # A fast delegation lookup is enabled for them.
@@ -357,6 +360,7 @@ module Plugins
 
       @names_hash = Hash.new
       @commandmappers = Hash.new
+      @maps = Hash.new
       @delegate_list = Hash.new { |h, k|
         h[k] = Array.new
       }
@@ -369,12 +373,26 @@ module Plugins
       bot_associate(nil)
     end
 
+    def inspect
+      ret = self.to_s[0..-2]
+      ret << ' corebotmodules='
+      ret << @botmodules[:CoreBotModule].map { |m|
+        m.name
+      }.inspect
+      ret << ' plugins='
+      ret << @botmodules[:Plugin].map { |m|
+        m.name
+      }.inspect
+      ret << ">"
+    end
+
     # Reset lists of botmodules
     def reset_botmodule_lists
       @botmodules[:CoreBotModule].clear
       @botmodules[:Plugin].clear
       @names_hash.clear
       @commandmappers.clear
+      @maps.clear
       @failures_shown = false
     end
 
@@ -401,6 +419,19 @@ module Plugins
       @commandmappers[cmd.to_sym] = {:botmodule => botmodule, :auth => auth_path}
     end
 
+    # Registers botmodule _botmodule_ with map _map_. This adds the map to the #maps hash
+    # which has three keys:
+    #
+    # botmodule:: the associated botmodule
+    # auth:: an array of auth keys checked by the map; the first is the full_auth_path of the map
+    # map:: the actual MessageTemplate object
+    #
+    #
+    def register_map(botmodule, map)
+      raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
+      @maps[map.template] = { :botmodule => botmodule, :auth => [map.options[:full_auth_path]], :map => map }
+    end
+
     def add_botmodule(botmodule)
       raise TypeError, "Argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
       kl = botmodule.botmodule_class