Ajout mélange de main
This commit is contained in:
parent
3f0ba14166
commit
3cd8bf82dc
70
bot.py
70
bot.py
@ -210,7 +210,7 @@ async def description(ctx: commands.Context, type_defi: Literal['capture', 'comp
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def tirage(ctx: commands.Context, nb_defis: int = 7):
|
||||
async def tirage(ctx: commands.Context, nb_defis: int = 5):
|
||||
if any(data['defis']['mains'][equipe] for equipe in EQUIPES):
|
||||
raise commands.BadArgument("Les mains sont déjà initialisées")
|
||||
|
||||
@ -230,7 +230,7 @@ async def tirage(ctx: commands.Context, nb_defis: int = 7):
|
||||
|
||||
|
||||
@bot.command(name="main")
|
||||
async def afficher_main(ctx: commands.Context, author_id: int | None = None):
|
||||
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
|
||||
for couleur, membres_equipe in data['equipes'].items():
|
||||
if author_id in membres_equipe:
|
||||
@ -246,8 +246,11 @@ async def afficher_main(ctx: commands.Context, author_id: int | None = None):
|
||||
embed = discord.Embed(title=defi['nom'], description=defi['description'], colour=colour)
|
||||
embed.set_footer(text=f"Défi n°{defi['id']}")
|
||||
embeds.append(embed)
|
||||
channel_dm = await bot.create_dm(ctx.author)
|
||||
await channel_dm.send("Vos défis en main :", embeds=embeds)
|
||||
if mode == "public":
|
||||
await ctx.send(f"Défis de l'équipe **{couleur}** :", embeds=embeds)
|
||||
else:
|
||||
channel_dm = await bot.create_dm(ctx.author)
|
||||
await channel_dm.send("Vos défis en main :", embeds=embeds)
|
||||
|
||||
|
||||
@bot.command()
|
||||
@ -330,13 +333,57 @@ async def echange(ctx: commands.Context, id_defi_1: int, id_defi_2: int):
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def debug(ctx: commands.Context, key: Literal['equipes', 'cantons', 'defis']):
|
||||
data_json = json.dumps(data[key], indent=4)
|
||||
await ctx.reply(f"```json\n{data_json}\n```", ephemeral=True)
|
||||
async def melanger(ctx: commands.Context, nb_defis: int = 5):
|
||||
author_id = ctx.author.id
|
||||
for equipe, membres_equipe in data['equipes'].items():
|
||||
if author_id in membres_equipe:
|
||||
break
|
||||
else:
|
||||
raise commands.BadArgument(f"Vous n'appartez à aucune équipe. Merci de faire `{PREFIX}equipe [{"|".join(EQUIPES)}]`.")
|
||||
|
||||
main = data['defis']['mains'][equipe]
|
||||
|
||||
for _i in range(nb_defis):
|
||||
nouveau_defi = random.choice([defi for defi in DEFIS['capture'] if defi['id'] not in data['defis']['tires_capture']])
|
||||
main.append(nouveau_defi['id'])
|
||||
data['defis']['tires_capture'].append(nouveau_defi['id'])
|
||||
with DATA_FILE.open('w') as data_file:
|
||||
json.dump(data, data_file, indent=2)
|
||||
|
||||
await ctx.send(f"Main de l'équipe {equipe} mélangée !")
|
||||
for member_id in data['equipes'][equipe]:
|
||||
await afficher_main(ctx, author_id=member_id)
|
||||
|
||||
|
||||
async def de(ctx: commands.Context, nb_faces: int = 6):
|
||||
resultat = random.randint(1, nb_faces + 1)
|
||||
await ctx.reply(f":dice: Résultat du dé à {nb_faces} faces : **{resultat}**")
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def debug(ctx: commands.Context, keys: str, *, set_value: str | None = None):
|
||||
keys = keys.split('.')
|
||||
parent = None
|
||||
out = data
|
||||
for key in keys:
|
||||
if key not in out:
|
||||
raise commands.BadArgument(f"Clé {key} absente du dictionnaire, valeurs possibles : {out.keys()}")
|
||||
parent = out
|
||||
last_key = key
|
||||
out = out[key]
|
||||
data_json = json.dumps(out, indent=2)
|
||||
if set_value is None:
|
||||
await ctx.reply(f"```json\n{data_json}\n```", ephemeral=True)
|
||||
else:
|
||||
new_data = json.loads(set_value)
|
||||
new_data_json = json.dumps(new_data, indent=2)
|
||||
parent[last_key] = new_data
|
||||
await ctx.reply(f"Anciennes données :\n```json\n{data_json}\n```Nouvelles données :\n```json\n{new_data_json}\n```\nFaites `{PREFIX}save` pour sauvegarder, ou `{PREFIX}` reload pour rollback.", ephemeral=True)
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def reload(ctx: commands.Context):
|
||||
global data, DEFIS
|
||||
with DATA_FILE.open() as data_file:
|
||||
data = json.load(data_file)
|
||||
with DEFIS_FILE.open() as defis_file:
|
||||
@ -344,6 +391,13 @@ async def reload(ctx: commands.Context):
|
||||
await ctx.reply("Configuration rechargée.", ephemeral=True)
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def save(ctx: commands.Context):
|
||||
with DATA_FILE.open('w') as data_file:
|
||||
json.dump(data, data_file, indent=2)
|
||||
await ctx.reply("Configuration sauvegardée.", ephemeral=True)
|
||||
|
||||
|
||||
@carte.error
|
||||
@reset.error
|
||||
@equipe.error
|
||||
@ -353,8 +407,10 @@ async def reload(ctx: commands.Context):
|
||||
@afficher_main.error
|
||||
@terminer.error
|
||||
@echange.error
|
||||
@melanger.error
|
||||
@debug.error
|
||||
@reload.error
|
||||
@save.error
|
||||
async def on_error(ctx, error):
|
||||
with DATA_FILE.open() as data_file:
|
||||
data = json.load(data_file)
|
||||
|
Loading…
x
Reference in New Issue
Block a user