commit 15b9549bcb5c258ac8e9435cedc20eac72b35135 Author: GZod01 Date: Sun Dec 15 14:59:41 2024 +0100 Ajout de la gestion des personnages avec des commandes personnalisées et intégration de la base de données diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5163f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +private_env.py \ No newline at end of file diff --git a/GammaRPBot_Define.py b/GammaRPBot_Define.py new file mode 100644 index 0000000..f324dd0 --- /dev/null +++ b/GammaRPBot_Define.py @@ -0,0 +1,10 @@ +import discord +import aiosqlite +from discord.ext import commands +from discord import app_commands +class GammaRPBot(commands.Bot): + db:aiosqlite.Connection + def __init__(self,intents:discord.Intents): + super().__init__(command_prefix="/",intents=intents) + async def setup_hook(self)->None: + pass diff --git a/__pycache__/GammaRPBot_Define.cpython-312.pyc b/__pycache__/GammaRPBot_Define.cpython-312.pyc new file mode 100644 index 0000000..01efd41 Binary files /dev/null and b/__pycache__/GammaRPBot_Define.cpython-312.pyc differ diff --git a/__pycache__/perso_commands.cpython-312.pyc b/__pycache__/perso_commands.cpython-312.pyc new file mode 100644 index 0000000..3f74df3 Binary files /dev/null and b/__pycache__/perso_commands.cpython-312.pyc differ diff --git a/__pycache__/private_env.cpython-312.pyc b/__pycache__/private_env.cpython-312.pyc new file mode 100644 index 0000000..69d95a4 Binary files /dev/null and b/__pycache__/private_env.cpython-312.pyc differ diff --git a/__pycache__/public_env.cpython-312.pyc b/__pycache__/public_env.cpython-312.pyc new file mode 100644 index 0000000..9234e25 Binary files /dev/null and b/__pycache__/public_env.cpython-312.pyc differ diff --git a/main-bot.py b/main-bot.py new file mode 100644 index 0000000..0416494 --- /dev/null +++ b/main-bot.py @@ -0,0 +1,27 @@ +import discord +import aiosqlite +from discord.ext import commands +from discord import app_commands +import logging +import sys +from public_env import * +from GammaRPBot_Define import GammaRPBot +formatter = discord.utils._ColourFormatter() +handler = logging.StreamHandler(sys.stdout) +handler.setFormatter(formatter) +logging.basicConfig(level=logging.INFO, handlers=[handler]) +logger = logging.getLogger() + + + +intents = discord.Intents.all() +bot = GammaRPBot(intents) + +@bot.event +async def on_ready(): + bot.db = await aiosqlite.connect("main.db") + await bot.load_extension("perso_commands") + await bot.tree.sync() + print(f"Logged in as {bot.user}") + +bot.run(bot_token) \ No newline at end of file diff --git a/main.db b/main.db new file mode 100644 index 0000000..b7ffcae Binary files /dev/null and b/main.db differ diff --git a/main.db-journal b/main.db-journal new file mode 100644 index 0000000..c9233ca Binary files /dev/null and b/main.db-journal differ diff --git a/perso_commands.py b/perso_commands.py new file mode 100644 index 0000000..4dab6d6 --- /dev/null +++ b/perso_commands.py @@ -0,0 +1,31 @@ +from discord import app_commands +import discord +from GammaRPBot_Define import GammaRPBot +async def setup(bot:GammaRPBot): + bot.tree.add_command(PersoCommands(bot)) +class PersoCommands(app_commands.Group): + bot:GammaRPBot + def __init__(self,bot): + super().__init__(name="perso",description="Commandes pour les personnages") + self.bot=bot + + @app_commands.command(name="créer",description="Crée un 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", + sexe="Le sexe du personnage",guild_only="Personnage global ou uniquement sur ce serveur",image="L'image du personnage") + @app_commands.choices(guild_only=[app_commands.Choice(name="Global",value="global"),app_commands.Choice(name="Ce serveur uniquement", value="guild")]) + 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,guild_only:app_commands.Choice[str]): + nom_court = short_name + nom_complet= full_name + if image.content_type!="image/png" and image.content_type!="image/jpeg": + await interaction.response.send_message("L'image doit être un fichier PNG ou JPEG",ephemeral=True) + return + histoire = story + pouvoirs = powers + uuid=interaction.user.id + guild_id = interaction.guild.id + image_blob=await image.read() + print(nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,guild_id) + print(image.filename) + await self.bot.db.execute("INSERT INTO personnages (nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,guild_id,image) VALUES (?,?,?,?,?,?,?,?,?)",(nom_court,nom_complet,histoire,pouvoirs,age,sexe,uuid,guild_id,image_blob)) + \ No newline at end of file diff --git a/public_env.py b/public_env.py new file mode 100644 index 0000000..0b62d12 --- /dev/null +++ b/public_env.py @@ -0,0 +1 @@ +from private_env import * \ No newline at end of file