fatbotslim.irc.bot

This module contains IRC protocol related stuff.

class fatbotslim.irc.bot.IRC(settings)[source]

The main IRC bot class.

The only expected argument is the bot’s configuration, it should be a dict with at least the following keys defined:

  • server: the ircd’s host (str)
  • port: the ircd’s port (int)
  • ssl: connect to the server using SSL (bool)
  • channels: the channels to join upon connection (list)
  • nick: the bot’s nickname (str)
  • realname: the bot’s real name (str)
Parameters:settings (dict) – bot configuration.
add_handler(handler, args=None, kwargs=None)[source]

Registers a new handler.

Parameters:
  • handler (fatbotslim.handlers.BaseHandler) – handler to register.
  • args (list) – positional arguments to pass to the handler’s constructor.
  • kwargs (dict) – keyword arguments to pass to the handler’s constructor.
cmd(command, args, prefix=None)[source]

Sends a command to the server.

Parameters:
  • command (unicode) – IRC code to send.
  • args (basestring) – arguments to pass with the command.
  • prefix (str or None) – optional prefix to prepend to the command.
ctcp_reply(command, dst, message=None)[source]

Sends a reply to a CTCP request.

Parameters:
  • command (str) – CTCP command to use.
  • dst (str) – sender of the initial request.
  • message (str) – data to attach to the reply.
disable_rights()[source]

Disables rights management provided by fatbotslim.handlers.RightsHandler.

disconnect()[source]

Disconnects the bot from the server.

enable_rights()[source]

Enables rights management provided by fatbotslim.handlers.RightsHandler.

join(channel)[source]

Make the bot join a channel.

Parameters:channel (str) – new channel to join.
msg(target, msg)[source]

Sends a message to an user or channel.

Parameters:
  • target (str) – user or channel to send to.
  • msg (str) – message to send.
notice(target, msg)[source]

Sends a NOTICE to an user or channel.

Parameters:
  • target (str) – user or channel to send to.
  • msg (basestring) – message to send.
classmethod randomize_nick(base, suffix_length=3)[source]

Generates a pseudo-random nickname.

Parameters:
  • base (unicode) – prefix to use for the generated nickname.
  • suffix_length (int) – amount of digits to append to base
Returns:

generated nickname.

Return type:

unicode

run()[source]

Connects the bot and starts the event loop.

set_nick(nick)[source]

Changes the bot’s nickname.

Parameters:nick (unicode) – new nickname to use
class fatbotslim.irc.bot.Message(data)[source]

Holds informations about a line received from the server.

Parameters:data (unicode) – line received from the server.
classmethod parse(data)[source]

Extracts message informations from data.

Parameters:data (unicode) – received line.
Returns:extracted informations (source, destination, command, args).
Return type:tuple(Source, str, str, list)
Raise:fatbotslim.irc.NullMessage if data is empty.
exception fatbotslim.irc.bot.NullMessage[source]

Raised when an empty line is received from the server.

class fatbotslim.irc.bot.Source(prefix)[source]

Holds informations about a message sender.

Parameters:prefix (unicode) – prefix with format <servername>|<nick>['!'<user>]['@'<host>].
classmethod parse(prefix)[source]

Extracts informations from prefix.

Parameters:prefix (unicode) – prefix with format <servername>|<nick>['!'<user>]['@'<host>].
Returns:extracted informations (nickname or host, mode, username, host).
Return type:tuple(str, str, str, str)
fatbotslim.irc.bot.run_bots(bots)[source]

Run many bots in parallel.

Parameters:bots (list) – IRC bots to run.