-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
290 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
per-file-ignores = | ||
__init__.py: F401,F403 | ||
__init__.py: F401 | ||
# Black already handles E501 - line too long, ignored for docstring anomolies. | ||
# W503 - line break before binary operator, ignored for Black, flake8 cannot decide what style lmao. | ||
extend-ignore = E501,W503 | ||
extend-ignore = E501,W503,F403,F405 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
# SPDX-License-Identifier: MIT | ||
# pyright: reportImportCycles=false | ||
# Player import. | ||
|
||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .player import Player | ||
from .track import Track | ||
from .type_variables import ClientT | ||
from .typings import ( | ||
LavalinkException, | ||
TrackEndEvent as TrackEndEventPayload, | ||
TrackExceptionEvent as TrackExceptionEventPayload, | ||
TrackStuckEvent as TrackStuckEventPayload, | ||
WebSocketClosedEvent as WebSocketClosedEventPayload, | ||
) | ||
|
||
__all__ = ( | ||
"EndReason", | ||
"TrackEndEvent", | ||
"TrackExceptionEvent", | ||
"TrackStartEvent", | ||
"TrackStuckEvent", | ||
"WebSocketClosedEvent", | ||
) | ||
|
||
|
||
class EndReason(str, Enum): | ||
"""Represents the reason why a track ended.""" | ||
|
||
FINISHED = "FINISHED" | ||
"""The track finished playing.""" | ||
|
||
LOAD_FAILED = "LOAD_FAILED" | ||
"""The track failed to load.""" | ||
|
||
STOPPED = "STOPPED" | ||
"""The track was stopped.""" | ||
|
||
REPLACED = "REPLACED" | ||
"""The track was replaced.""" | ||
|
||
CLEANUP = "CLEANUP" | ||
"""The track was cleaned up.""" | ||
|
||
|
||
class WebSocketClosedEvent: | ||
"""Represents an event when the connection to Discord is lost. | ||
Attributes | ||
---------- | ||
code: :class:`int` | ||
The close code. | ||
Find what this can be in the Discord `docs`_. | ||
.. _docs: https://discord.com/developers/docs/topics/opcodes-and-status-codes#close-event-codes. | ||
reason: :class:`str` | ||
The close reason. | ||
by_discord: :class:`bool` | ||
Whether the close was initiated by Discord. | ||
player: :class:`Player` | ||
The player that the event was dispatched from. | ||
""" | ||
|
||
__slots__ = ("code", "reason", "by_discord", "player") | ||
|
||
def __init__( | ||
self, *, payload: WebSocketClosedEventPayload, player: Player[ClientT] | ||
): | ||
self.code: int = payload["code"] | ||
self.reason: str = payload["reason"] | ||
self.by_discord: bool = payload["byRemote"] | ||
self.player: Player[ClientT] = player | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
f"<WebSocketClosedEvent code={self.code} reason={self.reason!r} " | ||
f"by_discord={self.by_discord}>" | ||
) | ||
|
||
|
||
class TrackStartEvent: | ||
"""Represents an event when a track starts playing. | ||
Attributes | ||
---------- | ||
track: :class:`Track` | ||
The track that started playing. | ||
player: :class:`Player` | ||
The player that the event was dispatched from. | ||
""" | ||
|
||
__slots__ = ("track", "player") | ||
|
||
def __init__(self, *, track: Track, player: Player[ClientT]): | ||
self.track: Track = track | ||
self.player: Player[ClientT] = player | ||
|
||
def __repr__(self) -> str: | ||
return f"<TrackStartEvent track={self.track!r}>" | ||
|
||
|
||
class TrackEndEvent: | ||
"""Represents an event when a track ends. | ||
Attributes | ||
---------- | ||
track: :class:`Track` | ||
The track that ended. | ||
reason: :class:`EndReason` | ||
The reason why the track ended. | ||
player: :class:`Player` | ||
The player that the event was dispatched from. | ||
""" | ||
|
||
__slots__ = ("track", "reason", "player") | ||
|
||
def __init__( | ||
self, *, track: Track, payload: TrackEndEventPayload, player: Player[ClientT] | ||
): | ||
self.track: Track = track | ||
self.reason: EndReason = EndReason(payload["reason"]) | ||
self.player: Player[ClientT] = player | ||
|
||
def __repr__(self) -> str: | ||
return f"<TrackEndEvent track={self.track!r} reason={self.reason!r}>" | ||
|
||
|
||
class TrackExceptionEvent: | ||
"""Represents an event when an exception occurs while playing a track. | ||
Attributes | ||
---------- | ||
track: :class:`Track` | ||
The track that caused the exception. | ||
exception: :class:`Exception` | ||
The exception that was raised. | ||
player: :class:`Player` | ||
The player that the event was dispatched from. | ||
""" | ||
|
||
__slots__ = ("track", "exception", "player") | ||
|
||
def __init__( | ||
self, | ||
*, | ||
track: Track, | ||
payload: TrackExceptionEventPayload, | ||
player: Player[ClientT], | ||
): | ||
self.track: Track = track | ||
self.exception: LavalinkException = payload["exception"] | ||
self.player: Player[ClientT] = player | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
f"<TrackExceptionEvent track={self.track!r} exception={self.exception!r}>" | ||
) | ||
|
||
|
||
class TrackStuckEvent: | ||
"""Represents an event when a track gets stuck. | ||
Attributes | ||
---------- | ||
track: :class:`Track` | ||
The track that got stuck. | ||
threshold_ms: :class:`int` | ||
The threshold in milliseconds that was exceeded. | ||
player: :class:`Player` | ||
The player that the event was dispatched from. | ||
""" | ||
|
||
__slots__ = ("track", "threshold_ms", "player") | ||
|
||
def __init__( | ||
self, *, track: Track, payload: TrackStuckEventPayload, player: Player[ClientT] | ||
): | ||
self.track: Track = track | ||
self.threshold_ms: int = payload["thresholdMs"] | ||
self.player: Player[ClientT] = player | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
f"<TrackStuckEvent track={self.track!r} threshold_ms={self.threshold_ms}>" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.