2026-08-16 19:37:15 +02:00
|
|
|
import discord
|
|
|
|
|
from discord import app_commands
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
import json
|
|
|
|
|
import math
|
Modularize bot: per-guild config system for roles/channels/categories
- Add utils/guild_config.py: centralized config loader per guild (data/guilds/{id}.json)
- Add commandes/config.py: /config set_role, /config set_channel, /config set_category, /config voir, /config reset
- Replace ALL hardcoded role IDs (banquier, gouvernement, citoyen, staff, ems, permis, fbm, ursaff, etc.) with guild_config lookups
- Replace ALL hardcoded channel IDs (welcome, candidature, questions, mp_reception) with guild_config lookups
- Replace ALL hardcoded category IDs (ticket) with guild_config lookups
- Remove duplicate commandes/welcome_message.py (kept utils/ version)
- Remove 20+ hardcoded snowflake IDs across 22 files
- Guilds configure via /config on Discord, no code changes needed
2026-08-17 00:12:57 +02:00
|
|
|
from utils.guild_config import has_role
|
2026-08-16 19:37:15 +02:00
|
|
|
|
|
|
|
|
class CompteFBM(commands.Cog):
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
|
|
def get_all_transactions(self):
|
|
|
|
|
try:
|
|
|
|
|
with open("comptes_entreprises.json", "r", encoding="utf-8") as f:
|
|
|
|
|
data = json.load(f)
|
|
|
|
|
fbm_data = data.setdefault("fbm", {}).setdefault("FBM", {
|
|
|
|
|
"solde": 0.0,
|
|
|
|
|
"transactions": []
|
|
|
|
|
})
|
|
|
|
|
return fbm_data["solde"], fbm_data["transactions"]
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Erreur lecture comptes_entreprises.json : {e}")
|
|
|
|
|
return 0.0, []
|
|
|
|
|
|
|
|
|
|
@app_commands.command(name="compte_fbm", description="Affiche le solde et l'historique du compte FBM (réservé au personnel FBM).")
|
|
|
|
|
async def compte_fbm(self, interaction: discord.Interaction):
|
Modularize bot: per-guild config system for roles/channels/categories
- Add utils/guild_config.py: centralized config loader per guild (data/guilds/{id}.json)
- Add commandes/config.py: /config set_role, /config set_channel, /config set_category, /config voir, /config reset
- Replace ALL hardcoded role IDs (banquier, gouvernement, citoyen, staff, ems, permis, fbm, ursaff, etc.) with guild_config lookups
- Replace ALL hardcoded channel IDs (welcome, candidature, questions, mp_reception) with guild_config lookups
- Replace ALL hardcoded category IDs (ticket) with guild_config lookups
- Remove duplicate commandes/welcome_message.py (kept utils/ version)
- Remove 20+ hardcoded snowflake IDs across 22 files
- Guilds configure via /config on Discord, no code changes needed
2026-08-17 00:12:57 +02:00
|
|
|
if not has_role(interaction.user, "fbm"):
|
2026-08-16 19:37:15 +02:00
|
|
|
await interaction.response.send_message("❌ Vous n'avez pas la permission d'accéder à ce compte.", ephemeral=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
solde, transactions = self.get_all_transactions()
|
|
|
|
|
|
|
|
|
|
if not transactions:
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
title="📄 Compte FBM",
|
|
|
|
|
description="Aucune transaction enregistrée.",
|
|
|
|
|
color=discord.Color.orange()
|
|
|
|
|
)
|
|
|
|
|
embed.add_field(name="💰 Solde actuel", value=f"{solde:.2f}€", inline=False)
|
|
|
|
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Pagination
|
|
|
|
|
pages = []
|
|
|
|
|
per_page = 5
|
|
|
|
|
total_pages = math.ceil(len(transactions) / per_page)
|
|
|
|
|
|
|
|
|
|
for i in range(total_pages):
|
|
|
|
|
start = i * per_page
|
|
|
|
|
end = start + per_page
|
|
|
|
|
chunk = transactions[start:end]
|
|
|
|
|
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
title="📄 Historique FBM",
|
|
|
|
|
description=f"Page {i+1}/{total_pages}",
|
|
|
|
|
color=discord.Color.orange()
|
|
|
|
|
)
|
|
|
|
|
embed.add_field(name="💰 Solde actuel", value=f"{solde:.2f}€", inline=False)
|
|
|
|
|
|
|
|
|
|
for tx in chunk:
|
|
|
|
|
desc = (
|
|
|
|
|
f"**Date**: {tx.get('date', 'N/A')}\n"
|
|
|
|
|
f"**Type**: {tx.get('type', 'N/A')}\n"
|
|
|
|
|
f"**Montant**: {tx.get('montant', 0)}€\n"
|
|
|
|
|
f"**Source**: {tx.get('source', 'N/A')}"
|
|
|
|
|
)
|
|
|
|
|
embed.add_field(name="🔸 Transaction", value=desc, inline=False)
|
|
|
|
|
|
|
|
|
|
pages.append(embed)
|
|
|
|
|
|
|
|
|
|
class Pagination(discord.ui.View):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__(timeout=None)
|
|
|
|
|
self.current = 0
|
|
|
|
|
|
|
|
|
|
@discord.ui.button(label="⬅️", style=discord.ButtonStyle.grey)
|
|
|
|
|
async def previous(self, interaction_btn: discord.Interaction, button: discord.ui.Button):
|
|
|
|
|
if self.current > 0:
|
|
|
|
|
self.current -= 1
|
|
|
|
|
await interaction_btn.response.edit_message(embed=pages[self.current], view=self)
|
|
|
|
|
|
|
|
|
|
@discord.ui.button(label="➡️", style=discord.ButtonStyle.grey)
|
|
|
|
|
async def next(self, interaction_btn: discord.Interaction, button: discord.ui.Button):
|
|
|
|
|
if self.current < len(pages) - 1:
|
|
|
|
|
self.current += 1
|
|
|
|
|
await interaction_btn.response.edit_message(embed=pages[self.current], view=self)
|
|
|
|
|
|
|
|
|
|
await interaction.response.send_message(embed=pages[0], view=Pagination(), ephemeral=True)
|
|
|
|
|
|
|
|
|
|
async def setup(bot):
|
|
|
|
|
await bot.add_cog(CompteFBM(bot))
|