remove _ from non-internal attributes for now

This commit is contained in:
vveeps 2021-10-07 18:37:41 +03:00
parent fc9f22e5ff
commit bdf0a75055
1 changed files with 23 additions and 23 deletions

View File

@ -23,11 +23,11 @@ class Player(VoiceProtocol):
self.client = client self.client = client
self.bot = client self.bot = client
self.channel = channel self.channel = channel
self._guild: discord.Guild = self.channel.guild self.guild: discord.Guild = self.channel.guild
self._dj: discord.Member = None self._dj: discord.Member = None
self._node = NodePool.get_node() self._node = NodePool.get_node()
self._current: objects.Track = None self.current: objects.Track = None
self._filter: filters.Filter = None self._filter: filters.Filter = None
self._volume = 100 self._volume = 100
self._paused = False self._paused = False
@ -41,7 +41,7 @@ class Player(VoiceProtocol):
def __repr__(self): def __repr__(self):
return ( return (
f"<Pomice.player bot={self.bot} guildId={self._guild.id} " f"<Pomice.player bot={self.bot} guildId={self.guild.id} "
f"is_connected={self.is_connected} is_playing={self.is_playing}>" f"is_connected={self.is_connected} is_playing={self.is_playing}>"
) )
@ -49,7 +49,7 @@ class Player(VoiceProtocol):
def position(self) -> float: def position(self) -> float:
"""Property which returns the player's position in a track in milliseconds""" """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 or not self.current:
return 0 return 0
if self.is_paused: if self.is_paused:
@ -58,15 +58,15 @@ class Player(VoiceProtocol):
difference = (time.time() * 1000) - self._last_update difference = (time.time() * 1000) - self._last_update
position = self._last_position + difference position = self._last_position + difference
if position > self._current.length: if position > self.current.length:
return 0 return 0
return min(position, self._current.length) return min(position, self.current.length)
@property @property
def is_playing(self) -> bool: def is_playing(self) -> bool:
"""Property which returns whether or not the player is actively playing a track.""" """Property which returns whether or not the player is actively playing a track."""
return self._is_connected and self._current is not None return self._is_connected and self.current is not None
@property @property
def is_paused(self) -> bool: def is_paused(self) -> bool:
@ -85,7 +85,7 @@ class Player(VoiceProtocol):
await self._node.send( await self._node.send(
op="voiceUpdate", op="voiceUpdate",
guildId=str(self._guild.id), guildId=str(self.guild.id),
**voice_data **voice_data
) )
@ -100,7 +100,7 @@ class Player(VoiceProtocol):
self._voice_state.clear() self._voice_state.clear()
return return
self.channel = self._guild.get_channel(int(channel_id)) self.channel = self.guild.get_channel(int(channel_id))
await self._dispatch_voice_update({**self._voice_state, "event": data}) await self._dispatch_voice_update({**self._voice_state, "event": data})
async def _dispatch_event(self, data: dict): async def _dispatch_event(self, data: dict):
@ -121,27 +121,27 @@ class Player(VoiceProtocol):
return await self._node.get_tracks(query, ctx) return await self._node.get_tracks(query, ctx)
async def connect(self, *, timeout: float, reconnect: bool): async def connect(self, *, timeout: float, reconnect: bool):
await self._guild.change_voice_state(channel=self.channel) await self.guild.change_voice_state(channel=self.channel)
self._node._players[self._guild.id] = self self._node._players[self.guild.id] = self
self.is_connected = True self.is_connected = True
async def stop(self): async def stop(self):
"""Stops a currently playing track.""" """Stops a currently playing track."""
self.current = None self.current = None
await self._node.send(op="stop", guildId=str(self._guild.id)) await self._node.send(op="stop", guildId=str(self.guild.id))
async def disconnect(self, *, force: bool = False): async def disconnect(self, *, force: bool = False):
await self.stop() await self.stop()
await self._guild.change_voice_state(channel=None) await self.guild.change_voice_state(channel=None)
self.cleanup() self.cleanup()
self.channel = None self.channel = None
self._is_connected = False self._is_connected = False
del self._node._players[self._guild.id] del self._node._players[self.guild.id]
async def destroy(self): async def destroy(self):
"""Disconnects a player and destroys the player instance.""" """Disconnects a player and destroys the player instance."""
await self.disconnect() await self.disconnect()
await self._node.send(op="destroy", guildId=str(self._guild.id)) await self._node.send(op="destroy", guildId=str(self.guild.id))
async def play(self, track: objects.Track, start_position: int = 0) -> objects.Track: async def play(self, track: objects.Track, start_position: int = 0) -> objects.Track:
"""Plays a track. If a Spotify track is passed in, it will be handled accordingly.""" """Plays a track. If a Spotify track is passed in, it will be handled accordingly."""
@ -151,7 +151,7 @@ class Player(VoiceProtocol):
))[0] ))[0]
await self._node.send( await self._node.send(
op="play", op="play",
guildId=str(self._guild.id), guildId=str(self.guild.id),
track=spotify_track.track_id, track=spotify_track.track_id,
startTime=start_position, startTime=start_position,
endTime=spotify_track.length, endTime=spotify_track.length,
@ -160,14 +160,14 @@ class Player(VoiceProtocol):
else: else:
await self._node.send( await self._node.send(
op="play", op="play",
guildId=str(self._guild.id), guildId=str(self.guild.id),
track=track.track_id, track=track.track_id,
startTime=start_position, startTime=start_position,
endTime=track.length, endTime=track.length,
noReplace=False noReplace=False
) )
self._current = track self.current = track
return self._current return self.current
async def seek(self, position: float) -> float: async def seek(self, position: float) -> float:
"""Seeks to a position in the currently playing track milliseconds""" """Seeks to a position in the currently playing track milliseconds"""
@ -177,18 +177,18 @@ class Player(VoiceProtocol):
f"Seek position must be between 0 and the track length" f"Seek position must be between 0 and the track length"
) )
await self._node.send(op="seek", guildId=str(self._guild.id), position=position) await self._node.send(op="seek", guildId=str(self.guild.id), position=position)
return self._position return self._position
async def set_pause(self, pause: bool) -> bool: async def set_pause(self, pause: bool) -> bool:
"""Sets the pause state of the currently playing track.""" """Sets the pause state of the currently playing track."""
await self._node.send(op="pause", guildId=str(self._guild.id), pause=pause) await self._node.send(op="pause", guildId=str(self.guild.id), pause=pause)
self._paused = pause self._paused = pause
return self._paused return self._paused
async def set_volume(self, volume: int) -> int: async def set_volume(self, volume: int) -> int:
"""Sets the volume of the player as an integer. Lavalink accepts an amount from 0 to 500.""" """Sets the volume of the player as an integer. Lavalink accepts an amount from 0 to 500."""
await self._node.send(op="volume", guildId=str(self._guild.id), volume=volume) await self._node.send(op="volume", guildId=str(self.guild.id), volume=volume)
self._volume = volume self._volume = volume
return self._volume return self._volume
@ -196,7 +196,7 @@ class Player(VoiceProtocol):
"""Sets a filter of the player. Takes a pomice.Filter object. """Sets a filter of the player. Takes a pomice.Filter object.
This will only work if you are using the development version of Lavalink. This will only work if you are using the development version of Lavalink.
""" """
await self._node.send(op="filters", guildId=str(self._guild.id), **filter.payload) await self._node.send(op="filters", guildId=str(self.guild.id), **filter.payload)
await self.seek(self.position) await self.seek(self.position)
self._filter = filter self._filter = filter
return filter return filter