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 4872037..2b51583 100644 Binary files a/main.db and b/main.db differ 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']