Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
67
commandes/transactions.py
Normal file
67
commandes/transactions.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
from utils.banque_manager import BanqueManager
|
||||
|
||||
BANQUIER_ROLE_ID = 1360314740567576616 # ID du rôle des banquiers # ID du rôle banquier # ID du rôle des banquiers
|
||||
|
||||
banque_manager = BanqueManager()
|
||||
|
||||
class Transactions(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@app_commands.command(name="transactions", description="Affiche les transactions d'un utilisateur (réservé aux banquiers).")
|
||||
async def transactions(self, interaction: discord.Interaction, utilisateur: discord.Member):
|
||||
"""Affiche l'historique des transactions d'un utilisateur (banquiers uniquement)."""
|
||||
|
||||
# ✅ Récupération du vrai membre pour avoir les rôles
|
||||
member = interaction.guild.get_member(interaction.user.id)
|
||||
if not member:
|
||||
await interaction.response.send_message("❌ Impossible de vérifier vos permissions.", ephemeral=True)
|
||||
return
|
||||
|
||||
# ✅ Vérification du rôle banquier
|
||||
if not any(role.id == BANQUIER_ROLE_ID for role in member.roles):
|
||||
await interaction.response.send_message("❌ Vous n'avez pas la permission de voir les transactions.", ephemeral=True)
|
||||
return
|
||||
|
||||
banque_manager.load_data()
|
||||
|
||||
user_id = str(utilisateur.id)
|
||||
|
||||
# ✅ Vérification si l'utilisateur a des transactions
|
||||
if user_id not in banque_manager.comptes or "transactions" not in banque_manager.comptes[user_id]:
|
||||
await interaction.response.send_message(f"❌ {utilisateur.mention} n'a pas d'historique de transactions.", ephemeral=True)
|
||||
return
|
||||
|
||||
transactions = banque_manager.comptes[user_id].get("transactions", [])
|
||||
|
||||
if not transactions:
|
||||
await interaction.response.send_message(f"📜 {utilisateur.mention} n'a encore effectué aucune transaction.", ephemeral=True)
|
||||
return
|
||||
|
||||
# ✅ Création de l'embed
|
||||
embed = discord.Embed(
|
||||
title=f"📜 Historique des transactions de {utilisateur.name}",
|
||||
color=discord.Color.gold()
|
||||
)
|
||||
|
||||
for t in transactions[-10:]:
|
||||
embed.add_field(
|
||||
name=f"📅 {t['date']}",
|
||||
value=(
|
||||
f"**Type**: {t['type']}\n"
|
||||
f"💰 **Montant**: {t['montant']}€\n"
|
||||
f"📤 **Émetteur**: <@{t['emetteur']}>\n"
|
||||
f"📥 **Destinataire**: <@{t['destinataire']}>"
|
||||
),
|
||||
inline=False
|
||||
)
|
||||
|
||||
embed.set_footer(text="Seules les 10 dernières transactions sont affichées.")
|
||||
|
||||
await interaction.response.send_message(embed=embed)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Transactions(bot))
|
||||
Loading…
Add table
Add a link
Reference in a new issue