Skip to content

Commit

Permalink
feat(player): support str for playing identifiers (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
ooliver1 committed May 14, 2023
1 parent af7c8be commit 6d1fde0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
13 changes: 10 additions & 3 deletions mafic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,14 @@ def update(
self,
*,
guild_id: int,
track: Track | None = MISSING,
track: Track | str | None = MISSING,
position: int | None = None,
end_time: int | None = None,
volume: int | None = None,
no_replace: bool | None = None,
pause: bool | None = None,
filter: Filter | None = None,
) -> Coro[None]:
) -> Coro[PlayerPayload]:
"""Update a player.
Parameters
Expand All @@ -896,7 +896,11 @@ def update(
The guild ID to update the player for.
track:
The track to update the player with.
This can be either a :class:`Track` or an identifier.
Setting this to ``None`` will clear the track.
.. versionchanged:: 2.4
The track can now be a :class:`str` to play an identifier.
position:
The position to update the player with.
end_time:
Expand All @@ -913,7 +917,10 @@ def update(
data: UpdatePlayerPayload = {}

if track is not MISSING:
data["encodedTrack"] = track.id if track is not None else None
if isinstance(track, Track) or track is None:
data["encodedTrack"] = track.id if track is not None else None
else:
data["identifier"] = track

if position is not None:
data["position"] = position
Expand Down
32 changes: 19 additions & 13 deletions mafic/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ async def fetch_tracks(
async def update(
self,
*,
track: Track | None = MISSING,
track: Track | str | None = MISSING,
position: int | None = None,
end_time: int | None = None,
volume: int | None = None,
Expand All @@ -545,7 +545,10 @@ async def update(
Parameters
----------
track:
The track to play.
The track to play. This can be a :class:`Track` or an identifier.
.. versionchanged:: 2.4
The track can now be a :class:`str` to play an identifier.
position:
The position to start the track at.
end_time:
Expand All @@ -567,13 +570,7 @@ async def update(
if self._node is None or not self._connected:
raise PlayerNotConnected

if track is not MISSING:
self._current = track

if position is not None:
self._position = position

await self._node.update(
data = await self._node.update(
guild_id=self._guild_id,
track=track,
position=position,
Expand All @@ -584,12 +581,18 @@ async def update(
no_replace=not replace,
)

if pause is not None:
self._paused = pause
if data["track"]:
self._current = Track.from_data_with_info(data["track"])

if data["volume"]:
self._volume = data["volume"]

if data["paused"]:
self._paused = data["paused"]

async def play(
self,
track: Track,
track: Track | str,
/,
*,
start_time: int | None = None,
Expand All @@ -603,7 +606,10 @@ async def play(
Parameters
----------
track:
The track to play.
The track to play. This can be a :class:`Track` or an identifier.
.. versionchanged:: 2.4
The track can now be a :class:`str` to play an identifier.
start_time:
The position to start the track at.
end_time:
Expand Down

0 comments on commit 6d1fde0

Please sign in to comment.