feat: sanityzacja tytułów w Discordzie oraz linki i embedy dla powiadomień z panelu web

This commit is contained in:
mmacierzanka committed 2026-07-04 15:31:45 +02:00
1 parent 867edf302f
commit 444b797cd0
2 files changed
+31 -10

No files matched your search

+8 -8
View File
@@ -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:
+23 -2
View File
@@ -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: