Fix song counter and inconsistent queue state

This commit is contained in:
mmacierzanka committed 2026-08-21 14:56:29 +02:00
1 parent 4468f96c3b
commit fff320d3f2
2 files changed
+45 -7

No files matched your search

+22 -5
View File
@@ -189,12 +189,30 @@ class MusicPlayer:
if state.consume_jump():
advance = False
# Utwór z ostatnim odtworzeniem musi pozostać w kolejce do chwili
# zakończenia źródła. W przeciwnym razie panel dostaje `current`, ale
# `queue_index` wskazuje pozycję spoza kolejki podczas faktycznego
# odtwarzania ostatniej kopii.
retired_index: int | None = None
if advance and state.current is not None and 0 <= state.index < len(state.queue):
current = state.queue[state.index]
if current is state.current and self.plays_left(current) <= 0:
retired_index = state.index
state.queue.pop(state.index)
state.index -= 1
if not state.queue:
state.index = -1
state.current = None
await self.trigger_state_change()
return
next_index = self._next_index(state, advance=advance)
if retired_index is not None:
next_index = retired_index
if state.loop_mode.loops_queue:
next_index %= len(state.queue)
else:
next_index = self._next_index(state, advance=advance)
if next_index >= len(state.queue):
state.index = next_index
state.current = None
@@ -220,13 +238,12 @@ class MusicPlayer:
track.plays_left = self.plays_left(track) - 1
track.volume = state.volume
state.queue[next_index] = track
if track.plays_left <= 0:
state.queue.pop(next_index)
state.index = next_index - 1
# Usunięcie nastąpi dopiero po callbacku discord.py, po tym jak
# ostatnie odtworzenie rzeczywiście się zakończy.
if state.loop_mode.loops_track:
state.loop_mode = LoopMode.OFF
else:
state.queue[next_index] = track
state.current = track
self._record_history(guild_id, track)