+
+ # call-seq: map(botmodule, template, options)
+ #
+ # _botmodule_:: the BotModule which will handle this map
+ # _template_:: a String describing the messages to be matched
+ # _options_:: a Hash holding variouns options
+ #
+ # This method is used to register a new MessageTemplate that will map any
+ # BasicUserMessage matching the given _template_ to a corresponding action.
+ # A simple example:
+ # plugin.map 'myplugin :parameter'
+ # (other examples follow).
+ #
+ # By default, the action to which the messages are mapped is a method named
+ # like the first word of the template. The
+ # :action => 'method_name'
+ # option can be used to override this default behaviour. Example:
+ # plugin.map 'myplugin :parameter', :action => 'mymethod'
+ #
+ # By default whether a handler is fired depends on an auth check. In rbot
+ # versions up to 0.9.10, the first component of the string was used for the
+ # auth check, unless overridden via the :auth => 'auth_name' option. Since
+ # version 0.9.11, a new auth method has been implemented. TODO document.
+ #
+ # Static parameters (not prefixed with ':' or '*') must match the
+ # respective component of the message exactly. Example:
+ # plugin.map 'myplugin :foo is :bar'
+ # will only match messages of the form "myplugin something is
+ # somethingelse"
+ #
+ # Dynamic parameters can be specified by a colon ':' to match a single
+ # component (whitespace separated), or a * to suck up all following
+ # parameters into an array. Example:
+ # plugin.map 'myplugin :parameter1 *rest'
+ #
+ # You can provide defaults for dynamic components using the :defaults
+ # parameter. If a component has a default, then it is optional. e.g:
+ # plugin.map 'myplugin :foo :bar', :defaults => {:bar => 'qux'}
+ # would match 'myplugin param param2' and also 'myplugin param'. In the
+ # latter case, :bar would be provided from the default.
+ #
+ # Static and dynamic parameters can also be made optional by wrapping them
+ # in square brackets []. For example
+ # plugin.map 'myplugin :foo [is] :bar'
+ # will match both 'myplugin something is somethingelse' and 'myplugin
+ # something somethingelse'.
+ #
+ # Components can be validated before being allowed to match, for
+ # example if you need a component to be a number:
+ # plugin.map 'myplugin :param', :requirements => {:param => /^\d+$/}
+ # will only match strings of the form 'myplugin 1234' or some other
+ # number.
+ #
+ # Templates can be set not to match public or private messages using the
+ # :public or :private boolean options.
+ #
+ # Summary of recognized options:
+ #
+ # action::
+ # method to call when the template is matched
+ # auth_path::
+ # TODO document
+ # requirements::
+ # a Hash whose keys are names of dynamic parameters and whose values are
+ # regular expressions that the parameters must match
+ # defaults::
+ # a Hash whose keys are names of dynamic parameters and whose values are
+ # the values to be assigned to those parameters when they are missing from
+ # the message. Any dynamic parameter appearing in the :defaults Hash is
+ # therefore optional
+ # public::
+ # a boolean (defaults to true) that determines whether the template should
+ # match public (in channel) messages.
+ # private::
+ # a boolean (defaults to true) that determines whether the template should
+ # match private (not in channel) messages.
+ # threaded::
+ # a boolean (defaults to false) that determines whether the action should be
+ # called in a separate thread.
+ #
+ #
+ # Further examples:
+ #
+ # # match 'pointstats' and call my stats() method
+ # plugin.map 'pointstats', :action => 'stats'
+ # # match 'points' with an optional 'key' and call my points() method
+ # plugin.map 'points :key', :defaults => {:key => false}
+ # # match 'points for something' and call my points() method
+ # plugin.map 'points for :key'
+ #
+ # # two matches, one for public messages in a channel, one for
+ # # private messages which therefore require a channel argument
+ # plugin.map 'urls search :channel :limit :string',
+ # :action => 'search',
+ # :defaults => {:limit => 4},
+ # :requirements => {:limit => /^\d+$/},
+ # :public => false
+ # plugin.map 'urls search :limit :string',
+ # :action => 'search',
+ # :defaults => {:limit => 4},
+ # :requirements => {:limit => /^\d+$/},
+ # :private => false
+ #
+ def map(botmodule, *args)
+ @templates << MessageTemplate.new(botmodule, *args)