require 'singleton'
module Irc
- BotConfig.register BotConfigArrayValue.new('plugins.blacklist',
+class Bot
+ Config.register Config::ArrayValue.new('plugins.blacklist',
:default => [], :wizard => false, :requires_rescan => true,
:desc => "Plugins that should not be loaded")
module Plugins
functionality. Rather than subclassing BotModule, however, one should
subclass either CoreBotModule (reserved for system modules) or Plugin
(for user plugins).
-
+
A BotModule interacts with Irc events by defining one or more of the following
methods, which get called as appropriate when the corresponding Irc event
happens.
map is the new, cleaner way to respond to specific message formats without
littering your plugin code with regexps, and should be used instead of
#register() and #privmsg() (see below) when possible.
-
+
The difference between map and map! is that map! will not register the new
command as an alternative name for the plugin.
# the rbot instance
# @registry::
# the botmodule's registry, which can be used to store permanent data
- # (see BotRegistryAccessor for additional documentation)
+ # (see Registry::Accessor for additional documentation)
#
# Other instance variables which are defined and should not be overwritten
# byt the user, but aren't usually accessed directly, are:
@botmodule_triggers = Array.new
@handler = MessageMapper.new(self)
- @registry = BotRegistryAccessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
+ @registry = Registry::Accessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
@manager.add_botmodule(self)
if self.respond_to?('set_language')
# 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)
# 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)
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.
@names_hash = Hash.new
@commandmappers = Hash.new
+ @maps = Hash.new
@delegate_list = Hash.new { |h, k|
h[k] = Array.new
}
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
@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
key = $1
params = $2
- # Let's see if we can match a plugin by the given name
+ # Let's see if we can match a plugin by the given name
(core_modules + plugins).each { |p|
- next unless p.name == key
+ next unless p.name == key
begin
return p.help(key, params)
rescue Exception => err
end
}
- # Nope, let's see if it's a command, and ask for help at the corresponding botmodule
+ # Nope, let's see if it's a command, and ask for help at the corresponding botmodule
k = key.to_sym
if commands.has_key?(k)
p = commands[k][:botmodule]
end
end
+end