From 444b797cd0ca1f55202c2244428c9e9fcefe537c Mon Sep 17 00:00:00 2001 From: Marcin Macierzanka Date: Sat, 4 Jul 2026 15:31:45 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20sanityzacja=20tytu=C5=82=C3=B3w=20w=20D?= =?UTF-8?q?iscordzie=20oraz=20linki=20i=20embedy=20dla=20powiadomie=C5=84?= =?UTF-8?q?=20z=20panelu=20web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 16 ++++++++-------- web.py | 25 +++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index fe1d99f..e672f76 100644 --- a/bot.py +++ b/bot.py @@ -141,7 +141,7 @@ class MusicBot(commands.Cog): self.get_queue(guild_id).append(player) await self.trigger_state_change() await interaction.followup.send( - f"Dodano do kolejki: {player.title}", + f"Dodano do kolejki: {discord.utils.escape_markdown(player.title)}", ephemeral=False ) else: @@ -155,7 +155,7 @@ class MusicBot(commands.Cog): ) ) await interaction.followup.send( - f"Teraz odtwarzane: {player.title}", + f"Teraz odtwarzane: {discord.utils.escape_markdown(player.title)}", ephemeral=False ) except Exception as e: @@ -186,7 +186,7 @@ class MusicBot(commands.Cog): self.bot.loop ) ) - await self.send_to_last_channel(guild_id, f"Teraz odtwarzane (zapętlone): {player.title}") + await self.send_to_last_channel(guild_id, f"Teraz odtwarzane (zapętlone): {discord.utils.escape_markdown(player.title)}") return except Exception as e: print(f"Error repeating song: {e}") @@ -203,17 +203,17 @@ class MusicBot(commands.Cog): self.bot.loop ) ) - await self.send_to_last_channel(guild_id, f"Teraz odtwarzane: {next_player.title}") + await self.send_to_last_channel(guild_id, f"Teraz odtwarzane: {discord.utils.escape_markdown(next_player.title)}") else: self.set_current(guild_id, None) await self.trigger_state_change() await self.send_to_last_channel(guild_id, "Kolejka jest pusta.") - async def send_to_last_channel(self, guild_id: int, text: str): + async def send_to_last_channel(self, guild_id: int, text: str = None, embed: discord.Embed = None): channel = self.get_notification_channel(guild_id) if channel: try: - await channel.send(text) + await channel.send(content=text if text else None, embed=embed) except Exception as e: print(f"Failed to send message: {e}") @@ -229,7 +229,7 @@ class MusicBot(commands.Cog): ) return - queue_list = "\n".join([f"{i + 1}. {item.title}" for i, item in enumerate(queue)]) + queue_list = "\n".join([f"{i + 1}. {discord.utils.escape_markdown(item.title)}" for i, item in enumerate(queue)]) await interaction.response.send_message( f"Aktualna kolejka:\n{queue_list}", ephemeral=False @@ -331,7 +331,7 @@ class MusicBot(commands.Cog): current = self.get_current(guild_id) if current: await interaction.response.send_message( - f"Teraz odtwarzane: {current.title}", + f"Teraz odtwarzane: {discord.utils.escape_markdown(current.title)}", ephemeral=False ) else: diff --git a/web.py b/web.py index b38c2be..f482259 100644 --- a/web.py +++ b/web.py @@ -201,9 +201,23 @@ async def api_play(req: PlayRequest): try: player = await YTDLSource.from_url(req.query, loop=bot.loop, stream=True) + url = player.data.get('webpage_url') or player.url + title_clean = discord.utils.escape_markdown(player.title or "Nieznany tytuł") + is_http = url and str(url).startswith("http") + if voice_client.is_playing() or voice_client.is_paused(): music_cog.get_queue(guild_id).append(player) - await music_cog.send_to_last_channel(guild_id, f"Dodano do kolejki (Web): {player.title}") + embed = discord.Embed( + title=f"🎵 {title_clean}", + url=url if is_http else None, + description=f"[Kliknij tutaj, aby otworzyć link]({url})" if is_http else "Plik lokalny / brak linku", + color=discord.Color.blue() + ) + embed.set_author(name="Dodano do kolejki z panelu Web", icon_url="https://cdn-icons-png.flaticon.com/512/3844/3844724.png") + if player.duration: + mins, secs = divmod(int(player.duration), 60) + embed.add_field(name="Czas trwania", value=f"{mins}:{secs:02d}", inline=True) + await music_cog.send_to_last_channel(guild_id, embed=embed) await broadcast_status() return {"status": "queued", "title": player.title} else: @@ -215,7 +229,14 @@ async def api_play(req: PlayRequest): bot.loop ) ) - await music_cog.send_to_last_channel(guild_id, f"Teraz odtwarzane (Web): {player.title}") + embed = discord.Embed( + title=f"▶️ {title_clean}", + url=url if is_http else None, + description=f"[Kliknij tutaj, aby otworzyć link]({url})" if is_http else "Plik lokalny / brak linku", + color=discord.Color.green() + ) + embed.set_author(name="Teraz odtwarzane (z panelu Web)", icon_url="https://cdn-icons-png.flaticon.com/512/3844/3844724.png") + await music_cog.send_to_last_channel(guild_id, embed=embed) await broadcast_status() return {"status": "playing", "title": player.title} except Exception as e: