fix: clean up `Player.position()`
This commit is contained in:
parent
8860df99de
commit
e8d29f9263
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue