From a3c71800afd6a6e72a0535369d44b173411a0dee Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Tue, 11 Mar 2025 22:04:03 +0100 Subject: [PATCH] =?UTF-8?q?D=C3=A9fis=20de=20comp=C3=A9tition=20et=20remis?= =?UTF-8?q?age?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bot.py b/bot.py index 762e8ba..82e94a3 100755 --- a/bot.py +++ b/bot.py @@ -229,6 +229,33 @@ async def tirage(ctx: commands.Context, nb_defis: int = 5): 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 competition(ctx: commands.Context): + defi_competition = random.choice([defi for defi in DEFIS['competition'] if defi['id'] not in data['defis']['tires_competition']]) + data['defis']['tires_competition'].append(defi_competition['id']) + embed = discord.Embed(title=defi_competition['nom'], description=defi_competition['description']) + embed.set_footer(text=f"Défi de compétition n°{defi_competition['id']}") + with DATA_FILE.open('w') as data_file: + json.dump(data, data_file, indent=2) + await ctx.send("@everyone Un canton est attaqué ! L'équipe vainqueure de ce défi conservera son contrôle jusqu'à la fin du jeu :", embed=embed) + + +@bot.command() +async def remiser(ctx: commands.Context, type_defi: Literal['capture', 'competition'] = "capture", id_defi: int | None = None): + defis = DEFIS[type_defi] + try: + defi = next(defi for defi in defis if defi['id'] == id_defi) + except StopIteration: + raise commands.BadArgument(f"Le défi de {type_defi} n°{id_defi} n'existe pas.") + if id_defi in data['defis'][f'tires_{type_defi}']: + data['defis'][f'tires_{type_defi}'].remove(id_defi) + with DATA_FILE.open('w') as data_file: + json.dump(data, data_file, indent=2) + await ctx.reply(f"Le défi de {type_defi} n°{id_defi} ({defi['nom']}) a été retiré de la défausse et pourra à nouveau être tiré au sort.") + else: + await ctx.reply(f"Le défi de {type_defi} n°{id_defi} ({defi['nom']}) n'était déjà pas dans la défausse.") + + @bot.command(name="main") async def afficher_main(ctx: commands.Context, mode: Literal['public', 'prive'] = "prive", author_id: int | None = None): author_id = author_id or ctx.author.id @@ -404,6 +431,8 @@ async def save(ctx: commands.Context): @defis.error @description.error @tirage.error +@competition.error +@remiser.error @afficher_main.error @terminer.error @echange.error