araeporkaeropk

This commit is contained in:
GZod01 2024-12-18 09:19:19 +01:00
parent ecd5036429
commit ea1ab953c7
4 changed files with 44 additions and 39 deletions

View file

@ -16,16 +16,17 @@ logger = logging.getLogger()
# _sql_table="""CREATE TABLE personnages ( # _sql_table="""CREATE TABLE personnages (
# nom_court varchar(255), # nom_court varchar(255),
# nom_complet text, # nom_complet text,
# image text, # image text,
# histoire text, # histoire text,
# pouvoirs text, # pouvoirs text,
# uuid TEXT, # uuid TEXT,
# age INTEGER, # age INTEGER,
# sexe TEXT, # sexe TEXT,
# money INTEGER DEFAULT 50, # guild_id INTEGER NULL,
# guild_id INTEGER NULL # money INTEGER DEFAULT 50,
# universe TEXT
# )""" # )"""
intents = discord.Intents.all() intents = discord.Intents.all()

BIN
main.db

Binary file not shown.

View file

@ -7,16 +7,17 @@ import io
from public_env import * from public_env import *
_sql_table="""CREATE TABLE personnages ( _sql_table="""CREATE TABLE personnages (
nom_court varchar(255), nom_court varchar(255),
nom_complet text, nom_complet text,
image text, image text,
histoire text, histoire text,
pouvoirs text, pouvoirs text,
uuid TEXT, uuid TEXT,
age INTEGER, age INTEGER,
sexe TEXT, sexe TEXT,
money INTEGER DEFAULT 50, guild_id INTEGER NULL,
guild_id INTEGER NULL money INTEGER DEFAULT 50,
universe TEXT
)""" )"""
async def setup(bot:GammaRPBot): async def setup(bot:GammaRPBot):

View file

@ -8,16 +8,17 @@ from public_env import *
_sql_table="""CREATE TABLE personnages ( _sql_table="""CREATE TABLE personnages (
nom_court varchar(255), nom_court varchar(255),
nom_complet text, nom_complet text,
image text, image text,
histoire text, histoire text,
pouvoirs text, pouvoirs text,
uuid TEXT, uuid TEXT,
age INTEGER, age INTEGER,
sexe TEXT, sexe TEXT,
money INTEGER DEFAULT 50, guild_id INTEGER NULL,
guild_id INTEGER NULL money INTEGER DEFAULT 50,
universe TEXT
)""" )"""
async def setup(bot:GammaRPBot): async def setup(bot:GammaRPBot):
@ -32,10 +33,12 @@ class PersoCommands(app_commands.Group):
@app_commands.describe(short_name="Le nom court du personnage (son ID)", full_name="Le nom complet du personnage", @app_commands.describe(short_name="Le nom court du personnage (son ID)", full_name="Le nom complet du personnage",
story="L'histoire du personnage",powers="Les pouvoirs du personnage",age="L'âge du personnage", story="L'histoire du personnage",powers="Les pouvoirs du personnage",age="L'âge du personnage",
sexe="Le sexe du personnage", sexe="Le sexe du personnage",
global_character="Le personnage est il global ou reservé à ce serveur", universe_code="Le code de l'univers du personnage",
global_character="Le personnage est il global ou réservé à ce serveur",
user_global_character="Le personnage vous est réservé ou global à tous les utilisateurs",
image="L'image du personnage") image="L'image du personnage")
async def create_character(self,interaction:discord.Interaction,short_name:str,full_name:str,image:discord.Attachment,story:str,powers:str,age:int,sexe:str, async def create_character(self,interaction:discord.Interaction,short_name:str,full_name:str,image:discord.Attachment,story:str,powers:str,age:int,sexe:str,universe_code:str,
global_character:bool=False global_character:bool=False,user_global_character:bool=False
): ):
nom_court = short_name nom_court = short_name
nom_complet= full_name nom_complet= full_name
@ -45,14 +48,17 @@ class PersoCommands(app_commands.Group):
if " " in nom_court: if " " in nom_court:
await interaction.response.send_message("Le nom court ne doit pas contenir d'espaces",ephemeral=True) await interaction.response.send_message("Le nom court ne doit pas contenir d'espaces",ephemeral=True)
return return
if " " in universe_code:
await interaction.response.send_message("Le code de l'univers ne doit pas contenir d'espaces",ephemeral=True)
return
check_exist = await self.bot.db.execute("SELECT * FROM personnages WHERE nom_court=?", (nom_court,)) check_exist = await self.bot.db.execute("SELECT * FROM personnages WHERE nom_court=?", (nom_court,))
if check_exist.rowcount>0 or await check_exist.fetchone() is not None: if check_exist.rowcount>0 or await check_exist.fetchone() is not None:
await interaction.response.send_message("Ce nom court est déjà utilisé",ephemeral=True) await interaction.response.send_message("Ce nom court est déjà utilisé",ephemeral=True)
return return
histoire = story histoire = story
pouvoirs = powers pouvoirs = powers
uuid=interaction.user.id uuid=interaction.user.id if user_global_character else None
guild_id = interaction.guild.id guild_id = interaction.guild.id if global_character else None
image_blob_raw=await image.read() image_blob_raw=await image.read()
a = await self.bot.get_guild(1037663859621765160).get_channel(1317876780635394068).send(file=discord.File(io.BytesIO(image_blob_raw),filename=image.filename)) a = await self.bot.get_guild(1037663859621765160).get_channel(1317876780635394068).send(file=discord.File(io.BytesIO(image_blob_raw),filename=image.filename))
perso_image_url = a.attachments[0].url perso_image_url = a.attachments[0].url
@ -61,10 +67,7 @@ class PersoCommands(app_commands.Group):
print(image.url) print(image.url)
try: try:
res=None res=None
if global_character: res = await self.bot.db.execute("INSERT INTO personnages (nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,image,universe,guild_id) VALUES (?,?,?,?,?,?,?,?)",(nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,perso_image_url,universe_code,guild_id))
res = await self.bot.db.execute("INSERT INTO personnages (nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,image) VALUES (?,?,?,?,?,?,?,?)",(nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,perso_image_url))
else:
res=await self.bot.db.execute("INSERT INTO personnages (nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,image,guild_id) VALUES (?,?,?,?,?,?,?,?,?)",(nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,perso_image_url,guild_id))
print(res) print(res)
await res.close() await res.close()
await self.bot.db.commit() await self.bot.db.commit()