2024-12-16 23:00:10 +01:00
from discord import app_commands
import discord
from GammaRPBot_Define import GammaRPBot
import aiosqlite
import base64
import io
from public_env import *
_sql_table = """ CREATE TABLE personnages (
nom_court varchar ( 255 ) ,
nom_complet text ,
image text ,
histoire text ,
pouvoirs text ,
uuid TEXT ,
age INTEGER ,
sexe TEXT ,
money INTEGER DEFAULT 50 ,
guild_id INTEGER NULL
) """
async def setup ( bot : GammaRPBot ) :
bot . tree . add_command ( MoneyCommands ( bot ) )
class MoneyCommands ( app_commands . Group ) :
bot : GammaRPBot
def __init__ ( self , bot ) :
super ( ) . __init__ ( name = " argent " , description = " Commandes pour l ' argent " )
self . bot = bot
@app_commands.command ( name = " donner " , description = " Donne de l ' argent à un autre personnage " )
2024-12-17 11:21:15 +01:00
@app_commands.describe ( amount = " Le montant à donner " , from_short_name = " Le personnage depuis lequel prendre l ' argent " , to_short_name = " Le personnage à qui donner l ' argent " , secret = " Si l ' opération doit être secrète " )
async def give_money ( self , interaction : discord . Interaction , amount : int , from_short_name : str , to_short_name : str , secret = True ) :
2024-12-16 23:00:10 +01:00
if amount < = 0 :
await interaction . response . send_message ( " Le montant doit être positif " , ephemeral = True )
return
check_exist = await self . bot . db . execute ( " SELECT money FROM personnages WHERE nom_court=? AND uuid=? " , ( from_short_name , interaction . user . id ) )
money = await check_exist . fetchone ( )
if money is None :
await interaction . response . send_message ( " Ce personnage n ' existe pas ou ne vous appartient pas " , ephemeral = True )
return
if money [ ' money ' ] < amount :
await interaction . response . send_message ( " Vous n ' avez pas assez d ' argent " , ephemeral = True )
return
check_exist = await self . bot . db . execute ( " SELECT money FROM personnages WHERE nom_court=? " , ( to_short_name , ) )
money = await check_exist . fetchone ( )
if money is None :
await interaction . response . send_message ( " Ce personnage n ' existe pas " , ephemeral = True )
return
await self . bot . db . execute ( " UPDATE personnages SET money=money-? WHERE nom_court=? " , ( amount , from_short_name ) )
await self . bot . db . execute ( " UPDATE personnages SET money=money+? WHERE nom_court=? " , ( amount , to_short_name ) )
await self . bot . db . commit ( )
2024-12-17 11:21:15 +01:00
await interaction . response . send_message ( f " { from_short_name } vient de donner { amount } pièces à { to_short_name } " , ephemeral = not secret )
2024-12-16 23:00:10 +01:00
@app_commands.command ( name = " voir " , description = " Voir votre solde ou le solde d ' un autre personnage " )
2024-12-17 11:21:15 +01:00
@app_commands.describe ( short_name = " Le personnage dont vous voulez voir le solde " , secret = " Si l ' opération doit être secrète " )
async def see_money ( self , interaction : discord . Interaction , short_name : str , secret = True ) :
2024-12-16 23:00:10 +01:00
check_exist = await self . bot . db . execute ( " SELECT money FROM personnages WHERE nom_court=? " , ( short_name , ) )
money = await check_exist . fetchone ( )
if money is None :
await interaction . response . send_message ( " Ce personnage n ' existe pas " , ephemeral = True )
return
2024-12-17 11:21:15 +01:00
await interaction . response . send_message ( f " { short_name } a { money [ ' money ' ] } pièces " , ephemeral = not secret )
2024-12-16 23:00:10 +01:00
@app_commands.command ( name = " admin_ajouter " , description = " Ajoute de l ' argent à un personnage " )
@app_commands.describe ( amount = " Le montant à ajouter " , short_name = " Le personnage à qui ajouter l ' argent " )
async def add_money ( self , interaction : discord . Interaction , amount : int , short_name : str ) :
if interaction . user . id != super_owner_id :
await interaction . response . send_message ( " Vous n ' êtes pas autorisé à utiliser cette commande " , ephemeral = True )
return
if amount < = 0 :
await interaction . response . send_message ( " Le montant doit être positif " , ephemeral = True )
return
check_exist = await self . bot . db . execute ( " SELECT money FROM personnages WHERE nom_court=? " , ( short_name , ) )
money = await check_exist . fetchone ( )
if money is None :
await interaction . response . send_message ( " Ce personnage n ' existe pas " , ephemeral = True )
return
await self . bot . db . execute ( " UPDATE personnages SET money=money+? WHERE nom_court=? " , ( amount , short_name ) )
await self . bot . db . commit ( )
await interaction . response . send_message ( f " Vous avez ajouté { amount } pièces à { short_name } " , ephemeral = True )