talkomatic.py 0.1.2
An easy-to-use Python versatile wrapper for the Talkomatic Bot interface ensuring best practices for making bots, and handling the REST API.
 
Loading...
Searching...
No Matches
talkomatic.bot.Bot Class Reference

Public Member Functions

None __init__ (self, str command_marker="/", RateLimits rate_limits=DISABLE_RATE_LIMITS, bool debug=False)
 
None run (self, str username, str location, bool create_help_command=False)
 
Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]] command (self, str name, str description="", list[CommandParameter] parameters=[], list[str] aliases=[], bool hidden=False)
 
bool create_room (self, str room_name, RoomType room_type=RoomType.PUBLIC, RoomLayoutType room_layout=RoomLayoutType.VERTICAL, int|None room_password=None)
 
None disconnect (self)
 
Room|None get_room_by_id (self, int id)
 
User|None get_user_by_id (self, str id)
 
str get_user_message (self, User user)
 
bool join_room (self, Room|int room, int|None access_code=None, bool do_api_check=True)
 
None leave_room (self)
 
Binding on_connect (self, Binding binding)
 
Binding on_inactivity_disconnect (self, Binding binding)
 
Binding on_room_creation (self, Binding binding)
 
Binding on_room_join (self, Binding binding)
 
Binding on_room_leave (self, Binding binding)
 
Binding on_user_message (self, Binding binding)
 
Binding on_user_join (self, Binding binding)
 
Binding on_user_leave (self, Binding binding)
 
Binding on_user_vote (self, Binding binding)
 
bool send_message (self, str message)
 
None toggle_vote (self, User user)
 

Public Attributes

 sio = AsyncClient(engineio_logger = debug, logger = debug)
 
 rate_limits = rate_limits
 
 command_marker = command_marker
 
 user = User.from_raw_json(data)
 

Static Public Attributes

Room current_room = None
 
dict commands = {}
 
list rooms = []
 
dict user_database = {}
 
dict user_messages = {}
 
Binding on_connect_binding = None
 
Binding on_inactivity_disconnect_binding = None
 
Binding on_room_creation_binding = None
 
Binding on_room_join_binding = None
 
Binding on_room_leave_binding = None
 
Binding on_user_message_binding = None
 
Binding on_user_join_binding = None
 
Binding on_user_leave_binding = None
 
Binding on_user_vote_binding = None
 

Protected Member Functions

None _run (self, str username, str location)
 
None _chat_update (self, dict data)
 
None _error (self, dict data)
 
None _join_lobby (self, str username, str location)
 
None _lobby_update (self, list[dict] rooms_data)
 
None _signin_status (self, dict data)
 
None _room_join (self, dict data)
 
None _room_update (self, dict data)
 
None _user_join (self, dict data)
 
None _user_leave (self, str data)
 
None _update_votes (self, dict data)
 

Protected Attributes

 _signin_status
 
 _lobby_update
 
 _chat_update
 
 _room_join
 
 _room_update
 
 _user_join
 
 _user_leave
 
 _update_votes
 
 _error
 

Static Protected Attributes

bool _fully_started = False
 
float _time_since_last_message = 0
 
float _time_since_last_room_join = 0
 
float _time_since_last_room_creation = 0
 

Detailed Description

A wrapper class around the socket.io Talkomatic API. This bot uses
an asynchronous socket.io client to optimize for concurrency,
while abstracting error handling, disconnecting, and other low-level
details, to make writing bots easier.

Args:
    username (str): The username of the bot.
    location (str): The location of the bot.
    The bot's name will show up as "username / location".

    Optional:
    rate_limits (RateLimits): The rate limits of the bot. (disabled by default to make
    development easier, consider putting rate limits in to prevent getting blocked by the API)
    debug (bool): Whether to enable debug mode for the internal socket.io
    client. Defaults to False.

Definition at line 16 of file bot.py.

Constructor & Destructor Documentation

◆ __init__()

None talkomatic.bot.Bot.__init__ ( self,
str command_marker = "/",
RateLimits rate_limits = DISABLE_RATE_LIMITS,
bool debug = False )

Definition at line 60 of file bot.py.

Member Function Documentation

◆ _chat_update()

None talkomatic.bot.Bot._chat_update ( self,
dict data )
protected

Definition at line 155 of file bot.py.

◆ _error()

None talkomatic.bot.Bot._error ( self,
dict data )
protected

Definition at line 185 of file bot.py.

◆ _join_lobby()

None talkomatic.bot.Bot._join_lobby ( self,
str username,
str location )
protected

Definition at line 195 of file bot.py.

◆ _lobby_update()

None talkomatic.bot.Bot._lobby_update ( self,
list[dict] rooms_data )
protected

Definition at line 201 of file bot.py.

◆ _room_join()

None talkomatic.bot.Bot._room_join ( self,
dict data )
protected

Definition at line 214 of file bot.py.

◆ _room_update()

None talkomatic.bot.Bot._room_update ( self,
dict data )
protected

Definition at line 226 of file bot.py.

◆ _run()

None talkomatic.bot.Bot._run ( self,
str username,
str location )
protected

Definition at line 116 of file bot.py.

◆ _signin_status()

None talkomatic.bot.Bot._signin_status ( self,
dict data )
protected

Definition at line 211 of file bot.py.

◆ _update_votes()

None talkomatic.bot.Bot._update_votes ( self,
dict data )
protected

Definition at line 251 of file bot.py.

◆ _user_join()

None talkomatic.bot.Bot._user_join ( self,
dict data )
protected

Definition at line 229 of file bot.py.

◆ _user_leave()

None talkomatic.bot.Bot._user_leave ( self,
str data )
protected

Definition at line 240 of file bot.py.

◆ command()

Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]] talkomatic.bot.Bot.command ( self,
str name,
str description = "",
list[CommandParameter] parameters = [],
list[str] aliases = [],
bool hidden = False )
Decorator for registering commands.

Args:
    name (str): The name of the command.
    description (str): The description of the command.
    parameters (list[CommandParameter]): The parameters of the command.
    aliases (list[str]): The aliases of the command.
    hidden (bool): Whether the command will show up in the built-in /help command.

Definition at line 293 of file bot.py.

◆ create_room()

bool talkomatic.bot.Bot.create_room ( self,
str room_name,
RoomType room_type = RoomType.PUBLIC,
RoomLayoutType room_layout = RoomLayoutType.VERTICAL,
int | None room_password = None )
Creates a room with the given name, type, layout, and password.

Args:
    room_name (str): The name of the room.
    room_type (RoomType): The type of the room.
    room_layout (RoomLayoutType): The layout of the room.
    room_password (int, **must be 6 digits**): The password of the room (if the room is not public).

Returns:
    bool: Whether the room was created successfully (returns False if the room was
    not created due to rate limits).

Definition at line 329 of file bot.py.

◆ disconnect()

None talkomatic.bot.Bot.disconnect ( self)
Disconnects the bot from the server.

Definition at line 360 of file bot.py.

◆ get_room_by_id()

Room | None talkomatic.bot.Bot.get_room_by_id ( self,
int id )
Gets a room by its ID.
Returns None if the room does not exist.

Args:
    id (int): The ID of the room to get.

Returns:
    Room: The room object. (None if the room does not exist)

Definition at line 367 of file bot.py.

◆ get_user_by_id()

User | None talkomatic.bot.Bot.get_user_by_id ( self,
str id )
Allows you to get a user from the user database by their ID.
Useful for getting a user from a "id-only" user, but is not
guaranteed to work if the user is not in a room anymore.

Args:
    id (str): The ID of the user to get.

Returns:
    User: The full user object. (None if the user is not in the database)

Definition at line 384 of file bot.py.

◆ get_user_message()

str talkomatic.bot.Bot.get_user_message ( self,
User user )
Gets the message of a user.

Args:
    user (User): The user to get the message of.

Returns:
    str: The message of the user.

Definition at line 399 of file bot.py.

◆ join_room()

bool talkomatic.bot.Bot.join_room ( self,
Room | int room,
int | None access_code = None,
bool do_api_check = True )
Joins a room with the given room/room ID and access code.
**Reminder: your bot can only be in 1 room at a time!**

Args:
    room (Room | int): The room (or ID of the room) to join.
    access_code (int | None): The 6 digit access code of the room to join (if the room is not public).
    do_api_check (bool): Whether to check if the room can be joined using the Talkomatic API.

Returns:
    bool: Whether the room was joined successfully (returns False if the room was
    not joined due to rate limits).

Definition at line 412 of file bot.py.

◆ leave_room()

None talkomatic.bot.Bot.leave_room ( self)
Leaves the room the bot is currently in.

Definition at line 446 of file bot.py.

◆ on_connect()

Binding talkomatic.bot.Bot.on_connect ( self,
Binding binding )
Binds a function to when the bot finishes connection to the server.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 453 of file bot.py.

◆ on_inactivity_disconnect()

Binding talkomatic.bot.Bot.on_inactivity_disconnect ( self,
Binding binding )
Binds a function to when the bot is disconnected due to having not interacted for too long.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 464 of file bot.py.

◆ on_room_creation()

Binding talkomatic.bot.Bot.on_room_creation ( self,
Binding binding )
Binds a function to when the bot has successfully created the room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 475 of file bot.py.

◆ on_room_join()

Binding talkomatic.bot.Bot.on_room_join ( self,
Binding binding )
Binds a function to when the bot has successfully joined the room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 486 of file bot.py.

◆ on_room_leave()

Binding talkomatic.bot.Bot.on_room_leave ( self,
Binding binding )
Binds a function to when the bot has successfully left the room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 497 of file bot.py.

◆ on_user_join()

Binding talkomatic.bot.Bot.on_user_join ( self,
Binding binding )
Binds a function to when another user has joined the bot's current room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 519 of file bot.py.

◆ on_user_leave()

Binding talkomatic.bot.Bot.on_user_leave ( self,
Binding binding )
Binds a function to when a user has left the bot's current room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 530 of file bot.py.

◆ on_user_message()

Binding talkomatic.bot.Bot.on_user_message ( self,
Binding binding )
Binds a function to when a user sent a message in the bot's current room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 508 of file bot.py.

◆ on_user_vote()

Binding talkomatic.bot.Bot.on_user_vote ( self,
Binding binding )
Binds a function to when a user has voted to a ban another user from the bot's current room.

Args:
    binding (Coroutine): The function to bind to the event.

Definition at line 541 of file bot.py.

◆ run()

None talkomatic.bot.Bot.run ( self,
str username,
str location,
bool create_help_command = False )
Runs the bot.

Args:
    username (str): The username of the bot.
    location (str): The location of the bot.

Definition at line 65 of file bot.py.

◆ send_message()

bool talkomatic.bot.Bot.send_message ( self,
str message )
Sends the message to the room the bot is currently in.

Args:
    message (str): The message to send.

Returns:
    bool: Whether the message was sent successfully (returns False if the message was
    not sent due to rate limits).

Definition at line 552 of file bot.py.

◆ toggle_vote()

None talkomatic.bot.Bot.toggle_vote ( self,
User user )
Votes the user to be banned (or remove vote if the user is already voted by the bot)
from the room the bot is currently in.

Args:
    user (User): The user to vote for.

Definition at line 577 of file bot.py.

Member Data Documentation

◆ _chat_update

talkomatic.bot.Bot._chat_update
protected

Definition at line 137 of file bot.py.

◆ _error

talkomatic.bot.Bot._error
protected

Definition at line 145 of file bot.py.

◆ _fully_started

bool talkomatic.bot.Bot._fully_started = False
staticprotected

Definition at line 44 of file bot.py.

◆ _lobby_update

talkomatic.bot.Bot._lobby_update
protected

Definition at line 136 of file bot.py.

◆ _room_join

talkomatic.bot.Bot._room_join
protected

Definition at line 140 of file bot.py.

◆ _room_update

talkomatic.bot.Bot._room_update
protected

Definition at line 141 of file bot.py.

◆ _signin_status

talkomatic.bot.Bot._signin_status
protected

Definition at line 121 of file bot.py.

◆ _time_since_last_message

float talkomatic.bot.Bot._time_since_last_message = 0
staticprotected

Definition at line 56 of file bot.py.

◆ _time_since_last_room_creation

float talkomatic.bot.Bot._time_since_last_room_creation = 0
staticprotected

Definition at line 58 of file bot.py.

◆ _time_since_last_room_join

float talkomatic.bot.Bot._time_since_last_room_join = 0
staticprotected

Definition at line 57 of file bot.py.

◆ _update_votes

talkomatic.bot.Bot._update_votes
protected

Definition at line 144 of file bot.py.

◆ _user_join

talkomatic.bot.Bot._user_join
protected

Definition at line 142 of file bot.py.

◆ _user_leave

talkomatic.bot.Bot._user_leave
protected

Definition at line 143 of file bot.py.

◆ command_marker

talkomatic.bot.Bot.command_marker = command_marker

Definition at line 63 of file bot.py.

◆ commands

dict talkomatic.bot.Bot.commands = {}
static

Definition at line 39 of file bot.py.

◆ current_room

talkomatic.bot.Bot.current_room = None
static

Definition at line 38 of file bot.py.

◆ on_connect_binding

talkomatic.bot.Bot.on_connect_binding = None
static

Definition at line 46 of file bot.py.

◆ on_inactivity_disconnect_binding

Binding talkomatic.bot.Bot.on_inactivity_disconnect_binding = None
static

Definition at line 47 of file bot.py.

◆ on_room_creation_binding

talkomatic.bot.Bot.on_room_creation_binding = None
static

Definition at line 48 of file bot.py.

◆ on_room_join_binding

Binding talkomatic.bot.Bot.on_room_join_binding = None
static

Definition at line 49 of file bot.py.

◆ on_room_leave_binding

Binding talkomatic.bot.Bot.on_room_leave_binding = None
static

Definition at line 50 of file bot.py.

◆ on_user_join_binding

Binding talkomatic.bot.Bot.on_user_join_binding = None
static

Definition at line 52 of file bot.py.

◆ on_user_leave_binding

Binding talkomatic.bot.Bot.on_user_leave_binding = None
static

Definition at line 53 of file bot.py.

◆ on_user_message_binding

Binding talkomatic.bot.Bot.on_user_message_binding = None
static

Definition at line 51 of file bot.py.

◆ on_user_vote_binding

Binding talkomatic.bot.Bot.on_user_vote_binding = None
static

Definition at line 54 of file bot.py.

◆ rate_limits

talkomatic.bot.Bot.rate_limits = rate_limits

Definition at line 62 of file bot.py.

◆ rooms

list talkomatic.bot.Bot.rooms = []
static

Definition at line 41 of file bot.py.

◆ sio

talkomatic.bot.Bot.sio = AsyncClient(engineio_logger = debug, logger = debug)

Definition at line 61 of file bot.py.

◆ user

talkomatic.bot.Bot.user = User.from_raw_json(data)

Definition at line 212 of file bot.py.

◆ user_database

dict talkomatic.bot.Bot.user_database = {}
static

Definition at line 42 of file bot.py.

◆ user_messages

dict talkomatic.bot.Bot.user_messages = {}
static

Definition at line 43 of file bot.py.


The documentation for this class was generated from the following file: