chore: snapshot 2026-02-08
This commit is contained in:
36
player.py
36
player.py
@@ -8,7 +8,7 @@ import data
|
||||
import ui
|
||||
import logging
|
||||
|
||||
from subsonic import Song, APIError, get_random_songs, get_similar_songs, stream, scrobble
|
||||
from subsonic import Song, APIError, get_random_songs, get_similar_songs, stream, scrobble, get_album_art_url
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -263,6 +263,12 @@ class Player():
|
||||
song = self.queue.pop(0)
|
||||
self.current_song = song
|
||||
await ui.SysMsg.now_playing(interaction, song)
|
||||
# Update bot presence with now playing info
|
||||
try:
|
||||
cover_url = get_album_art_url(song.cover_id)
|
||||
await interaction.client.set_now_playing(song.title, song.artist, cover_url)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to update bot presence: {e}")
|
||||
await self.stream_track(interaction, song, voice_client)
|
||||
else:
|
||||
logger.debug("Queue is empty.")
|
||||
@@ -278,10 +284,15 @@ class Player():
|
||||
return
|
||||
# If the queue is empty, playback has ended; we should let the user know
|
||||
await ui.SysMsg.playback_ended(interaction)
|
||||
# Reset bot presence to default
|
||||
try:
|
||||
await interaction.client.set_default_presence()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to reset bot presence: {e}")
|
||||
|
||||
|
||||
async def skip_track(self, interaction: discord.Interaction, voice_client: discord.VoiceClient) -> None:
|
||||
''' Skips the current track and plays the next one in the queue '''
|
||||
async def skip_track(self, interaction: discord.Interaction, voice_client: discord.VoiceClient, count: int=None) -> None:
|
||||
''' Skips the current track and optionally additional tracks from the queue '''
|
||||
|
||||
# Check if the bot is connected to a voice channel; it's the caller's responsibility to open a voice channel
|
||||
if voice_client is None:
|
||||
@@ -290,8 +301,25 @@ class Player():
|
||||
logger.debug("Skipping track...")
|
||||
# Check if the bot is already playing something
|
||||
if voice_client.is_playing():
|
||||
# Determine how many tracks to skip in total (current + additional)
|
||||
total_skips = 1 if count is None or count < 1 else count
|
||||
|
||||
# Stop current playback (this counts as 1 skip)
|
||||
voice_client.stop()
|
||||
await ui.SysMsg.skipping(interaction)
|
||||
|
||||
# Remove additional tracks from the front of the queue, if any
|
||||
additional_to_skip = max(0, total_skips - 1)
|
||||
if additional_to_skip > 0 and self.queue:
|
||||
removed = min(additional_to_skip, len(self.queue))
|
||||
# Slice off the skipped items
|
||||
self.queue = self.queue[removed:]
|
||||
logger.debug(f"Skipped {removed} additional track(s) from queue")
|
||||
|
||||
# Notify user
|
||||
if total_skips <= 1:
|
||||
await ui.SysMsg.skipping(interaction)
|
||||
else:
|
||||
await ui.SysMsg.msg(interaction, f"Skipped {total_skips} track{'s' if total_skips != 1 else ''}", ephemeral=True)
|
||||
else:
|
||||
await ui.ErrMsg.not_playing(interaction)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user