summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-12-13 10:34:04 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-12-13 10:34:04 +0000
commitd06b96bf95563cea4ebf31e2e324536d812efdbd (patch)
tree9072c3610efcbbb6f33c5ca7676f0d8b4f95118a
parentafeb2476d6a25220b20d27030a61bf49335e2e33 (diff)
plugins: register maps with full information accessible via @bot.plugins.maps
-rw-r--r--lib/rbot/plugins.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 81e29bd1..6f308609 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -220,8 +220,10 @@ module Plugins
def do_map(silent, *args)
@handler.map(self, *args)
# register this map
- name = @handler.last.items[0]
+ 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)
@@ -335,6 +337,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.
@@ -354,6 +357,7 @@ module Plugins
@names_hash = Hash.new
@commandmappers = Hash.new
+ @maps = Hash.new
@delegate_list = Hash.new { |h, k|
h[k] = Array.new
}
@@ -385,6 +389,7 @@ module Plugins
@botmodules[:Plugin].clear
@names_hash.clear
@commandmappers.clear
+ @maps.clear
@failures_shown = false
end
@@ -411,6 +416,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