API Reference¶
The following docs outline the classes involved in backtracked.
Client¶
-
class
backtracked.Client(**kwargs)[source]¶ The client class is the main class you should be using to communicate with the QueUp API. It provides methods for handling events and non-room-specific functions.
All parameters are optional.
- Parameters
connector (
aiohttp.BaseConnector) – A custom aiohttp connector may be passed if desired. This is to allow proxying.proxy_options (
ProxyOptions) – Proxy options, if proxying is required.recent_conversations (bool) – If True, calls
Client.fetch_conversations()after you have logged in. Defaults to True.
-
user¶ The logged-in user. Populated after a successful login call, None otherwise.
- Type
-
rooms¶ Cached rooms that the bot has joined at least once this session.
- Type
RoomCollection
-
users¶ Cached users the bot has seen.
- Type
Collection
-
messages¶ Messages received during this session.
- Type
MessageCollection
-
await
fetch_conversations()[source]¶ Fetch currently open conversations from QueUp.
This method is called automatically if the parameter recent_conversations is True when initializing this
Client.
-
await
join_room(room_slug: str) → backtracked.models.room.Room[source]¶ Join a QueUp room via its URL slug.
Data Classes¶
These classes should never be constructed. They are given to you in the various events and methods in the library.
Important
Creating the data classes yourself will result in pain and suffering.
Room¶
-
class
backtracked.Room(client, data: dict)[source]¶ Represents a room on QueUp that may or may not be currently joined.
-
music_type¶ Music type for this room.
-
User¶
-
class
backtracked.User(client, data: dict)[source]¶ Represents a specific user on QueUp.
-
created_at¶ Datetime representing the date when this user created their account.
- Type
-
member_of(room)[source]¶ Returns the
Memberobject of this user in the givenRoom. May be None if the member hasn’t yet been backfilled.
-
Member¶
-
class
backtracked.Member(client, data: dict)[source]¶ Represents a QueUp user’s data from a specific
Room. This does not subclassUser, as QueUp itself does not count them as the same entity. Instead, the user getter should be used for retrieving the associated user.No idea tbh
- Type
-
banned_time¶ Datetime representing the time this member was banned. Useless if banned is False.
- Type
-
banned_until¶ Datetime representing the time this member will be unbanned. Useless if banned is False.
- Type
-
role¶ Get this user’s assigned role, or None if the user has no role.
- Returns
Assigned role of this member.
- Return type
AuthenticatedUser¶
Message¶
-
class
backtracked.Message(client, data: dict)[source]¶ Represents a sent message on QueUp.
-
created_at¶ Datetime representing the time this message was sent.
- Type
Get the author of this message.
- Returns
Author of this message
- Return type
-
member¶ Get the author of this message as a member of the room.
- Returns
Member who sent this message.
- Return type
-
Conversation¶
-
class
backtracked.Conversation(client, data: dict)[source]¶ Represents a private conversation between two users.
-
created_at¶ Time this conversation was started.
- Type
-
latest_message_str¶ Text of the last message to be sent in this conversation. May not be up-to-date unless
fetch()is called.- Type
-
has_read(user: backtracked.models.user.User) → bool[source]¶ Checks if the passed
Userhas read this conversation.
-
Song¶
-
class
backtracked.Song(client, data: dict)[source]¶ Represents a song on QueUp that will play, is playing, or has played in the past.
-
created_at¶ Datetime representing the time this song was added.
- Type
-
played_at¶ Datetime representing the time this song was played.
- Type
-
length¶ Length of this song’s assigned media in milliseconds. You can use
backtracked.utils.song_length()to convert this to a human-readable string.- Type
-
room¶ Get the room this playlist entry was added to.
- Returns
Room this song exists in.
- Return type
-
song_info¶ Get the media information object for this song.
- Returns
Media information object for this playlist entry.
- Return type
-
SongInfo¶
-
class
backtracked.SongInfo(data: dict)[source]¶ Represents a specific media from a specific media source.
-
created_at¶ Datetime representing the time this media was created at the source.
- Type
-
length¶ Length of this media in milliseconds. You can use
backtracked.utils.song_length()to convert this to a human-readable string.- Type
-
Helper Classes¶
These classes can be created by the user, and are used for supplying information to certain methods.
ProxyOptions¶
-
class
backtracked.ProxyOptions(proxy_url: str, client_request: Optional[aiohttp.client_reqrep.ClientRequest] = None)[source]¶ Used to pass proxy options to the HTTP and WebSocket clients.
- Parameters
Examples
aiosocks socks4 proxy example:
from backtracked import Client, ProxyOptions from aiosocks import connector proxy_opts = ProxyOptions("socks4://127.0.0.1:1080", client_request=connector.ProxyClientRequest) c = Client(connector=connector.ProxyConnector(), proxy_options=proxy_opts) @c.event async def on_ready(): print("Logged in as {0.username}".format(c.user)) c.run("email", "password")
Enums¶
Classes here extend python’s builtin Enum class. Some attributes use these objects, and some parameters take these objects.
Presence¶
Utilities¶
The utils module contains several helper functions useful for converting and extracting information from various sources.
-
backtracked.utils.dt(msts: int) → datetime.datetime[source]¶ Converts a JavaScript-style timestamp (milliseconds) to a Python datetime.
- Parameters
msts (int) – Timestamp to convert
- Returns
Python datetime representing the passed date
- Return type
-
backtracked.utils.get(iterable: collections.abc.Iterable, **attrs)[source]¶ Finds the first object in an iterable that has all attributes present and equal to their value
- Parameters
iterable (
Iterable) – Iterable of objects to checkattrs (kwargs) – Key-value pairs of attributes to check against
- Returns
First element in the iterable that has all the required attributes
- Return type
-
backtracked.utils.song_length(length: int, format='%M:%S')[source]¶ Convert a song length in milliseconds to a human-readable format, e.g. 03:54.
- Parameters
length (int) – Length in milliseconds to convert
format (str) – Optional custom format, to change the output. Passed to
datetime.datetime.strftime().
- Returns
String representing the length of time according to the format string.
- Return type
-
backtracked.utils.ts(time: datetime.datetime) → float[source]¶ Converts a Python datetime to a JavaScript-style timestamp (milliseconds). Not 100% accurate.
- Parameters
time (
datetime.datetime) – Datetime to convert.- Returns
Number of milliseconds elapsed since 1970.
- Return type