ib3 package

Module contents

class ib3.Bot(*args, **kwargs)[source]

Bases: irc.bot.SingleServerIRCBot

Basic IRC bot.

Simple subclass of irc.bot.SingleServerIRCBot that sets up lenient UTF-8 encoding handling for inbound messages. This is a nice base to start from when adding other IB3 mixins.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Submodules

ib3.auth module

class ib3.auth.AbstractAuth(server_list, nickname, realname, ident_password, channels=None, username=None, **kwargs)[source]

Bases: ib3.mixins.JoinChannels

Base class for authentication mixins.

__init__(server_list, nickname, realname, ident_password, channels=None, username=None, **kwargs)[source]
Parameters:
  • server_list – List of servers the bot will use.
  • nickname – The bot’s nickname
  • realname – The bot’s realname
  • ident_password – The bot’s password
  • channels – List of channels to join after authenticating
  • username – IRC username (default: nickname)
class ib3.auth.NickServ(*args, **kwargs)[source]

Bases: ib3.auth.AbstractAuth

Authenticate with NickServ before joining channels.

__init__(*args, **kwargs)[source]
Parameters:
  • server_list – List of servers the bot will use.
  • nickname – The bot’s nickname
  • realname – The bot’s realname
  • ident_password – The bot’s password
  • channels – List of channels to join after authenticating
  • username – IRC username (default: nickname)
_handle_privnotice(conn, event)[source]

Handle NOTICE sent directly to user.

Check for messages from NickServ requesting auth, warning of password failures, and acknowledging successful auth.

_handle_welcome(conn, event)[source]

Handle WELCOME message.

Starts authentication handshake by sending NickServ an identify message.

_identify_to_nickserv()[source]

Send NickServ our username and password.

class ib3.auth.SASL(*args, **kwargs)[source]

Bases: ib3.auth.AbstractAuth

Authenticate using SASL before joining channels.

__init__(*args, **kwargs)[source]
Parameters:
  • server_list – List of servers the bot will use.
  • nickname – The bot’s nickname
  • realname – The bot’s realname
  • ident_password – The bot’s password
  • channels – List of channels to join after authenticating
  • username – IRC username (default: nickname)
_handle_authenticate(conn, event)[source]

Handle AUTHENTICATE responses.

_handle_cap(conn, event)[source]

Handle CAP responses.

_handle_connect(sock)[source]

Send CAP REQ :sasl on connect.

_handle_saslmechs(conn, event)[source]

Handle 908 RPL_SASLMECHS responses.

_handle_saslsuccess(conn, event)[source]

Handle 903 RPL_SASLSUCCESS responses.

_handle_welcome(conn, event)[source]

Handle WELCOME message.

ib3.connection module

class ib3.connection.SSL(*args, **kwargs)[source]

Bases: object

Use SSL connections.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

ib3.mixins module

class ib3.mixins.DisconnectOnError(*args, **kwargs)[source]

Bases: object

Handle ERROR message by logging and disconnecting.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class ib3.mixins.JoinChannels[source]

Bases: object

Join channels one at a time to avoid flooding.

join_channels(channels)[source]

Join a list of channels, one at a time.

class ib3.mixins.PingServer(max_pings=2, ping_interval=300, *args, **kwargs)[source]

Bases: object

Add checks for connection liveness using PING commands.

__init__(max_pings=2, ping_interval=300, *args, **kwargs)[source]
Parameters:
  • max_pings – Maximum numer of missed pings to tolerate
  • ping_interval – Seconds between ping attempts
_handle_pong(conn, event)[source]

Clear ping count when a pong is received.

_ping_server()[source]

Send a ping or disconnect if too many pings are outstanding.

class ib3.mixins.RejoinOnBan(*args, **kwargs)[source]

Bases: object

Handle ERR_BANNEDFROMCHAN by attempting to rejoin channel.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class ib3.mixins.RejoinOnKick(*args, **kwargs)[source]

Bases: object

Handle KICK by attempting to rejoin channel.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

ib3.nick module

class ib3.nick.Ghost(server_list, nickname, realname, altnick=None, *args, **kwargs)[source]

Bases: ib3.nick.NicknameInUse

GHOST disconnects an old user session, or somebody attempting to use your nickname without authorization.

This mixin assumes that you are also using a mixin from ib3.auth or another means to authenticate your IRC account.

_recover_nick()[source]

Recover nick by sending GHOST command to NickServ.

class ib3.nick.NicknameInUse(server_list, nickname, realname, altnick=None, *args, **kwargs)[source]

Bases: object

Handle ERR_NICKNAMEINUSE messages by changing to an alternate nick.

__init__(server_list, nickname, realname, altnick=None, *args, **kwargs)[source]
Parameters:
  • server_list – List of servers the bot will use.
  • nickname – The bot’s nickname
  • realname – The bot’s realname
  • altnick – Alternate nickname if primary nick is taken
_handle_nicknameinuse(conn, event)[source]

Handle ERR_NICKNAMEINUSE message.

If failed nick matches our desired nick, switch to secondary nick, and schedule an attempt to reclaim our primary nick.

If failed nick matches our secondary nick, die.

_recover_nick()[source]

Do nothing.

Subclasses can override this method to perform some special action to recover the bot’s primary nickname.

has_primary_nick()[source]

Do we currently have our primary nick?

Return type:bool
class ib3.nick.Regain(server_list, nickname, realname, altnick=None, *args, **kwargs)[source]

Bases: ib3.nick.NicknameInUse

REGAIN disconnects an old user session, or somebody attempting to use your nickname without authorization, then changes your nickname to the given nickname. This may not work, disconnecting you, if the target client reconnects automatically.

This mixin assumes that you are also using a mixin from ib3.auth or another means to authenticate your IRC account.

_recover_nick()[source]

Recover nick by sending REGAIN command to NickServ.