From a66c31ecf6f5359e9f39c9e20c66e49898fe1c24 Mon Sep 17 00:00:00 2001 From: Mow Date: Wed, 12 Nov 2025 23:31:23 +0100 Subject: [PATCH 1/3] Modification de l'embed affiche jusqu'a 35 jeux + notifi quand il cherche --- discordbot/__init__.py | 68 +++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/discordbot/__init__.py b/discordbot/__init__.py index c552d85..8871cbe 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -178,7 +178,13 @@ async def on_message(message: Message): logging.error(f"Échec de la gestion du message d'aide ProtonDB : {e}") return - games = searhProtonDb(name) + try: + searching_msg = await message.channel.send(f"🔍 Recherche en cours pour **{name}**...") + games = searhProtonDb(name) + await searching_msg.delete() + except: + games = searhProtonDb(name) + if (len(games)==0) : msg = f'{mention} Je n\'ai pas trouvé de jeux correspondant à **{name}**. Es-tu sûr que le jeu est disponible sur Steam ?' try: @@ -188,51 +194,51 @@ async def on_message(message: Message): return total_games = len(games) embed = discord.Embed( - title=f"**{total_games} jeu{'x' if total_games > 1 else ''} trouvé{'s' if total_games > 1 else ''}**", - color=discord.Color.blurple() + title=f"🎮 Résultats ProtonDB - **{total_games} jeu{'x' if total_games > 1 else ''} trouvé{'s' if total_games > 1 else ''}**", + color=0x5865F2 ) - max_fields = 10 - count = 0 - for game in games: - if count >= max_fields: - break + tier_colors = {'platinum': '🟣', 'gold': '🟡', 'silver': '⚪', 'bronze': '🟤', 'borked': '🔴'} + content = "" + max_games = 35 + + for count, game in enumerate(games[:max_games]): g_name = str(game.get('name')) g_id = str(game.get('id')) - tier = str(game.get('tier') or 'N/A') + tier = str(game.get('tier') or 'N/A').lower() + tier_icon = tier_colors.get(tier, '⚫') + + content += f"**[{g_name}]()**\n" + content += f"{tier_icon} Classé **{tier.capitalize()}**" + ac_status = game.get('anticheat_status') - ac_text = '' if ac_status: status_lower = str(ac_status).lower() - if status_lower == 'supported': - ac_emoji, ac_label = '✅', 'Supporté' - elif status_lower == 'running': - ac_emoji, ac_label = '⚠️', 'Fonctionne' - elif status_lower == 'broken': - ac_emoji, ac_label = '❌', 'Cassé' - elif status_lower == 'denied': - ac_emoji, ac_label = '🚫', 'Refusé' - elif status_lower == 'planned': - ac_emoji, ac_label = '📅', 'Planifié' - else: - ac_emoji, ac_label = '❔', str(ac_status) + ac_map = { + 'supported': ('✅', 'Supporté'), + 'running': ('⚠️', 'Fonctionne'), + 'broken': ('❌', 'Cassé'), + 'denied': ('🚫', 'Refusé'), + 'planned': ('📅', 'Planifié') + } + ac_emoji, ac_label = ac_map.get(status_lower, ('❔', str(ac_status))) acs = game.get('anticheats') or [] ac_list = ', '.join([str(ac) for ac in acs if ac]) - ac_text = f" | [Anti-cheat: {ac_emoji} {ac_label}" + content += f" • [Anti-cheat {ac_emoji} {ac_label}" if ac_list: - ac_text += f" ({ac_list})" - ac_text += f"]()" + content += f" ({ac_list})" + content += f"]()" - field_value = f"[{g_name}]() - **Classé**: {tier}{ac_text}" - embed.add_field(name="\u200b", value=field_value, inline=False) - count += 1 + content += "\n\n" - rest = max(0, len(games) - count) + rest = max(0, len(games) - max_games) if rest > 0: - embed.add_field(name="…", value=f"et encore {rest} autres jeux", inline=False) + content += f"*... et {rest} autre{'s' if rest > 1 else ''} jeu{'x' if rest > 1 else ''}*" + + embed.add_field(name="", value=content, inline=False) try : - await message.channel.send(content=mention, embed=embed) + await message.channel.send(embed=embed) except Exception as e: logging.error(f"Échec de l'envoi de l'embed ProtonDB : {e}") From 9abd7b81014085dc4838d1faa788ef4ed9d118b9 Mon Sep 17 00:00:00 2001 From: Mow Date: Wed, 12 Nov 2025 23:47:46 +0100 Subject: [PATCH 2/3] Ajout de la limitation de carractere 4096 MAx et 15 resultat a afficher --- discordbot/__init__.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/discordbot/__init__.py b/discordbot/__init__.py index 8871cbe..2de81dd 100644 --- a/discordbot/__init__.py +++ b/discordbot/__init__.py @@ -193,14 +193,9 @@ async def on_message(message: Message): logging.error(f"Échec de l'envoi du message ProtonDB : {e}") return total_games = len(games) - embed = discord.Embed( - title=f"🎮 Résultats ProtonDB - **{total_games} jeu{'x' if total_games > 1 else ''} trouvé{'s' if total_games > 1 else ''}**", - color=0x5865F2 - ) - tier_colors = {'platinum': '🟣', 'gold': '🟡', 'silver': '⚪', 'bronze': '🟤', 'borked': '🔴'} content = "" - max_games = 35 + max_games = 15 for count, game in enumerate(games[:max_games]): g_name = str(game.get('name')) @@ -208,8 +203,7 @@ async def on_message(message: Message): tier = str(game.get('tier') or 'N/A').lower() tier_icon = tier_colors.get(tier, '⚫') - content += f"**[{g_name}]()**\n" - content += f"{tier_icon} Classé **{tier.capitalize()}**" + new_entry = f"**[{g_name}]()**\n{tier_icon} Classé **{tier.capitalize()}**" ac_status = game.get('anticheat_status') if ac_status: @@ -224,18 +218,30 @@ async def on_message(message: Message): ac_emoji, ac_label = ac_map.get(status_lower, ('❔', str(ac_status))) acs = game.get('anticheats') or [] ac_list = ', '.join([str(ac) for ac in acs if ac]) - content += f" • [Anti-cheat {ac_emoji} {ac_label}" + new_entry += f" • [Anti-cheat {ac_emoji} {ac_label}" if ac_list: - content += f" ({ac_list})" - content += f"]()" + new_entry += f" ({ac_list})" + new_entry += f"]()" - content += "\n\n" + new_entry += "\n\n" + + # Vérifier la limite avant d'ajouter + if len(content) + len(new_entry) > 3900: + rest = len(games) - count + content += f"*... et {rest} autre{'s' if rest > 1 else ''} jeu{'x' if rest > 1 else ''}*" + break + + content += new_entry + else: + rest = max(0, len(games) - max_games) + if rest > 0: + content += f"*... et {rest} autre{'s' if rest > 1 else ''} jeu{'x' if rest > 1 else ''}*" - rest = max(0, len(games) - max_games) - if rest > 0: - content += f"*... et {rest} autre{'s' if rest > 1 else ''} jeu{'x' if rest > 1 else ''}*" - - embed.add_field(name="", value=content, inline=False) + embed = discord.Embed( + title=f"🎮 Résultats ProtonDB - **{total_games} jeu{'x' if total_games > 1 else ''} trouvé{'s' if total_games > 1 else ''}**", + description=content, + color=0x5865F2 + ) try : await message.channel.send(embed=embed) From 559a780a4fcaaa959f61112f5abf43fbbd1d6e95 Mon Sep 17 00:00:00 2001 From: Mow Date: Sun, 16 Nov 2025 21:55:05 +0100 Subject: [PATCH 3/3] Correctif !pdb avec ajout du message de recherche, correction des bugs mention sur les notifications, et correction !say pour mettre un ID de channel --- discordbot/moderation.py | 49 ++++++++++++++++++++++++++-------------- discordbot/welcome.py | 4 ++-- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/discordbot/moderation.py b/discordbot/moderation.py index 8eb7a86..366aeb9 100644 --- a/discordbot/moderation.py +++ b/discordbot/moderation.py @@ -231,8 +231,8 @@ async def send_warning_confirmation(channel, target_user, reason: str, original_ color=discord.Color.orange(), timestamp=datetime.now(timezone.utc) ) - embed.add_field(name="👤 Utilisateur", value=f"{target_user.mention}\n`{target_user.id}`", inline=True) - embed.add_field(name="🛡️ Modérateur", value=f"{original_message.author.mention}\n`{original_message.author.name}`", inline=True) + embed.add_field(name="👤 Utilisateur", value=f"**{target_user.name}**\n`{target_user.id}`", inline=True) + embed.add_field(name="🛡️ Modérateur", value=f"**{original_message.author.name}**", inline=True) embed.add_field(name="📅 Date et heure", value=local_now.strftime('%d/%m/%Y à %H:%M'), inline=True) if reason != "Sans raison": embed.add_field(name="📝 Raison", value=reason, inline=False) @@ -349,8 +349,8 @@ async def send_timeout_confirmation(channel, target_user, reason: str, timeout_s color=discord.Color.orange(), timestamp=datetime.now(timezone.utc) ) - embed.add_field(name="👤 Utilisateur", value=f"{target_user.mention}\n`{target_user.id}`", inline=True) - embed.add_field(name="🛡️ Modérateur", value=f"{original_message.author.mention}\n`{original_message.author.name}`", inline=True) + embed.add_field(name="👤 Utilisateur", value=f"**{target_user.name}**\n`{target_user.id}`", inline=True) + embed.add_field(name="🛡️ Modérateur", value=f"**{original_message.author.name}**", inline=True) embed.add_field(name="📅 Date et heure", value=local_now.strftime('%d/%m/%Y à %H:%M'), inline=True) embed.add_field(name="⏱️ Durée", value=format_timeout_duration(timeout_seconds), inline=True) if reason != "Sans raison": @@ -686,8 +686,8 @@ async def _process_ban_success(message: Message, target_user, reason: str, bot): color=discord.Color.red(), timestamp=datetime.now(timezone.utc) ) - embed.add_field(name="👤 Utilisateur", value=f"{target_user.mention}\n`{target_user.id}`", inline=True) - embed.add_field(name="🛡️ Modérateur", value=f"{message.author.mention}\n`{message.author.name}`", inline=True) + embed.add_field(name="👤 Utilisateur", value=f"**{target_user.name}**\n`{target_user.id}`", inline=True) + embed.add_field(name="🛡️ Modérateur", value=f"{message.author.name}", inline=True) embed.add_field(name="📅 Date et heure", value=local_now.strftime('%d/%m/%Y à %H:%M'), inline=True) if joined_days is not None: embed.add_field(name="⏱️ Membre depuis", value=format_days_to_age(joined_days), inline=True) @@ -801,9 +801,9 @@ async def _process_unban_success(message: Message, bot, target_user, discord_id: color=discord.Color.green(), timestamp=datetime.now(timezone.utc) ) - user_mention = target_user.mention if target_user else username - embed.add_field(name="👤 Utilisateur", value=f"{user_mention}\n`{discord_id}`", inline=True) - embed.add_field(name="🛡️ Modérateur", value=f"{message.author.mention}\n`{message.author.name}`", inline=True) + user_display = f"**{target_user.name}**" if target_user else f"**{username}**" + embed.add_field(name="👤 Utilisateur", value=f"{user_display}\n`{discord_id}`", inline=True) + embed.add_field(name="🛡️ Modérateur", value=f"**{message.author.name}**", inline=True) embed.add_field(name="📅 Date et heure", value=local_now.strftime('%d/%m/%Y à %H:%M'), inline=True) if reason != "Sans raison": embed.add_field(name="📝 Raison", value=reason, inline=False) @@ -1155,8 +1155,8 @@ async def _process_kick_success(message: Message, target_member, reason: str, bo color=discord.Color.orange(), timestamp=datetime.now(timezone.utc) ) - embed.add_field(name="👤 Utilisateur", value=f"{target_member.mention}\n`{target_member.id}`", inline=True) - embed.add_field(name="🛡️ Modérateur", value=f"{message.author.mention}\n`{message.author.name}`", inline=True) + embed.add_field(name="👤 Utilisateur", value=f"**{target_member.name}**\n`{target_member.id}`", inline=True) + embed.add_field(name="🛡️ Modérateur", value=f"**{message.author.name}**", inline=True) embed.add_field(name="📅 Date et heure", value=local_now.strftime('%d/%m/%Y à %H:%M'), inline=True) if joined_days is not None: embed.add_field(name="⏱️ Membre depuis", value=format_days_to_age(joined_days), inline=True) @@ -1228,7 +1228,7 @@ def create_inspect_embed(user, member, join_date, days_on_server, account_age, w ) embed.set_thumbnail(url=user.display_avatar.url) - embed.add_field(name="👤 Utilisateur", value=f"{user.mention}\n`{user.id}`", inline=True) + embed.add_field(name="👤 Utilisateur", value=f"**{user.name}**\n`{user.id}`", inline=True) if account_age is not None: embed.add_field( @@ -1355,25 +1355,40 @@ async def handle_say_command(message: Message, bot): if len(parts) < 3: embed = discord.Embed( title="📋 Utilisation de la commande", - description="**Syntaxe :** `!say #channel message`", + description="**Syntaxe :** `!say #channel message` ou `!say message`", color=discord.Color.blue() ) - embed.add_field(name="Exemple", value="`!say #general Bonjour à tous !`", inline=False) + embed.add_field(name="Exemples", value="`!say #general Bonjour à tous !`\n`!say 123456789 Annonce importante`", inline=False) msg = await message.channel.send(embed=embed) asyncio.create_task(delete_after_delay(msg)) return - if not message.channel_mentions: + target_channel = None + + if message.channel_mentions: + target_channel = message.channel_mentions[0] + else: + try: + channel_id = int(parts[1]) + target_channel = bot.get_channel(channel_id) + if not target_channel: + try: + target_channel = await bot.fetch_channel(channel_id) + except discord.NotFound: + pass + except ValueError: + pass + + if not target_channel: embed = discord.Embed( title="❌ Erreur", - description="Vous devez mentionner un canal avec #", + description="Vous devez mentionner un canal avec # ou fournir un ID de salon valide.", color=discord.Color.red() ) msg = await message.channel.send(embed=embed) asyncio.create_task(delete_after_delay(msg)) return - target_channel = message.channel_mentions[0] text_to_send = parts[2] try: diff --git a/discordbot/welcome.py b/discordbot/welcome.py index d37d02d..f5e9ffe 100644 --- a/discordbot/welcome.py +++ b/discordbot/welcome.py @@ -94,7 +94,7 @@ async def sendWelcomeMessage(bot: discord.Client, member: Member): ) embed.set_thumbnail(url=member.display_avatar.url) - embed.add_field(name='Membre', value=member.mention, inline=True) + embed.add_field(name='Membre', value=member.name, inline=True) embed.add_field(name='Nombre de membres', value=str(member.guild.member_count), inline=True) embed.add_field(name='Invitation utilisée', value=invite_display, inline=False) embed.set_footer(text=f'ID: {member.id}') @@ -179,7 +179,7 @@ async def sendLeaveMessage(bot: discord.Client, member: Member): ) embed.set_thumbnail(url=member.display_avatar.url) - embed.add_field(name='Membre', value=f'{member.mention} ({member.name})', inline=True) + embed.add_field(name='Membre', value=f'**{member.name}**', inline=True) embed.add_field(name='Nombre de membres', value=str(member.guild.member_count), inline=True) embed.add_field(name='Temps sur le serveur', value=duration_text, inline=False) embed.set_footer(text=f'ID: {member.id}')