Supplementary¶
This section contains reference documentation for the more advanced concepts and types in SonoLink. If you’re new to SonoLink, you should start with the SonoLink Documentation and the Guides before diving into this section.
Queue¶
- class sonolink.History(settings: HistorySettings | None = None)[source]¶
- Attributes
A specialized queue for tracking playback history.
This class is intended to be read-only for users. Mutation methods will raise
AttributeError.
- class sonolink.Queue(*, mode: QueueMode = QueueMode.NORMAL, history_settings: HistorySettings | None = None)[source]¶
- Attributes
A queue implementation for managing playable tracks.
- copy() Queue[source]¶
Create a shallow copy of the queue.
- Returns:
A shallow copy of the queue with the same items, mode, and history.
- Return type:
- get() Playable[source]¶
Get the next track from the queue, respecting the current queue mode.
User-added tracks always take priority over AutoPlay-discovered tracks. If the user lane is empty, falls back to the AutoPlay lane. If the queue is in
LOOPmode, returns the current track. If the queue is inLOOP_ALLmode and empty, restores tracks from history.- Returns:
The retrieved track.
- Return type:
- Raises:
QueueEmpty – Both the user queue and AutoPlay queue are empty.
- async get_wait() Playable[source]¶
Asynchronously get a track from the queue, waits if necessary.
This method will wait indefinitely until a track is available in the queue. This method can be used to implement a system that waits for a next track to play after the current track finishes, for example.
- Returns:
The retrieved track.
- Return type:
- pop() Playable[source]¶
Remove and return the next track from the queue.
The returned track is set as the current track. If history is enabled, the previous current track is added to history.
- Returns:
The popped track.
- Return type:
- Raises:
QueueEmpty – The queue is empty.
- pop_at(index: int) Playable[source]¶
Remove and return a track from a specific queue index.
The returned track is set as the current track. If history is enabled, the previous current track is added to history.
- Parameters:
index (
int) – The index to pop from.- Returns:
The popped track.
- Return type:
- Raises:
QueueEmpty – The queue is empty.
IndexError – There is no item at the given index.
- previous() Playable[source]¶
Pop the most recent track from history and set it as current.
The current track is pushed back to the front of the queue.
- Returns:
The track retrieved from history.
- Return type:
- Raises:
QueueEmpty – The history is empty.
- put(tracks: Iterable[Playable] | Playable | Playlist, /, *, atomic: bool = True) int[source]¶
Put one or more tracks at the end of the queue.
- Parameters:
tracks (
sonolink.models.Playable|sonolink.models.Playlist| Iterable[sonolink.models.Playable]) – The track(s) or playlist to add to the queue.atomic (
bool) – Whether to insert the items atomically. IfTrue, all items must be Playable or a TypeError is raised and nothing is added. IfFalse, non-Playable items are filtered out. Defaults toTrue.
- Returns:
The number of tracks added to the queue.
- Return type:
- Raises:
TypeError – When
atomic=Trueand a non-Playable item is encountered.
- put_at(index: int, tracks: Iterable[Playable] | Playable | Playlist, /, *, atomic: bool = True) int¶
Put one or more tracks at
index.- Parameters:
index (
int) – The index to insert the track(s) to.tracks (
sonolink.models.Playable|sonolink.models.Playlist| Iterable[sonolink.models.Playable]) – The track(s) or playlist to add to the queue.atomic (
bool) – Whether to insert the items atomically. IfTrue, all items must be Playable or a TypeError is raised and nothing is added. IfFalse, non-Playable items are filtered out. Defaults toTrue.
- Returns:
The number of tracks added to the queue.
- Return type:
- Raises:
TypeError – When
atomic=Trueand a non-Playable item is encountered.
- put_autoplay(tracks: Iterable[Playable] | Playable, /) int[source]¶
Add AutoPlay-discovered tracks to the AutoPlay lane.
These tracks are only played once all user-added tracks are exhausted. Each track is automatically tagged with
autoplay.- Parameters:
tracks (
sonolink.models.Playable| Iterable[sonolink.models.Playable]) – The AutoPlay track(s) to stage.- Returns:
int– The number of tracks added.versionadded::1.1.0
- Return type:
- async put_wait(tracks: Iterable[Playable] | Playable | Playlist, /, *, atomic: bool = True) int[source]¶
Asynchronously put one or more tracks into the queue.
This method is thread-safe and maintains insert order through a lock.
- Parameters:
tracks (
sonolink.models.Playable|sonolink.models.Playlist| Iterable[sonolink.models.Playable]) – The track(s) or playlist to add to the queue.atomic (
bool) – Whether to insert the items atomically. IfTrue, all items must be Playable or a TypeError is raised and nothing is added. IfFalse, non-Playable items are filtered out. Defaults toTrue.
- Returns:
The number of tracks added to the queue.
- Return type:
- Raises:
TypeError – When
atomic=Trueand a non-Playable item is encountered.
- remove(tracks: Iterable[Playable] | Playable | Playlist, /, *, remove_all: bool = True) int¶
Removes one or more tracks from this queue.
- Parameters:
tracks (
sonolink.models.Playable|sonolink.models.Playlist| Iterable[sonolink.models.Playable]) – The track(s) or playlist to remove from the queue.remove_all (
bool) – Whether to remove all occurrences of a track from this queue. When set toFalse, only the first occurrence of each track is removed. Defaults toTrue.
- Returns:
The number of tracks removed from the queue.
- Return type:
- async remove_wait(tracks: Iterable[Playable] | Playable | Playlist, /, *, remove_all: bool = True) int[source]¶
Asynchronously remove one or more tracks from the queue.
This method is thread-safe.
- Parameters:
tracks (
sonolink.models.Playable|sonolink.models.Playlist| Iterable[sonolink.models.Playable]) – The track(s) or playlist to remove from the queue.remove_all (
bool) – Whether to remove all occurrences of a track from this queue. When set toFalse, only the first occurrence of each track is removed. Defaults toTrue.
- Returns:
The number of tracks removed from the queue.
- Return type:
- reset() None[source]¶
Reset the queue to its default state.
This will: - Clear all items from the queue - Clear AutoPlay-discovered tracks - Clear history - Reset the mode to
QueueMode.NORMAL- Clear the current track - Cancel all waiting futures
- swap(old: int, new: int) None[source]¶
Swap two tracks in the queue by index.
- Parameters:
- Raises:
IndexError – One or both indices are out of range.
- property autoplay_tracks: list[Playable]¶
The list of AutoPlay-discovered tracks currently staged in the queue.
These tracks are only played once all user-added tracks are exhausted. Modifying this list will not affect the actual queue.
- Returns:
list[:class:`Playable]` – A list of AutoPlay tracks.versionadded::1.1.0
- property count: int¶
The number of tracks in this collection.
- Returns:
The total number of tracks currently held.
- Return type:
- property current_track: Playable | None¶
The currently loaded track.
This track is typically the one being played or most recently played.
This is also used when
modeis set toQueueMode.LOOPto determine which track to repeat. This can be manually set too.- Returns:
The current track, or
Noneif not set.- Return type:
sonolink.models.Playable| None
- property history: History¶
The queue history.
- Returns:
The queue history if history is enabled, otherwise
None.- Return type:
History| None
- property mode: QueueMode¶
The current queue mode.
QueueMode.NORMAL: Tracks are played in order and removed from the queue.QueueMode.LOOP:current_trackis repeated indefinitely until manually changed.QueueMode.LOOP_ALL: When the queue is empty, all tracks from history are restoredto the queue and played again.
- Returns:
The current queue mode.
- Return type:
- property tracks: list[Playable]¶
The list of tracks currently in the queue.
This does not include the
current_trackor AutoPlay-discovered tracks. Modifying this list will not affect the actual queue; use methods likeput()orpop_at()for modifications.- Returns:
A list of tracks in the queue.
- Return type:
list[:class:`Playable]`
Network¶
Messages¶
- class sonolink.network.message.MessageType(*values)[source]¶
- classmethod from_bytes(bytes, byteorder='big', *, signed=False)¶
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.
- signed
Indicates whether two’s complement is used to represent the integer.
- as_integer_ratio()¶
Return a pair of integers, whose ratio is equal to the original int.
The ratio is in lowest terms and has a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- bit_count()¶
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- bit_length()¶
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- conjugate()¶
Returns self, the complex conjugate of any int.
- is_integer()¶
Returns True. Exists for duck type compatibility with float.is_integer.
- to_bytes(length=1, byteorder='big', *, signed=False)¶
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- BINARY = 2¶
- CLOSE = 8¶
- CONTINUATION = 0¶
- PING = 9¶
- PONG = 10¶
- TEXT = 1¶
- denominator¶
the denominator of a rational number in lowest terms
- imag¶
the imaginary part of a complex number
- numerator¶
the numerator of a rational number in lowest terms
- real¶
the real part of a complex number
Utilities API¶
- sonolink.utils.cached_property(attribute: str) Callable[[Callable[[T], T_co]], _cached_property[T, T_co]][source]¶
Creates a cached property that stores the result under
class.attribute.
- sonolink._registry.get_client(bot: Any) Client[Any] | None[source]¶
Get the SonoLink client associated with a Discord client instance.
Added in version 1.1.0.
- Parameters:
bot (
Any) – The Discord client instance to retrieve the client for.- Returns:
The SonoLink client associated with the Discord client, if any. Otherwise,
None.- Return type:
Client[Any] | None