Skip to content

Commit c2c6206

Browse files
committed
economie call
1 parent 2f346ce commit c2c6206

File tree

10 files changed

+131
-1
lines changed

10 files changed

+131
-1
lines changed

TODO.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818

1919
---
2020

21+
## 🪙 Economie du serveur
22+
- [ ] création de la banque centrale avec la gestion des données
23+
- [ ] capacité d'utiliser sont argent + récompense
24+
- [ ] commande de management de l'économie du serveur
25+
2126
## 🧹 Nettoyage & Sécurité
2227

2328
- [ ] Supprimer la commande ban du bot
37 Bytes
Binary file not shown.
3.28 KB
Binary file not shown.
-183 Bytes
Binary file not shown.

app/_app.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import f1api
1111
from datetime import timedelta
1212
from typing import Literal
13+
import economie as eco
1314

1415

1516

@@ -451,5 +452,23 @@ async def next_event(interaction: discord.Interaction):
451452

452453
except Exception as e:
453454
await interaction.followup.send(f"❌ Une erreur est survenue : {e}")
455+
456+
# _______________________________________________________________________________________________________________________________
457+
458+
459+
@tree.command(name="salaire", description="Te permet de récupérer ton salaire journalié")
460+
async def paye(interaction: discord.Interaction):
461+
await interaction.response.defer()
462+
msg = eco.salaire(interaction)
463+
await interaction.followup.send(msg, ephemeral=True)
464+
logger.info(f"{interaction.user} a demandé son salaire journalié")
465+
466+
# _______________________________________________________________________________________________________________________________
467+
468+
@tree.command(name="solde", description="Te permet de voir ton solde actuelle")
469+
async def solding(interaction: discord.Interaction):
470+
await interaction.response.defer()
471+
await eco.voir_solde(interaction)
472+
logger.info(f"{interaction.user} a regardé son solde")
454473

455474
bot.run(TOKEN)

app/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@
6363
PRONOS_ID = 1398238150215860345
6464
GUILD_ID = 1394054995523010761
6565
ROLE_ID_F1PADDOCKCLUB = 992784555150946446
66+
67+
# === 🪙 Bot et Tree pour les commandes slash ===
68+
SALAIRE_JOURNALIER = 100

app/economie.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
import json
3+
import discord
4+
from datetime import datetime
5+
6+
from config import SALAIRE_JOURNALIER
7+
8+
file_path = 'data/eco/central_account.json'
9+
10+
def salaire(interaction: discord.Interaction):
11+
12+
# Chargement ou création du fichier
13+
if not os.path.exists(file_path):
14+
central_account = {}
15+
else:
16+
with open(file_path, 'r', encoding='utf-8') as f:
17+
central_account = json.load(f)
18+
19+
user_id = str(interaction.user.id)
20+
username = interaction.user.name
21+
today = datetime.now().date()
22+
23+
# Si l'utilisateur est nouveau, on initialise son compte
24+
if user_id not in central_account:
25+
central_account[user_id] = {
26+
"Pseudo": username,
27+
"Solde": SALAIRE_JOURNALIER,
28+
"last_claim": str(today)
29+
}
30+
message = f"💸 Premier salaire reçu ! Tu as obtenu {SALAIRE_JOURNALIER} 💰."
31+
else:
32+
# Récupération de la dernière date de versement
33+
last_claim_str = central_account[user_id].get("last_claim", "2000-01-01")
34+
last_claim = datetime.strptime(last_claim_str, "%Y-%m-%d").date()
35+
36+
if last_claim < today:
37+
# L'utilisateur peut réclamer son salaire
38+
central_account[user_id]["Solde"] += SALAIRE_JOURNALIER
39+
central_account[user_id]["last_claim"] = str(today)
40+
message = f"💰 Salaire journalier reçu ! +{SALAIRE_JOURNALIER} 💸"
41+
else:
42+
# Il a déjà réclamé aujourd'hui
43+
message = "⏳ Tu as déjà reçu ton salaire aujourd’hui. Reviens demain !"
44+
45+
# Sauvegarde
46+
with open(file_path, 'w', encoding='utf-8') as f:
47+
json.dump(central_account, f, indent=4, ensure_ascii=False)
48+
49+
return message
50+
51+
52+
async def voir_solde(interaction: discord.Interaction):
53+
user_id = str(interaction.user.id)
54+
55+
if not os.path.exists(file_path):
56+
message = "Désolé, mais tu n'as rien sur ton compte. Fais la commande `/salaire` pour obtenir ton premier salaire."
57+
else:
58+
with open(file_path, 'r', encoding='utf-8') as f:
59+
soldes = json.load(f)
60+
61+
user_data = soldes.get(user_id)
62+
if user_data is None:
63+
message = "Désolé, mais tu n'as rien sur ton compte. Fais la commande `/salaire` pour obtenir ton premier salaire."
64+
else:
65+
solde = user_data.get("Solde", 0)
66+
message = f"💰 Ton solde actuel est de **{solde}** coins."
67+
68+
await interaction.followup.send(message, ephemeral=True)

data/eco/central_account.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"1200489866165747722": {
3+
"Pseudo": "matt_karting",
4+
"Solde": 200,
5+
"last_claim": "2025-07-29"
6+
}
7+
}

data/pronos_Belgium_sprint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"2": "a",
66
"3": "a",
77
"Best Lap": "a",
8-
"Modif": false
8+
"Modif": true
99
}
1010
}

log/app.log

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,31 @@ TypeError: pronos() missing 1 required positional argument: 'bt'
426426
2025-07-25 16:25:32,575 - INFO - BOT LANCER
427427
2025-07-25 16:33:41,818 - INFO - BOT LANCER
428428
2025-07-25 16:34:49,280 - INFO - BOT LANCER
429+
2025-07-26 00:56:42,870 - INFO - BOT LANCER
430+
2025-07-26 00:59:07,972 - INFO - matt_karting a demandé /help dans général
431+
2025-07-26 01:00:48,451 - INFO - matt_karting à fais son pronos course sprint
432+
2025-07-26 01:01:33,642 - INFO - matt_karting à visualisé ses pronos.
433+
2025-07-26 01:02:40,819 - INFO - matt_karting à regarder le leaderbord
434+
2025-07-26 01:04:52,960 - INFO - Présentation par matt_karting dans général sur TEST F1F
435+
2025-07-26 01:04:52,960 - INFO - matt_karting a demandé la présentation du BOT
436+
2025-07-26 01:05:08,571 - INFO - matt_karting a demandé les règles du BOT.
437+
2025-07-26 08:37:57,631 - INFO - BOT LANCER
438+
2025-07-26 08:59:58,720 - INFO - BOT LANCER
439+
2025-07-26 09:02:05,808 - INFO - BOT LANCER
440+
2025-07-26 09:03:48,135 - INFO - BOT LANCER
441+
2025-07-26 09:04:31,048 - INFO - BOT LANCER
442+
2025-07-26 09:04:36,038 - INFO - matt_karting a demandé son salaire journalié
443+
2025-07-26 09:05:05,665 - INFO - matt_karting a demandé son salaire journalié
444+
2025-07-26 09:05:21,779 - INFO - matt_karting a demandé son salaire journalié
445+
2025-07-26 09:18:34,905 - INFO - BOT LANCER
446+
2025-07-26 09:19:59,361 - INFO - BOT LANCER
447+
2025-07-26 09:20:29,015 - INFO - matt_karting a demandé son salaire journalié
448+
2025-07-26 09:20:34,877 - INFO - matt_karting a regardé son solde
449+
2025-07-26 11:12:24,542 - INFO - BOT LANCER
450+
2025-07-26 16:18:03,018 - INFO - BOT LANCER
451+
2025-07-27 11:23:23,851 - INFO - BOT LANCER
452+
2025-07-27 20:33:20,083 - INFO - BOT LANCER
453+
2025-07-29 11:14:09,994 - INFO - BOT LANCER
454+
2025-07-29 11:14:16,799 - INFO - matt_karting a demandé son salaire journalié
455+
2025-07-29 11:14:21,247 - INFO - matt_karting a demandé son salaire journalié
456+
2025-07-29 11:14:40,193 - INFO - matt_karting a regardé son solde

0 commit comments

Comments
 (0)