From 2c7fcb6fc5465b9f9a6185a60eec5f6c64a257d4 Mon Sep 17 00:00:00 2001 From: GZod01 Date: Sun, 15 Dec 2024 15:45:33 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20commande=20pour=20envoyer=20u?= =?UTF-8?q?n=20message=20en=20tant=20que=20personnage=20et=20cr=C3=A9ation?= =?UTF-8?q?=20d'une=20fonction=20utilitaire=20pour=20r=C3=A9cup=C3=A9rer?= =?UTF-8?q?=20les=20personnages=20d'un=20utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main-bot.py | 19 +++++++++++++++++++ utils.py | 3 +++ 2 files changed, 22 insertions(+) create mode 100644 utils.py diff --git a/main-bot.py b/main-bot.py index 0416494..a427fd5 100644 --- a/main-bot.py +++ b/main-bot.py @@ -24,4 +24,23 @@ async def on_ready(): await bot.tree.sync() print(f"Logged in as {bot.user}") + +@bot.tree.command(name="s",description="Envoyer un message en tant que personnage",aliases=["say","dire","écrire"]) +async def say(interaction:discord.Interaction,id:str,message:str): + res = await bot.db.execute("SELECT * FROM personnages WHERE uuid=? AND (guild_id=? OR guild_id IS NULL) AND nom_court=?",(interaction.user.id,interaction.guild.id,id)) + row = await res.fetchone() + await res.close() + if row is None: + await interaction.response.send_message("Personnage non trouvé",ephemeral=True) + return + short_name = row[0] + full_name = row[1] + perso_image = row[2] + webhook = None + if discord.utils.get(interaction.channel.webhooks(),name=short_name) is None: + webhook = await interaction.channel.create_webhook(name=short_name,avatar=perso_image) + else: + webhook = discord.utils.get(interaction.channel.webhooks(),name=short_name) + await webhook.send(message,username=full_name,avatar_url=perso_image) + await interaction.response.send_message("Message envoyé",ephemeral=True) bot.run(bot_token) \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..3636e52 --- /dev/null +++ b/utils.py @@ -0,0 +1,3 @@ +async def get_user_persos(bot,user:int,guild_id:int): + async with bot.db.execute("SELECT * FROM personnages WHERE uuid=? AND (guild_id=? OR guild_id IS NULL)",(user,guild_id)) as cursor: + return await cursor.fetchall() \ No newline at end of file