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
config.py
Go to the documentation of this file.
1from talkomatic.api.v1.auth import get_auth_bot_token
2
3from requests import get as requests_get
4
5from dataclasses import dataclass
6
7
8@dataclass
10 """
11 A class representing the Talkomatic server configuration.
12
13 Composed of:
14 - max_username_length: The maximum length of a username.
15 - max_afk_time: The maximum time for inactivity before the user gets kicked (in milliseconds).
16 - max_location_length: The maximum length of a location.
17 - max_room_name_length: The maximum length of a room name.
18 - max_message_length: The maximum length of a message.
19 - max_room_capacity: The maximum number of users in a room.
20 - max_connections_per_ip: The maximum number of connections per IP.
21 - socket_max_requests_window: The maximum number of requests per window.
22 - socket_max_requests_per_window: The maximum number of requests per window.
23 - chat_update_rate_limit: The maximum number of chat updates per minute.
24 - typing_rate_limit: The maximum number of typing updates per minute.
25 - connection_delay: The delay in milliseconds between a user connecting and the first chat update.
26 - word_filter_enabled: Whether the word filter is enabled.
27 - api_version: The version of the API.
28 - server_version: The version of the server.
29 """
30
31 max_username_length: int
32 max_afk_time: int
33 max_location_length: int
34 max_room_name_length: int
35 max_message_length: int
36 max_room_capacity: int
37 max_connections_per_ip: int
38 socket_max_requests_window: int
39 socket_max_requests_per_window: int
40 chat_update_rate_limit: int
41 typing_rate_limit: int
42 connection_delay: int
43 word_filter_enabled: bool
44 api_version: str
45 server_version: str
46
47 @classmethod
48 def get(cls) -> "ServerConfig":
49 response = requests_get(f"https://classic.talkomatic.co/api/v1/config?token={get_auth_bot_token()}")
50 if response.status_code != 200: raise RuntimeError("The talkomatic.co server is down.")
51 data = response.json()
52 limits = data["limits"]
53 features = data["features"]
54 versions = data["versions"]
55
56 return cls(
57 max_username_length = limits["MAX_USERNAME_LENGTH"],
58 max_afk_time = limits["MAX_AFK_TIME"],
59 max_location_length = limits["MAX_LOCATION_LENGTH"],
60 max_room_name_length = limits["MAX_ROOM_NAME_LENGTH"],
61 max_message_length = limits["MAX_MESSAGE_LENGTH"],
62 max_room_capacity = limits["MAX_ROOM_CAPACITY"],
63 max_connections_per_ip = limits["MAX_CONNECTIONS_PER_IP"],
64 socket_max_requests_window = limits["SOCKET_MAX_REQUESTS_WINDOW"],
65 socket_max_requests_per_window = limits["SOCKET_MAX_REQUESTS_PER_WINDOW"],
66 chat_update_rate_limit = limits["CHAT_UPDATE_RATE_LIMIT"],
67 typing_rate_limit = limits["TYPING_RATE_LIMIT"],
68 connection_delay = limits["CONNECTION_DELAY"],
69 word_filter_enabled = features["ENABLE_WORD_FILTER"],
70 api_version = versions["API"],
71 server_version = versions["SERVER"]
72 )
73
74__all__ = ["ServerConfig"]