errbot.backends.text module

class errbot.backends.text.TextBackend(config)[source]

Bases: ErrBot

__init__(config)[source]

Those arguments will be directly those put in BOT_IDENTITY

add_reaction(msg: Message, reaction: str) None[source]
build_identifier(text_representation: str) TextOccupant | TextRoom | TextPerson[source]
build_reply(msg: Message, text: str = None, private: bool = False, threaded: bool = 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.

property mode
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: str) TextRoom[source]

Query a room for information.

Return type:

TextRoom

Parameters:

room (str) – The room to query for.

Returns:

An instance of Room.

readline_support() None[source]
remove_reaction(msg: Message, reaction: str) None[source]
rooms() List[TextRoom][source]

Return a list of rooms the bot is currently in.

Returns:

A list of Room 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(user: Identifier, fsource: BinaryIO, name: str = None, size: int = None, stream_type: str = None) Stream[source]

Starts a file transfer. For Slack, the size and stream_type are unsupported

Return type:

Stream

Parameters:
  • user (Identifier) – is the identifier of the person you want to send it to.

  • fsource (BinaryIO) – is a file object you want to send.

  • name (str) – is an optional filename for it.

  • size (int) – not supported in Slack backend

  • stream_type (str) – not supported in Slack backend

Return Stream:

object on which you can monitor the progress of it.

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.

class errbot.backends.text.TextOccupant(person, room)[source]

Bases: TextPerson, RoomOccupant

__init__(person, room)[source]
property room: TextRoom

Some backends have the full name of a user.

Returns:

the fullname of this user if available.

class errbot.backends.text.TextPerson(person, client=None, nick=None, fullname=None)[source]

Bases: Person

Simple Person implementation which represents users as simple text strings.

__init__(person, client=None, nick=None, fullname=None)[source]
property aclattr: str
Returns:

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

property client: str
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: str

Some backends have the full name of a user.

Returns:

the fullname of this user if available.

property nick: str
Returns:

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

property person: Person
Returns:

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

class errbot.backends.text.TextRoom(name: str, bot: ErrBot)[source]

Bases: Room

__init__(name: str, bot: ErrBot)[source]
create() None[source]

Create the room.

Calling this on an already existing room is a no-op.

destroy() None[source]

Destroy the room.

Calling this on a non-existing room is a no-op.

property exists: bool

Boolean indicating whether this room already exists or not.

Getter:

Returns True if the room exists, False otherwise.

invite(*args)[source]

Invite one or more people into the room.

Parameters:

*args

One or more identifiers to invite into the room.

join(username: str | None = 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[TextOccupant]

The room’s occupants.

Getter:

Returns a list of occupant identities.

Raises:

MUCNotJoinedError if the room has not yet been joined.

property topic: str

The room topic.

Getter:

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

Note

Back-ends may return an empty string rather than None when no topic has been set as a network may not differentiate between no topic and an empty topic.

Raises:

MUCNotJoinedError if the room has not yet been joined.

errbot.backends.text.borderless_ansi() Markdown[source]

This makes a converter from markdown to ansi (console) format. It can be called like this: from errbot.rendering import ansi md_converter = ansi() # you need to cache the converter

ansi_txt = md_converter.convert(md_txt)