| | |
- kibot.BaseModule.BaseModule
-
- CommandHandler
- Command
- ReplyObject
-
- DirectConnectionReply
- IRCReply
class Command |
| |
An instance of this class will be created for each command, and
will be passed to every command function. Creation is automatic
(in CommandHandler._do_command).
The public attributes are:
cmd.bot - the bot object
cmd.nick - nick of the user who executed the command
cmd.nickmask - nickmask of the user who executed the command
cmd.channel - channel on which it was executed (or None if private)
cmd.cmd - the string command as it was typed
cmd.args - single string containing the args (stuff after cmd.cmd)
cmd.event - the raw event (instance of kibot.m_irclib.Event) that
led to the command (probably a pubmsg or privmsg event)
There are also a number of convenience methods (documented below):
cmd.asplit(maxsplit=-1)
cmd.shsplit(maxsplit=-1)
In addition to the above methods, each of the IRCReply methods are
copied in and are available directly as Command methods. |
| |
Methods defined here:
- __init__(self, **kwargs)
- bot=self.bot, nick=nick, nickmask=nickmask, channel=channel,
cmd=cmd, args=args, _reply_object=reply, event=event
- __str__(self)
- asplit(self, maxsplit=-1)
- split the arguments string on whitespace
- shsplit(self, maxsplit=-1)
- split the arguments string shell-style (quotes and backslashes)
Data and non-method functions defined here:
- __doc__ = 'An instance of this class will be created for ea...d are available directly as Command methods.\n '
- __module__ = 'kibot.CommandHandler'
|
class CommandHandler(kibot.BaseModule.BaseModule) |
| |
This class is for handling bot commands. An instance will
be stored as bot.command_handler, but has no public methods
and should not be accessed directly. |
| |
Methods defined here:
- __init__(self, bot)
- _check_ignore(self, cmd)
- _cmd_split(self, command)
- split a command line into command and args
args is a single string
- _do_command(self, nm, channel, command, connection, event)
- called by the pubmsg and privmsg handlers
creates the reply object and command object, and passes
it on to _run()
- _on_command(self, c, e)
- default handler for command events
- _on_command_not_found(self, c, e)
- default handler for command_not_found events
- _on_permission_denied(self, c, e)
- default handler for permission_denied events
- _on_privmsg(self, c, e)
- handler for all private messages to the bot
- _on_pubmsg(self, c, e)
- handler for all public (channel) messages
- _run(self, cmd)
- check permissions, look up function, and throw either a
command_not_found, permission_denied, or command event
- _unload(self)
Data and non-method functions defined here:
- __doc__ = 'This class is for handling bot commands. An ins... methods\n and should not be accessed directly.'
- __module__ = 'kibot.CommandHandler'
- _ignore_perm = <kibot.PermObjects.cpString instance>
Methods inherited from kibot.BaseModule.BaseModule:
- _del_handlers(self, priority=0, prefix='_on_')
- This "undoes" self._set_handlers
- _get_handlers(self, prefix)
- return a list of all event types for which it looks like
the module has handlers. If the module has defined _on_join and
_on_kick, then this will return ['join', 'kick']
if the attribute self._handlers is defined, it will be returned
instead
- _get_stasher(self, file=None, format=None, **kwargs)
- #_stash_file = 'foo.pickle' # will appear in the "data_dir"
- _set_handlers(self, priority=0, prefix='_on_')
- set handlers for all methods with prefix <prefix>
For example, if the method _on_join is defined, then that method
will be registered as handler for the "join" event.
If the attribute self._handlers is defined, it will be used instead.
each element of the self._handlers list should be the event type.
def _handle_join(self, conn, event): pass
def _handle_kick(self, conn, event): pass
def _handle_part(self, conn, event): pass
self._handlers = ['join', 'kick']
_set_handlers(prefix='_handle_')
In this case, only the first two will be set. If self._handlers
were not defined, then all three would be set.
- _stash(self, default=<class kibot.BaseModule.NoDefault>)
- Store the attributes listed in self._stash_attrs in a stasher.
One will be created if necessary. If a value isn't set and
a default is provided, that value will be used.
- _unstash(self, default=<class kibot.BaseModule.NoDefault>)
- Reload the attributes listed in self._stash_attrs from the
stasher. If the attribute was not in the stasher (or if the file
didn't exist) then the attribute will be set to 'default'. If
default is not provided, then the attribute will not be set at all.
Data and non-method functions inherited from kibot.BaseModule.BaseModule:
- _stash_attrs = []
- _stash_format = 'pickle'
|
class DirectConnectionReply(ReplyObject) |
| |
This is the class for DirectConnection replies. These basically
all do the same thing (write to the direct connection), but with
different prefixes so you can see which method as called. |
| |
Methods defined here:
- msg(self, *args)
- nnotice(self, *args)
- notice(self, *args)
- nreply(self, *args)
- pnotice(self, *args)
- privmsg(self, *args)
- reply = privmsg(self, *args)
Data and non-method functions defined here:
- __doc__ = 'This is the class for DirectConnection replies. ...t prefixes so you can see which method as called.'
- __module__ = 'kibot.CommandHandler'
Methods inherited from ReplyObject:
- __init__(self, **kwargs)
- Args: nick, channel (or None), Connection object
- _get_target_and_message(self, arg_list)
- arg_list should contain either 1 or >1 elements
If >1, the first should be the "target", either a nick or channel.
the other arguments will be joined to form the message
If 1, it is interpreted as the message, and the target will be
chosen based on the nature of the incoming command. If it
was private, the reply will be private if it was public, the
reply will be public.
|
class IRCReply(ReplyObject) |
| |
This is the class for IRC replies to commands. Every Command
object has a reply object. The public methods of this class will
be available as methods of Command instances directly. |
| |
Methods defined here:
- msg(self, *args)
- will _always_ respond privately, even if the command was in
a channel
- nnotice(self, *args)
- same as nreply, but with notice instead of privmsg
- notice(self, *args)
- same as reply/privmsg, but sends an irc notice instead.
Some clients handle notices differently from privmsgs, which
may be good or bad :)
- nreply(self, *args)
- same as reply, but if it's a public response, the user's nick
(the one who typed the command) is prepended
- pnotice(self, *args)
- like msg, but with a notice
- privmsg(self, *args)
- default reply mechanism, if multiple args, first is interpreted
as the target (either nick or channel). Otherwise, reply will
be the same as the command. That is, a publicly-asked command
will get a public response.
the methods reply and privmsg are identical
- reply = privmsg(self, *args)
Data and non-method functions defined here:
- __doc__ = 'This is the class for IRC replies to commands. ...ailable as methods of Command instances directly.'
- __module__ = 'kibot.CommandHandler'
Methods inherited from ReplyObject:
- __init__(self, **kwargs)
- Args: nick, channel (or None), Connection object
- _get_target_and_message(self, arg_list)
- arg_list should contain either 1 or >1 elements
If >1, the first should be the "target", either a nick or channel.
the other arguments will be joined to form the message
If 1, it is interpreted as the message, and the target will be
chosen based on the nature of the incoming command. If it
was private, the reply will be private if it was public, the
reply will be public.
|
class ReplyObject |
| |
Base class for the different reply types. Mostly, this just
provides the _get_target_and_message method
Reply objects are created automatically in CommandHandler._run |
| |
Methods defined here:
- __init__(self, **kwargs)
- Args: nick, channel (or None), Connection object
- _get_target_and_message(self, arg_list)
- arg_list should contain either 1 or >1 elements
If >1, the first should be the "target", either a nick or channel.
the other arguments will be joined to form the message
If 1, it is interpreted as the message, and the target will be
chosen based on the nature of the incoming command. If it
was private, the reply will be private if it was public, the
reply will be public.
Data and non-method functions defined here:
- __doc__ = 'Base class for the different reply types. Mostl...created automatically in CommandHandler._run\n '
- __module__ = 'kibot.CommandHandler'
| |