Ajout support des powerups
This commit is contained in:
parent
e74184a4ce
commit
67650bcd60
39
bot.py
39
bot.py
@ -69,6 +69,7 @@ else:
|
|||||||
'cantons': {code_canton: {'capture': None, 'verrouille': False} for code_canton in CANTONS.keys()},
|
'cantons': {code_canton: {'capture': None, 'verrouille': False} for code_canton in CANTONS.keys()},
|
||||||
'defis': {
|
'defis': {
|
||||||
'mains': {equipe: [] for equipe in EQUIPES},
|
'mains': {equipe: [] for equipe in EQUIPES},
|
||||||
|
'powerups': {equipe: 0 for equipe in EQUIPES},
|
||||||
'tires_capture': [],
|
'tires_capture': [],
|
||||||
'tires_competition': [],
|
'tires_competition': [],
|
||||||
}
|
}
|
||||||
@ -197,7 +198,7 @@ async def description(ctx: commands.Context, type_defi: Literal['capture', 'comp
|
|||||||
defi = next(defi for defi in defis if defi['id'] == id_defi)
|
defi = next(defi for defi in defis if defi['id'] == id_defi)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise commands.BadArgument(f"Le défi de {type_defi} n°{id_defi} n'existe pas.")
|
raise commands.BadArgument(f"Le défi de {type_defi} n°{id_defi} n'existe pas.")
|
||||||
embed.add_field(name=f"{defi['nom']}", value=defi['description'], inline=False)
|
embed.add_field(name=f"{defi['nom']} {defi['powerups'] * ":star:"}", value=defi['description'], inline=False)
|
||||||
embeds.append(embed)
|
embeds.append(embed)
|
||||||
else:
|
else:
|
||||||
for page in range((len(defis) - 1) // 25 + 1):
|
for page in range((len(defis) - 1) // 25 + 1):
|
||||||
@ -205,7 +206,7 @@ async def description(ctx: commands.Context, type_defi: Literal['capture', 'comp
|
|||||||
embed = discord.Embed(title=f"Description des défis", colour=discord.Colour.gold())
|
embed = discord.Embed(title=f"Description des défis", colour=discord.Colour.gold())
|
||||||
embed.set_footer(text=f"Page {page + 1}/{(len(defis) - 1) // 25 + 1}")
|
embed.set_footer(text=f"Page {page + 1}/{(len(defis) - 1) // 25 + 1}")
|
||||||
for defi in defis_page:
|
for defi in defis_page:
|
||||||
embed.add_field(name=f"{defi['nom']} (n°{defi['id']})", value=defi['description'], inline=False)
|
embed.add_field(name=f"{defi['nom']} {defi['powerups'] * ":star:"} (n°{defi['id']})", value=defi['description'], inline=False)
|
||||||
embeds.append(embed)
|
embeds.append(embed)
|
||||||
await ctx.send(embeds=embeds)
|
await ctx.send(embeds=embeds)
|
||||||
|
|
||||||
@ -283,18 +284,19 @@ async def afficher_main(ctx: commands.Context, mode: Literal['public', 'prive']
|
|||||||
raise commands.BadArgument(f"Vous n'appartez à aucune équipe. Merci de faire `{PREFIX}equipe [{"|".join(EQUIPES)}]`.")
|
raise commands.BadArgument(f"Vous n'appartez à aucune équipe. Merci de faire `{PREFIX}equipe [{"|".join(EQUIPES)}]`.")
|
||||||
|
|
||||||
main = data['defis']['mains'][couleur]
|
main = data['defis']['mains'][couleur]
|
||||||
|
nb_powerups = data['defis']['powerups'][couleur]
|
||||||
embeds = []
|
embeds = []
|
||||||
colour = discord.Color.red() if couleur == "rouge" else discord.Color.green()
|
colour = discord.Color.red() if couleur == "rouge" else discord.Color.green()
|
||||||
for id_defi in main:
|
for id_defi in main:
|
||||||
defi = next(defi for defi in DEFIS['capture'] if defi['id'] == id_defi)
|
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 = discord.Embed(title=f"{defi['nom']} {defi['powerups'] * ":star:"}", description=defi['description'], colour=colour)
|
||||||
embed.set_footer(text=f"Défi n°{defi['id']}")
|
embed.set_footer(text=f"Défi n°{defi['id']}")
|
||||||
embeds.append(embed)
|
embeds.append(embed)
|
||||||
if mode == "public":
|
if mode == "public":
|
||||||
await ctx.send(f"Défis de l'équipe **{couleur}** :", embeds=embeds)
|
await ctx.send(f"Défis de l'équipe **{couleur}** :", embeds=embeds)
|
||||||
else:
|
else:
|
||||||
channel_dm = await bot.create_dm(namedtuple('User', 'id')(author_id))
|
channel_dm = await bot.create_dm(namedtuple('User', 'id')(author_id))
|
||||||
await channel_dm.send("Vos défis en main :", embeds=embeds, view=MainView(ctx, author_id, main))
|
await channel_dm.send(f"Vous disposez de **{nb_powerups} powerup{"s" if nb_powerups >= 2 else ""} {nb_powerups * ":star:"}**.\nVos défis en main :", embeds=embeds, view=MainView(ctx, author_id, main))
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@ -317,19 +319,45 @@ async def terminer(ctx: commands.Context, id_defi: int, author_id: int | None =
|
|||||||
main.remove(id_defi)
|
main.remove(id_defi)
|
||||||
main.append(nouveau_defi['id'])
|
main.append(nouveau_defi['id'])
|
||||||
data['defis']['tires_capture'].append(nouveau_defi['id'])
|
data['defis']['tires_capture'].append(nouveau_defi['id'])
|
||||||
|
data['defis']['powerups'][equipe] += defi['powerups']
|
||||||
with DATA_FILE.open('w') as data_file:
|
with DATA_FILE.open('w') as data_file:
|
||||||
json.dump(data, data_file, indent=2)
|
json.dump(data, data_file, indent=2)
|
||||||
|
|
||||||
channel = channel or ctx
|
channel = channel or ctx
|
||||||
await channel.send(f"Défi n°{id_defi} **{defi['nom']}** terminé ! Il est retiré de votre main.")
|
await channel.send(f"Défi n°{id_defi} **{defi['nom']}** terminé ! Il est retiré de votre main.")
|
||||||
|
await channel.send(f"Votre équipe gagne **{defi['powerups']} powerup{"s" if defi['powerups'] >= 2 else ""}**. Vous en possédez désormais {data['defis']['powerups'][equipe]}.")
|
||||||
colour = discord.Color.red() if equipe == "rouge" else discord.Color.green()
|
colour = discord.Color.red() if equipe == "rouge" else discord.Color.green()
|
||||||
embed = discord.Embed(title=nouveau_defi['nom'], description=nouveau_defi['description'], colour=colour)
|
embed = discord.Embed(title=f"{nouveau_defi['nom']} {defi['powerups'] * ":star:"}", description=nouveau_defi['description'], colour=colour)
|
||||||
embed.set_footer(text=f"Défi n°{nouveau_defi['id']}")
|
embed.set_footer(text=f"Défi n°{nouveau_defi['id']}")
|
||||||
await channel.send("**Votre nouveau défi en main :**", embed=embed)
|
await channel.send("**Votre nouveau défi en main :**", embed=embed)
|
||||||
for member_id in data['equipes'][equipe]:
|
for member_id in data['equipes'][equipe]:
|
||||||
await afficher_main(ctx, author_id=member_id)
|
await afficher_main(ctx, author_id=member_id)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
async def powerup(ctx: commands.Context, equipe: Couleur | None = None, nouvelle_valeur: int | None = None):
|
||||||
|
if equipe is None:
|
||||||
|
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)}]`.")
|
||||||
|
|
||||||
|
nb_powerups = data['defis']['powerups'][equipe]
|
||||||
|
if nouvelle_valeur is None:
|
||||||
|
if nb_powerups >= 1:
|
||||||
|
data['defis']['powerups'][equipe] -= 1
|
||||||
|
await ctx.send(f"L'équipe **{equipe}** vient d'utiliser un powerup !")
|
||||||
|
else:
|
||||||
|
await ctx.reply(f"Vous n'avez plus de powerup.", ephemeral=True)
|
||||||
|
else:
|
||||||
|
data['defis']['powerups'][equipe] = nouvelle_valeur
|
||||||
|
await ctx.send(f"L'équipe **{equipe}** a désormais **{nouvelle_valeur} powerup{"s" if nouvelle_valeur >= 2 else ""}**, contre {nb_powerups} auparavant.")
|
||||||
|
with DATA_FILE.open('w') as data_file:
|
||||||
|
json.dump(data, data_file, indent=2)
|
||||||
|
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def echange(ctx: commands.Context, id_defi_1: int, id_defi_2: int):
|
async def echange(ctx: commands.Context, id_defi_1: int, id_defi_2: int):
|
||||||
if all(id_defi_1 != defi['id'] for defi in DEFIS['capture']):
|
if all(id_defi_1 != defi['id'] for defi in DEFIS['capture']):
|
||||||
@ -462,6 +490,7 @@ async def save(ctx: commands.Context):
|
|||||||
@remiser.error
|
@remiser.error
|
||||||
@afficher_main.error
|
@afficher_main.error
|
||||||
@terminer.error
|
@terminer.error
|
||||||
|
@powerup.error
|
||||||
@echange.error
|
@echange.error
|
||||||
@melanger.error
|
@melanger.error
|
||||||
@de.error
|
@de.error
|
||||||
|
48
defis.json
48
defis.json
@ -3,82 +3,98 @@
|
|||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"nom": "Défi 1",
|
"nom": "Défi 1",
|
||||||
"description": "Défi 1"
|
"description": "Défi 1",
|
||||||
|
"powerups": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"nom": "Défi 2",
|
"nom": "Défi 2",
|
||||||
"description": "Défi 2"
|
"description": "Défi 2",
|
||||||
|
"powerups": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"nom": "Défi 3",
|
"nom": "Défi 3",
|
||||||
"description": "Défi 3"
|
"description": "Défi 3",
|
||||||
|
"powerups": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 4,
|
"id": 4,
|
||||||
"nom": "Défi 4",
|
"nom": "Défi 4",
|
||||||
"description": "Défi 4"
|
"description": "Défi 4",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"nom": "Défi 5",
|
"nom": "Défi 5",
|
||||||
"description": "Défi 5"
|
"description": "Défi 5",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
"nom": "Défi 6",
|
"nom": "Défi 6",
|
||||||
"description": "Défi 6"
|
"description": "Défi 6",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 7,
|
"id": 7,
|
||||||
"nom": "Défi 7",
|
"nom": "Défi 7",
|
||||||
"description": "Défi 7"
|
"description": "Défi 7",
|
||||||
|
"powerups": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 8,
|
"id": 8,
|
||||||
"nom": "Défi 8",
|
"nom": "Défi 8",
|
||||||
"description": "Défi 8"
|
"description": "Défi 8",
|
||||||
|
"powerups": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 9,
|
"id": 9,
|
||||||
"nom": "Défi 9",
|
"nom": "Défi 9",
|
||||||
"description": "Défi 9"
|
"description": "Défi 9",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 10,
|
"id": 10,
|
||||||
"nom": "Défi 10",
|
"nom": "Défi 10",
|
||||||
"description": "Défi 10"
|
"description": "Défi 10",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 11,
|
"id": 11,
|
||||||
"nom": "Défi 11",
|
"nom": "Défi 11",
|
||||||
"description": "Défi 11"
|
"description": "Défi 11",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 12,
|
"id": 12,
|
||||||
"nom": "Défi 12",
|
"nom": "Défi 12",
|
||||||
"description": "Défi 12"
|
"description": "Défi 12",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 13,
|
"id": 13,
|
||||||
"nom": "Défi 13",
|
"nom": "Défi 13",
|
||||||
"description": "Défi 13"
|
"description": "Défi 13",
|
||||||
|
"powerups": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 14,
|
"id": 14,
|
||||||
"nom": "Défi 14",
|
"nom": "Défi 14",
|
||||||
"description": "Défi 14"
|
"description": "Défi 14",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 15,
|
"id": 15,
|
||||||
"nom": "Défi 15",
|
"nom": "Défi 15",
|
||||||
"description": "Défi 15"
|
"description": "Défi 15",
|
||||||
|
"powerups": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 16,
|
"id": 16,
|
||||||
"nom": "Défi 16",
|
"nom": "Défi 16",
|
||||||
"description": "Défi 16"
|
"description": "Défi 16",
|
||||||
|
"powerups": 2
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"competition": [
|
"competition": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user