Skip to content

Commit

Permalink
feat(node): add play route
Browse files Browse the repository at this point in the history
  • Loading branch information
ooliver1 committed Sep 19, 2022
1 parent f6bcd5f commit 8a12d6e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
44 changes: 42 additions & 2 deletions mafic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

from .__libraries import Client, VoiceServerUpdatePayload
from .player import Player
from .typings import Coro, EventPayload, IncomingMessage, OutgoingMessage
from .typings import (
Coro,
EventPayload,
IncomingMessage,
OutgoingMessage,
PlayPayload,
)

_log = getLogger(__name__)

Expand Down Expand Up @@ -265,7 +271,7 @@ def configure_resuming(self) -> Coro[None]:
}
)

def send_destroy(self, guild_id: int) -> Coro[None]:
def destroy(self, guild_id: int) -> Coro[None]:
_log.debug("Sending request to destroy player", extra={"label": self._label})

return self.__send(
Expand All @@ -275,6 +281,40 @@ def send_destroy(self, guild_id: int) -> Coro[None]:
}
)

def play(
self,
*,
guild_id: int,
track: str,
start_time: int | None,
end_time: int | None,
volume: int | None,
no_replace: bool | None,
pause: bool | None,
) -> Coro[None]:
data: PlayPayload = {
"op": "play",
"guildId": str(guild_id),
"track": track,
}

if start_time is not None:
data["startTime"] = str(start_time)

if end_time is not None:
data["endTime"] = str(end_time)

if volume is not None:
data["volume"] = str(volume)

if no_replace is not None:
data["noReplace"] = no_replace

if pause is not None:
data["pause"] = pause

return self.__send(data)

# TODO: play
# TODO: stop
# TODO: pause
Expand Down
2 changes: 1 addition & 1 deletion mafic/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ async def destroy(self) -> None:

if self._node is not None:
self._node.players.pop(self.guild.id, None)
await self._node.send_destroy(guild_id=self.guild.id)
await self._node.destroy(guild_id=self.guild.id)
10 changes: 5 additions & 5 deletions mafic/typings/outgoing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class VoiceStatePayload(PayloadWithGuild):
class PlayPayload(PayloadWithGuild):
op: Literal["play"]
track: str
startTime: str
endTime: str
volume: str
noReplace: bool
pause: bool
startTime: NotRequired[str]
endTime: NotRequired[str]
volume: NotRequired[str]
noReplace: NotRequired[bool]
pause: NotRequired[bool]


class StopPayload(PayloadWithGuild):
Expand Down

0 comments on commit 8a12d6e

Please sign in to comment.