From 273dc88daa1d59e6dc739607f2b3eb075f400196 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Tue, 11 Mar 2025 18:13:30 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20commande=20de=20debug=20pour=20?= =?UTF-8?q?afficher=20l'=C3=A9tat=20de=20la=20m=C3=A9moire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/bot.py b/bot.py index 8165b6a..10ac2ba 100755 --- a/bot.py +++ b/bot.py @@ -210,25 +210,16 @@ async def tirage(ctx: commands.Context, nb_defis: int = 7): data['defis']['mains'][equipe].append(defi['id']) data['defis']['tires_capture'].append(defi['id']) - main = data['defis']['mains'][equipe] - embeds = [] - colour = discord.Color.red() if equipe == "rouge" else discord.Color.green() - for id_defi in main: - defi = next(defi for defi in DEFIS['capture'] if defi['id'] == id_defi) - embed = discord.Embed(title=defi['nom'], description=defi['description'], colour=colour) - embed.set_footer(text=f"Défi n°{defi['id']}") - embeds.append(embed) for member_id in data['equipes'][equipe]: - channel_dm = await bot.create_dm(namedtuple("User", "id")(member_id)) - await channel_dm.send("Vos défis en main :", embeds=embeds) + await main(ctx, author_id=member_id) with DATA_FILE.open('w') as data_file: json.dump(data, data_file, indent=2) await ctx.send("Les mains de départ ont bien été tirées ! Le contenu vous a été envoyé en MP.") @bot.command() -async def main(ctx: commands.Context): - author_id = ctx.author.id +async def main(ctx: commands.Context, *, author_id: int | None = None): + author_id = author_id or ctx.author.id for couleur, membres_equipe in data['equipes'].items(): if author_id in membres_equipe: break @@ -247,8 +238,21 @@ async def main(ctx: commands.Context): await channel_dm.send("Vos défis en main :", embeds=embeds) +@bot.command() +async def debug(ctx: commands.Context, key: Literal['equipes', 'cantons', 'defis']): + data_json = json.dumps(data[key], indent=4) + await ctx.send(f"```json\n{data_json}\n```") + + +@carte.error +@reset.error @equipe.error -async def equipe_error(ctx, error): +@defis.error +@description.error +@tirage.error +@main.error +@debug.error +async def on_error(ctx, error): await ctx.send(str(error))