Skip to content

Commit

Permalink
fix(events): handle v4 loadFailed EndReason
Browse files Browse the repository at this point in the history
  • Loading branch information
ooliver1 committed Aug 28, 2023
1 parent 8ab596a commit 7fc34b5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions mafic/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
class EndReason(str, Enum):
"""Represents the reason why a track ended."""

FINISHED = "FINISHED"
FINISHED = "finished"
"""The track finished playing."""

LOAD_FAILED = "LOAD_FAILED"
LOAD_FAILED = "loadFailed"
"""The track failed to load."""

STOPPED = "STOPPED"
STOPPED = "stopped"
"""The track was stopped."""

REPLACED = "REPLACED"
REPLACED = "replaced"
"""The track was replaced."""

CLEANUP = "CLEANUP"
CLEANUP = "cleanup"
"""The track was cleaned up."""


Expand Down Expand Up @@ -130,7 +130,13 @@ def __init__(
self, *, track: Track, payload: TrackEndEventPayload, player: PlayerT
) -> None:
self.track: Track = track
self.reason: EndReason = EndReason(payload["reason"].upper())
reason = payload["reason"]
if reason.isupper():
reason = reason.lower()
if reason == "loadfailed":
# Only case this happens, not worth a regex sub.
reason = "loadFailed"
self.reason: EndReason = EndReason(reason)
self.player: PlayerT = player

def __repr__(self) -> str:
Expand Down

0 comments on commit 7fc34b5

Please sign in to comment.