diff --git a/main-bot.py b/main-bot.py index d9bebde..f373a35 100644 --- a/main-bot.py +++ b/main-bot.py @@ -16,16 +16,17 @@ logger = logging.getLogger() # _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 +# nom_court varchar(255), +# nom_complet text, +# image text, +# histoire text, +# pouvoirs text, +# uuid TEXT, +# age INTEGER, +# sexe TEXT, +# guild_id INTEGER NULL, +# money INTEGER DEFAULT 50, +# universe TEXT # )""" intents = discord.Intents.all() diff --git a/main.db b/main.db index 2b51583..ef66457 100644 Binary files a/main.db and b/main.db differ diff --git a/money_commands.py b/money_commands.py index 5bfff86..d5d643e 100644 --- a/money_commands.py +++ b/money_commands.py @@ -7,16 +7,17 @@ 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 + nom_court varchar(255), + nom_complet text, + image text, + histoire text, + pouvoirs text, + uuid TEXT, + age INTEGER, + sexe TEXT, + guild_id INTEGER NULL, + money INTEGER DEFAULT 50, + universe TEXT )""" async def setup(bot:GammaRPBot): diff --git a/perso_commands.py b/perso_commands.py index 205a1d1..ce9ac60 100644 --- a/perso_commands.py +++ b/perso_commands.py @@ -8,16 +8,17 @@ 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 + nom_court varchar(255), + nom_complet text, + image text, + histoire text, + pouvoirs text, + uuid TEXT, + age INTEGER, + sexe TEXT, + guild_id INTEGER NULL, + money INTEGER DEFAULT 50, + universe TEXT )""" 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", story="L'histoire du personnage",powers="Les pouvoirs du personnage",age="L'âge 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") - 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, - global_character:bool=False + 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,user_global_character:bool=False ): nom_court = short_name nom_complet= full_name @@ -45,14 +48,17 @@ class PersoCommands(app_commands.Group): if " " in nom_court: await interaction.response.send_message("Le nom court ne doit pas contenir d'espaces",ephemeral=True) 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,)) 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) return histoire = story pouvoirs = powers - uuid=interaction.user.id - guild_id = interaction.guild.id + uuid=interaction.user.id if user_global_character else None + guild_id = interaction.guild.id if global_character else None 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)) perso_image_url = a.attachments[0].url @@ -61,10 +67,7 @@ class PersoCommands(app_commands.Group): print(image.url) try: res=None - if global_character: - 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)) + 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)) print(res) await res.close() await self.bot.db.commit()