Skip to content

Commit 2f346ce

Browse files
committed
test fusion all pronos
1 parent e300642 commit 2f346ce

12 files changed

+85
-51
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-75 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-208 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

app/_app.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import json
1010
import f1api
1111
from datetime import timedelta
12+
from typing import Literal
13+
1214

1315

1416
@bot.event
@@ -37,29 +39,57 @@ async def helping_tools(interaction: discord.Interaction):
3739
# _______________________________________________________________________________________________________________________________
3840

3941

40-
@tree.command(name="pronos_course", description="Enregistre tes pronos ou modifie les si tu l'a déja fait par le passé(max 1 fois)")
41-
@app_commands.describe(premier="Le premier", deuxieme="Le deuxième", troisieme="Le troisième", best_lap="Meilleur Tour")
42-
async def submit(interaction: discord.Interaction, premier: str, deuxieme: str, troisieme: str, best_lap: str):
42+
@tree.command(name="pronos", description="Enregistre tes pronos ou modifie les si tu l'as déjà fait")
43+
@app_commands.describe(
44+
statue="Type de session (Qualif, Course, Sprint, Sprint_Qualif)",
45+
premier="Le premier",
46+
deuxieme="Le deuxième",
47+
troisieme="Le troisième",
48+
best_lap="Meilleur tour (uniquement pour Course et Sprint, optionnel pour Qualif)"
49+
)
50+
async def submit(interaction: discord.Interaction,
51+
statue: str,
52+
premier: str,
53+
deuxieme: str,
54+
troisieme: str,
55+
best_lap: str = None):
4356
await interaction.response.defer(ephemeral=True)
57+
statue_lower = statue.lower()
58+
if statue_lower not in ["Qualif", "Course", "Sprint", "Sprint_Qualif"]:
59+
await embed.Error(interaction, "❌ Statue invalide. Choisis parmi : Qualif, Course, Sprint.")
60+
return
61+
62+
if statue_lower in ["Course", "Sprint"] and not best_lap:
63+
await embed.Error(interaction, "❌ Pour Course et Sprint, le Meilleur tour est obligatoire.")
64+
return
65+
66+
# Pour Qualif, on ignore best_lap
67+
if statue_lower in ["Qualif", "Sprint_Qualif"]:
68+
best_lap = None
69+
4470
if command_enabled:
4571
try:
46-
success = pr.pronos(
72+
success = pr.pronos_race(
4773
interaction.user.id,
4874
str(interaction.user),
49-
premier, deuxieme, troisieme, best_lap
75+
premier,
76+
deuxieme,
77+
troisieme,
78+
best_lap,
79+
statue_lower
5080
)
5181
except Exception as e:
52-
logger.exception("Erreur pendant l'enregistrement du prono course")
82+
logger.exception("Erreur pendant l'enregistrement du prono")
5383
await embed.Error(interaction, f"❌ Erreur pendant l'enregistrement du prono : `{e}`")
5484
return
5585

5686
if success:
57-
await interaction.followup.send("✅ Ton prono course a bien été pris en compte !", ephemeral=True)
58-
logger.info(f'{interaction.user} à fais son pronos course')
87+
await interaction.followup.send("✅ Ton prono a bien été pris en compte !", ephemeral=True)
88+
logger.info(f'{interaction.user} a fait son pronostic {statue_lower}')
5989
else:
6090
await embed.Error(interaction, "❌ Tu ne peux modifier ton pronostic qu'une seule fois.")
6191
else:
62-
await embed.Error(interaction, "Il y a une heure pour tout faire, et celle ci n'est pas pour les pronos. Par conséquent ton prono n'a pas pu être enregistré. Si tu veux être notifié des prochaines sessions, utilise /role")
92+
await embed.Error(interaction, "Il y a une heure pour tout faire, et celle-ci n'est pas pour les pronos. Par conséquent ton prono n'a pas pu être enregistré. Si tu veux être notifié des prochaines sessions, utilise /role")
6393

6494
# _______________________________________________________________________________________________________________________________
6595

@@ -150,20 +180,20 @@ async def bannissement(interaction: discord.Interaction, member: discord.Member,
150180
# _______________________________________________________________________________________________________________________________
151181

152182

153-
@tree.command(name="admin_open", description="Ouvre une session de pronostics pour un temp donné")
154-
@app_commands.describe(duration="temps en heures")
155-
async def create(interaction: discord.Interaction, duration: float):
183+
@tree.command(name="admin_open", description="Ouvre une session de pronostics pour un temps donné")
184+
@app_commands.describe(duration="temps en heures", statue="Choix de la session")
185+
async def create(interaction: discord.Interaction, duration: float, statue: Literal["Course", "Qualif", "Sprint", "Sprint_Qualif"]):
186+
global current_session, command_enabled, auto, task
187+
156188
if interaction.user.guild_permissions.administrator:
157-
global auto
158-
if (not auto):
189+
if not auto:
159190
await interaction.response.defer()
160-
global task
161-
global command_enabled
191+
current_session = statue
162192
command_enabled = True
163-
task = asyncio.create_task(
164-
tool.start_Session(interaction, duration))
193+
task = asyncio.create_task(tool.start_Session(interaction, duration))
165194
await task
166195
command_enabled = False
196+
current_session = None # reset à la fin de la session
167197
else:
168198
await interaction.response.defer(ephemeral=True)
169199
await embed.Error(interaction, "Cette commande n'est pas disponible en mode auto")

app/error_embed.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ async def chat_Oops(interaction: discord.Interaction):
3131

3232

3333
async def info_embed(message: str, interaction: discord.Interaction):
34-
role = interaction.guild.get_role(PRONOS_ID)
3534
embed = discord.Embed(
3635
title="Infos",
3736
description=message,
@@ -42,7 +41,6 @@ async def info_embed(message: str, interaction: discord.Interaction):
4241
embed.set_image(url=EMBED_IMAGE)
4342
embed.set_thumbnail(url=EMBED_THUMBNAIL)
4443
await interaction.followup.send(
45-
content=f"||{role.mention}||",
4644
ephemeral=False,
4745
embed=embed
4846
)

app/pronos.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,41 @@ def country_fonction():
2828
return "Unknown" # fallback par défaut si rien trouvé
2929

3030

31-
def pronos(id: int, pseudo: str, premier: str, second: str, troisieme: str, bt: str):
3231

32+
def pronos_generic(pseudo, premier, second, troisieme, statue, best_lap=None):
3333
country = country_fonction()
34-
file_path = f'data/pronos_{country}.json'
34+
35+
if statue == "qualif":
36+
file_path = f'data/pronos_{country}_qualifs.json'
37+
elif statue == "sprint":
38+
file_path = f'data/pronos_{country}_sprint.json'
39+
elif statue == "qualif_sprint":
40+
file_path = f'data/pronos_{country}_qualifsprint.json'
41+
else:
42+
file_path = f'data/pronos_{country}.json'
3543

3644
if not os.path.exists(file_path):
37-
pronos_database = {
38-
str(id): {
39-
"Pseudo": pseudo,
40-
"1": premier,
41-
"2": second,
42-
"3": troisieme,
43-
"Best Lap": bt,
44-
"Modif": False
45-
}
46-
}
45+
pronos_database = {}
4746
else:
4847
with open(file_path, 'r', encoding='utf-8') as f:
4948
pronos_database = json.load(f)
50-
if str(id) not in pronos_database:
51-
pronos_database[str(id)] = {
52-
"Pseudo": pseudo,
53-
"1": premier,
54-
"2": second,
55-
"3": troisieme,
56-
"Best Lap": bt,
57-
"Modif": False
58-
}
59-
else:
60-
if pronos_database[str(id)]["Modif"]:
61-
return False
62-
else:
6349

64-
pronos_database[str(id)]["Pseudo"] = pseudo
65-
pronos_database[str(id)]["1"] = premier
66-
pronos_database[str(id)]["2"] = second
67-
pronos_database[str(id)]["3"] = troisieme
68-
pronos_database[str(id)]["Best Lap"] = bt
69-
pronos_database[str(id)]["Modif"] = True
50+
user_key = pseudo # ou id si tu as
51+
52+
pronos_database[user_key] = {
53+
"Pseudo": pseudo,
54+
"1": premier,
55+
"2": second,
56+
"3": troisieme,
57+
"Modif": False
58+
}
59+
60+
if statue in ["course", "sprint"]:
61+
pronos_database[user_key]["Best Lap"] = best_lap
7062

7163
with open(file_path, 'w', encoding='utf-8') as f:
7264
json.dump(pronos_database, f, ensure_ascii=False, indent=4)
65+
7366
return True
7467

7568

0 commit comments

Comments
 (0)