errbot.backends.irc module

class errbot.backends.irc.IRCBackend(config)[source]

Bases: ErrBot

__init__(config)[source]

Those arguments will be directly those put in BOT_IDENTITY

aclpattern = '{nick}!{user}@{host}'
build_identifier(txtrep: str) IRCRoom | IRCRoomOccupant | IRCPerson[source]
build_message(text: str) Message[source]

You might want to override this one depending on your backend

build_reply(msg: Message, text: str | None = None, private: bool = False, threaded: str = False) Message[source]

Should be implemented by the backend

change_presence(status: str = 'online', message: str = '') None[source]

Signal a presence change for the bot. Should be overridden by backends with a super().send_message() call.

connect() IRCConnection[source]

Connects the bot to server or returns current connection

property mode: str
prefix_groupchat_reply(message: Message, identifier: Identifier)[source]

Patches message with the conventional prefix to ping the specific contact For example: @gbin, you forgot the milk !

query_room(room: IRCRoom) IRCRoom[source]

Query a room for information.

Return type:

IRCRoom

Parameters:

room (IRCRoom) – The channel name to query for.

Returns:

An instance of IRCMUCRoom.

rooms() List[IRCRoom][source]

Return a list of rooms the bot is currently in.

Returns:

A list of IRCMUCRoom instances.

send_message(msg: Message) None[source]

This needs to be overridden by the backends with a super() call.

Parameters:

msg (Message) – the message to send.

Returns:

None

send_stream_request(identifier: Identifier, fsource: BinaryIO, name: str | None = None, size: int | None = None, stream_type: str | None = None) Stream[source]
serve_forever() None[source]

Connect the back-end to the server and serve forever.

Back-ends MAY choose to re-implement this method, in which case they are responsible for implementing reconnection logic themselves.

Back-ends SHOULD trigger connect_callback() and disconnect_callback() themselves after connection/disconnection.

set_message_size_limit(limit: int = 510, hard_limit: int = 510) None[source]

IRC message size limit

shutdown() None[source]
class errbot.backends.irc.IRCConnection(bot, nickname, server, port=6667, ssl=False, bind_address=None, ipv6=False, password=None, username=None, nickserv_password=None, private_rate=1, channel_rate=1, reconnect_on_kick=5, reconnect_on_disconnect=5)[source]

Bases: SingleServerIRCBot

__init__(bot, nickname, server, port=6667, ssl=False, bind_address=None, ipv6=False, password=None, username=None, nickserv_password=None, private_rate=1, channel_rate=1, reconnect_on_kick=5, reconnect_on_disconnect=5)[source]
away(message: str | None = '') None[source]

Extend the original implementation to support AWAY. To set an away message, set message to something. To cancel an away message, leave message at empty string.

connect(*args, **kwargs) None[source]

Connect using the underlying connection

on_currenttopic(connection: ServerConnection, event: Event) None[source]

When you Join a room with a topic set this event fires up to with the topic information. If the room that you join don’t have a topic set, nothing happens. Here is NOT the place to fire the callback_room_topic() event for that case exist on_topic.

Parameters:
  • connection (ServerConnection) – Is an ‘irc.client.ServerConnection’ object

  • event (Event) – Is an ‘irc.client.Event’ object The event.arguments[0] contains the room name The event.arguments[1] contains the topic of the room.

on_dcc_connect(dcc, event) None[source]
on_dcc_disconnect(dcc, event)[source]
on_dccmsg(dcc, event)[source]
on_disconnect(connection, event) None[source]
on_endofnames(connection: ServerConnection, event: Event) None[source]

Handler of the enfofnames IRC message/event.

The endofnames message is sent to the client when the server finish to send the list of names of the room ocuppants. This usually happens when you join to the room. So in this case, we use this event to determine that our bot is finally joined to the room.

Parameters:
  • connection (ServerConnection) – Is an ‘irc.client.ServerConnection’ object

  • event (Event) – Is an ‘irc.client.Event’ object the event.arguments[0] contains the channel name

on_join(connection: ServerConnection, event: Event) None[source]

Handler of the join IRC message/event. Is in response of a /JOIN client message.

Parameters:
  • connection (ServerConnection) – Is an ‘irc.client.ServerConnection’ object

  • event (Event) – Is an ‘irc.client.Event’ object the event.target contains the channel name

on_kick(_, e) None[source]
on_notopic(connection: ServerConnection, event: Event) None[source]

This event fires ip when there is no topic set on a room

Parameters:
  • connection (ServerConnection) – Is an ‘irc.client.ServerConnection’ object

  • event (Event) – Is an ‘irc.client.Event’ object The event.arguments[0] contains the room name

on_part(connection: ServerConnection, event: Event) None[source]

Handler of the part IRC Message/event.

The part message is sent to the client as a confirmation of a /PART command sent by someone in the room/channel. If the event.source contains the bot nickname then we need to fire the callback_room_left() event on the bot.

Parameters:
  • connection (ServerConnection) – Is an ‘irc.client.ServerConnection’ object

  • event (Event) – Is an ‘irc.client.Event’ object The event.source contains the nickmask of the user that leave the room The event.target contains the channel name

on_privmsg(_, e) None[source]
on_privnotice(_, e) None[source]
on_pubmsg(_, e) None[source]
on_pubnotice(_, e) None[source]
on_topic(connection: ServerConnection, event: Event) None[source]

On response to the /TOPIC command if the room have a topic. If the room don’t have a topic the event fired is on_notopic :type event: Event :type connection: ServerConnection :param connection: Is an ‘irc.client.ServerConnection’ object

Parameters:

event – Is an ‘irc.client.Event’ object The event.target contains the room name. The event.arguments[0] contains the topic name

on_welcome(_, e) None[source]
static send_chunk(stream, dcc)[source]
send_private_message(to, line: str) None[source]
send_public_message(to, line: str) None[source]
send_stream_request(identifier: Identifier, fsource: BinaryIO, name: str | None = None, size: int | None = None, stream_type: str | None = None) Stream[source]
class errbot.backends.irc.IRCPerson(mask)[source]

Bases: Person

__init__(mask)[source]
property aclattr
Returns:

returns the unique identifier that will be used for ACL matches.

property client
Returns:

a backend specific unique identifier representing the device or client the person is using to talk.

property email: str

Some backends have the email of a user.

Returns:

the email of this user if available.

property fullname: None

Some backends have the full name of a user.

Returns:

the fullname of this user if available.

property host: str
property nick: str
Returns:

a backend specific nick returning the nickname of this person if available.

property person: str
Returns:

a backend specific unique identifier representing the person you are talking to.

property user: str
class errbot.backends.irc.IRCRoom(room: Room, bot)[source]

Bases: Room

Represent the specifics of a IRC Room/Channel.

This lifecycle of this object is:
  • Created in IRCConnection.on_join

  • The joined status change in IRCConnection on_join/on_part

  • Deleted/destroyed in IRCConnection.on_disconnect

__init__(room: Room, bot)[source]
cb_set_topic(current_topic: str) None[source]

Store the current topic for this room.

This method is called by the IRC backend when a currenttopic, topic or notopic IRC event is received to store the topic set for this channel.

This function is not meant to be executed by regular plugins. To get or set

create() None[source]

Not supported on this back-end. Will join the room to ensure it exists, instead.

destroy() None[source]

Not supported on IRC, will raise RoomError.

property exists: bool

Boolean indicating whether this room already exists or not.

Getter:

Returns True if the room exists, False otherwise.

invite(*args) None[source]

Invite one or more people into the room.

Parameters:

*args – One or more nicks to invite into the room.

join(username: Any = None, password: str | None = None) None[source]

Join the room.

If the room does not exist yet, this will automatically call create() on it first.

property joined: bool

Boolean indicating whether this room has already been joined.

Getter:

Returns True if the room has been joined, False otherwise.

leave(reason: str | None = None) None[source]

Leave the room.

Parameters:

reason – An optional string explaining the reason for leaving the room

property occupants: List[IRCRoomOccupant]

The room’s occupants.

Getter:

Returns a list of occupants. :raises: MUCNotJoinedError if the room has not yet been joined.

property topic: str | None

The room topic.

Getter:

Returns the topic (a string) if one is set, None if no topic has been set at all.

class errbot.backends.irc.IRCRoomOccupant(mask, room)[source]

Bases: IRCPerson, RoomOccupant

__init__(mask, room)[source]
property room: Room

Some backends have the full name of a user.

Returns:

the fullname of this user if available.

errbot.backends.irc.irc_md() Markdown[source]

This makes a converter from markdown to mirc color format.