feat: dodanie trybu zapętlania całej kolejki (playlisty) w Discord (/loopplaylist) i w dashboardzie web
This commit is contained in:
4 files changed
+90
No files matched your search
@@ -19,6 +19,7 @@ class MusicBot(commands.Cog):
|
||||
self.currents = {} # guild_id -> player
|
||||
self.volumes = {} # guild_id -> volume float
|
||||
self.loop_currents = {} # guild_id -> bool
|
||||
self.loop_playlists = {} # guild_id -> bool
|
||||
self.last_channels = {} # guild_id -> text channel
|
||||
self.history = {} # guild_id -> list of dicts
|
||||
self.on_state_change_callback = None
|
||||
@@ -94,6 +95,12 @@ class MusicBot(commands.Cog):
|
||||
def set_loop_current(self, guild_id: int, loop: bool):
|
||||
self.loop_currents[guild_id] = loop
|
||||
|
||||
def get_loop_playlist(self, guild_id: int):
|
||||
return self.loop_playlists.get(guild_id, False)
|
||||
|
||||
def set_loop_playlist(self, guild_id: int, loop: bool):
|
||||
self.loop_playlists[guild_id] = loop
|
||||
|
||||
async def trigger_state_change(self):
|
||||
if self.on_state_change_callback:
|
||||
try:
|
||||
@@ -307,6 +314,17 @@ class MusicBot(commands.Cog):
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"Error repeating song: {e}")
|
||||
elif self.get_loop_playlist(guild_id) and current:
|
||||
try:
|
||||
if current.data.get('is_local'):
|
||||
new_player = await YTDLSource.from_file(current.data['filepath'], loop=self.bot.loop, title=current.title)
|
||||
else:
|
||||
url = current.data.get('webpage_url') or current.url
|
||||
new_player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True)
|
||||
self.get_queue(guild_id).append(new_player)
|
||||
await self.trigger_state_change()
|
||||
except Exception as e:
|
||||
print(f"Error re-adding track to playlist loop: {e}")
|
||||
|
||||
queue = self.get_queue(guild_id)
|
||||
if len(queue) > 0:
|
||||
@@ -573,12 +591,28 @@ class MusicBot(commands.Cog):
|
||||
guild_id = interaction.guild.id
|
||||
loop_current = not self.get_loop_current(guild_id)
|
||||
self.set_loop_current(guild_id, loop_current)
|
||||
if loop_current:
|
||||
self.set_loop_playlist(guild_id, False)
|
||||
state = "włączone" if loop_current else "wyłączone"
|
||||
await interaction.response.send_message(
|
||||
f"Zapętlanie aktualnego utworu zostało {state}.",
|
||||
ephemeral=False
|
||||
)
|
||||
|
||||
@app_commands.command(name="loopplaylist", description="Włącz/wyłącz zapętlanie całej kolejki (tryb playlisty)")
|
||||
async def loopplaylist_command(self, interaction: discord.Interaction):
|
||||
"""Włącz/wyłącz zapętlanie całej kolejki"""
|
||||
guild_id = interaction.guild.id
|
||||
loop_pl = not self.get_loop_playlist(guild_id)
|
||||
self.set_loop_playlist(guild_id, loop_pl)
|
||||
if loop_pl:
|
||||
self.set_loop_current(guild_id, False)
|
||||
state = "włączone (utwory po zakończeniu wracają na koniec kolejki)" if loop_pl else "wyłączone"
|
||||
await interaction.response.send_message(
|
||||
f"🔁 Zapętlanie całej kolejki: **{state}**.",
|
||||
ephemeral=False
|
||||
)
|
||||
|
||||
|
||||
class MyBot(commands.Bot):
|
||||
def __init__(self):
|
||||
|
||||
Reference in new issue
Block a user