From e8d29f9263769fdf037d97b960eeb8631afa6ad0 Mon Sep 17 00:00:00 2001 From: NiceAesth Date: Sat, 11 Mar 2023 18:24:28 +0200 Subject: [PATCH] fix: clean up `Player.position()` --- pomice/player.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pomice/player.py b/pomice/player.py index b8b3936..4646760 100644 --- a/pomice/player.py +++ b/pomice/player.py @@ -135,7 +135,6 @@ class Player(VoiceProtocol): *, node: Optional[Node] = None, ) -> None: - self.client: Client = client self.channel: VoiceChannel = channel @@ -166,10 +165,12 @@ class Player(VoiceProtocol): @property def position(self) -> float: """Property which returns the player's position in a track in milliseconds""" - if not self.is_playing or not self._current: + if not self.is_playing: return 0 - current = getattr(self._current, "original", self._current) + current: Track = self._current # type: ignore + if current.original: + current = current.original if self.is_paused: return min(self._last_position, current.length) @@ -353,7 +354,9 @@ class Player(VoiceProtocol): self, *, timeout: float, reconnect: bool, self_deaf: bool = False, self_mute: bool = False ) -> None: await self.guild.change_voice_state( - channel=self.channel, self_deaf=self_deaf, self_mute=self_mute, + channel=self.channel, + self_deaf=self_deaf, + self_mute=self_mute, ) self._node._players[self.guild.id] = self self._is_connected = True @@ -388,7 +391,9 @@ class Player(VoiceProtocol): self._node._players.pop(self.guild.id) await self._node.send( - method="DELETE", path=self._player_endpoint_uri, guild_id=self._guild.id, + method="DELETE", + path=self._player_endpoint_uri, + guild_id=self._guild.id, ) async def play( @@ -405,15 +410,20 @@ class Player(VoiceProtocol): raise search = ( await self._node.get_tracks(f"{track._search_type}:{track.isrc}", ctx=track.ctx) - )[0] # type: ignore + )[ + 0 + ] # type: ignore except Exception: # First method didn't work, lets try just searching it up try: search = ( await self._node.get_tracks( - f"{track._search_type}:{track.title} - {track.author}", ctx=track.ctx, + f"{track._search_type}:{track.title} - {track.author}", + ctx=track.ctx, ) - )[0] # type: ignore + )[ + 0 + ] # type: ignore except: # The song wasn't able to be found, raise error raise TrackLoadError(