From 74c120110aa16f1e7ba6079c7c8dceb60f1f5a89 Mon Sep 17 00:00:00 2001 From: GZod01 Date: Mon, 16 Dec 2024 23:00:10 +0100 Subject: [PATCH] a --- main-bot.py | 61 +++++++++++++++++++++++++++++++++++ main.db | Bin 8192 -> 8192 bytes money_commands.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++ perso_commands.py | 1 + 4 files changed, 142 insertions(+) create mode 100644 money_commands.py diff --git a/main-bot.py b/main-bot.py index 39bb947..b78e584 100644 --- a/main-bot.py +++ b/main-bot.py @@ -7,6 +7,7 @@ import sys from public_env import * from GammaRPBot_Define import GammaRPBot import base64 +import aiohttp formatter = discord.utils._ColourFormatter() handler = logging.StreamHandler(sys.stdout) handler.setFormatter(formatter) @@ -14,6 +15,18 @@ logging.basicConfig(level=logging.INFO, handlers=[handler]) 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 +)""" intents = discord.Intents.all() bot = GammaRPBot(intents) @@ -87,4 +100,52 @@ async def say_message(userid:int, guildid:int, shortname:str, message:str,channe # print("ok8") return True + + +# @bot.tree.command(name="ai",description="Envoyer un message par IA en tant que personnage (attention mémoire allant jusqu'a 100 messages max)") +# @app_commands.user_install() +# @app_commands.describe(id="Le nom court du personnage",prompt="La prompt pour le message de l'IA") +# @app_commands.allowed_contexts(guilds=True,dms=True,private_channels=True) +# @app_commands.allowed_installs(guilds=True,users=True) +# async def say_ai(interaction:discord.Interaction,id:str,prompt:str=""): +# if not await say_message(interaction.user.id,(interaction.guild.id if interaction.guild is not None else -1),id,prompt,interaction.channel,interaction.response): +# print("ok9") +# await interaction.response.send_message("Vous n'avez pas ce personnage",ephemeral=True) +# return +# print("ok10") +# await interaction.response.send_message("Message envoyé",ephemeral=True) +# async def say_message_ai(userid:int,guildid:int,shortname:str,channel:discord.TextChannel,interaction_res:discord.InteractionResponse=None, prompt:str=""): +# messages = await channel.history(limit=100).flatten() +# #gemini request using gemini_token +# super_payload = { +# "contents":[ +# { +# "role":"user", +# "parts":[{ +# "text":"Hello" +# }] +# } +# ] +# } +# res_message=use_gemini(payload=super_payload) + +# say_message(userid,guildid,shortname,res_message,channel,interaction_res) +# return True + +# async def use_gemini(payload): +# url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key="+gemini_token +# headers={ +# "Content-Type":"application/json" +# } +# async with aiohttp.ClientSession().post(url,headers=headers,json=payload) as response: +# result = await response.json() +# print(result) +# try: +# content = result['candidates'][0]['content']['parts'][0]['text'] +# return content +# except (KeyError, IndexError) as e: +# # Log the error and response for debugging +# print(f"Error parsing response: {e}") +# print(f"Unexpected response format: {result}") +# return "Error: Unexpected response format" bot.run(bot_token) \ No newline at end of file diff --git a/main.db b/main.db index 4872037b84184a5c0f9c7c098b1f2b844306d87e..2b515835a6889ec41ee956b2d1fd09d1c907b121 100644 GIT binary patch delta 94 zcmZp0XmFSyEy&5hz`z8=Fu*iX$C#g!K~E=u7bwKY&&t5hy0LINA6H`qBfGe=GGnv( pWKI5SQaTE``FW|83Z8x;uI{cu3NEg0j-fsw3Z@2||MN2n007X=67>K8 delta 68 zcmZp0XmFSyEy%&Zz`z8=Fu*ub$C#gkK`)t+7bwKYFVDa)zgbXVBOg~|93#89vNB^c P^JIShYn%V`GYS9zHx&yE diff --git a/money_commands.py b/money_commands.py new file mode 100644 index 0000000..900dbb1 --- /dev/null +++ b/money_commands.py @@ -0,0 +1,80 @@ +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") + @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") + async def give_money(self,interaction:discord.Interaction,amount:int,from_short_name:str,to_short_name:str): + 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']