fatbotslim.handlers

This module contains a collection of handlers to react to basic IRC events and allow creation of custom handlers.

class fatbotslim.handlers.BaseHandler(irc)[source]

The base of every handler.

A handler should at least have a commands attribute of type dict which maps IRC codes (as defined in fatbotslim.irc.codes) to methods.

Mapped methods take 1 argument, the fatbotslim.irc.bot.Message object that triggered the event.

class fatbotslim.handlers.CommandHandler(irc)[source]

The CommandHandler is a special kind of handler that eases the creation of bots that react to prefixed commands (like !command). It only reacts to PRIVMSG and NOTICE messages.

The prefix character is defined by the handler’s trigger_char attribute, and defaults to !.

Commands are defined in the handler’s triggers attribute, a dict that maps method names to events to which they should react. Possible events are EVT_PUBLIC, EVT_PRIVATE, and EVT_NOTICE. The methods should take 1 argument, which is the fatbotslim.irc.bot.Message object that triggered the event.

For example, the message !foo bar would call the handler’s foo() method.

Here is a command handler that says hello when it receives !hello in public:

class HelloCommand(CommandHandler):
    triggers = {
        'hello': [EVT_PUBLIC],
    }
    def hello(self, msg):
        self.irc.msg(msg.dst, "Hello, {0}!".format(msg.src.name))
class fatbotslim.handlers.PingHandler(irc)[source]

Answers to PINGs sent by the server. (enabled by default)

class fatbotslim.handlers.CTCPHandler(irc)[source]

Reacts to CTCP events (VERSION,SOURCE,TIME,PING). (enabled by default)

class fatbotslim.handlers.UnknownCodeHandler(irc)[source]

Logs messages for which the IRC code is unknown. (enabled by default)

class fatbotslim.handlers.HelpHandler(irc)[source]

Provides automatic help messages for fatbotslim.handlers.CommandHandler commands.

help(msg)[source]

help [command] - displays available commands, or help message for given command

class fatbotslim.handlers.RightsHandler(irc)[source]

Provides rights management for fatbotslim.handlers.CommandHandler commands.

del_restriction(command, user, event_types)[source]

Removes restriction for given command.

Parameters:
  • command (str) – command on which the restriction should be removed.
  • user (str) – username for which restriction should be removed.
  • event_types (list) – types of events that should be removed from restriction.
handle_rights(msg)[source]

Catch-all command that is called whenever a restricted command is triggered.

Parameters:msg (fatbotslim.irc.Message) – message that triggered the command.
set_restriction(command, user, event_types)[source]

Adds restriction for given command.

Parameters:
  • command (str) – command on which the restriction should be set.
  • user (str) – username for which the restriction applies.
  • event_types (list) – types of events for which the command is allowed.