This commit is contained in:
GZod01 2024-12-16 23:00:10 +01:00
parent 2d153d64ab
commit 74c120110a
4 changed files with 142 additions and 0 deletions

View file

@ -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)

BIN
main.db

Binary file not shown.

80
money_commands.py Normal file
View file

@ -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']<amount:
await interaction.response.send_message("Vous n'avez pas assez d'argent",ephemeral=True)
return
check_exist = await self.bot.db.execute("SELECT money FROM personnages WHERE nom_court=?", (to_short_name,))
money = await check_exist.fetchone()
if money is None:
await interaction.response.send_message("Ce personnage n'existe pas",ephemeral=True)
return
await self.bot.db.execute("UPDATE personnages SET money=money-? WHERE nom_court=?", (amount,from_short_name))
await self.bot.db.execute("UPDATE personnages SET money=money+? WHERE nom_court=?", (amount,to_short_name))
await self.bot.db.commit()
await interaction.response.send_message(f"Vous avez donné {amount} pièces à {to_short_name}",ephemeral=True)
@app_commands.command(name="voir",description="Voir votre solde ou le solde d'un autre personnage")
@app_commands.describe(short_name="Le personnage dont vous voulez voir le solde")
async def see_money(self,interaction:discord.Interaction,short_name:str):
check_exist = await self.bot.db.execute("SELECT money FROM personnages WHERE nom_court=?", (short_name,))
money = await check_exist.fetchone()
if money is None:
await interaction.response.send_message("Ce personnage n'existe pas",ephemeral=True)
return
await interaction.response.send_message(f"{short_name} a {money['money']} pièces",ephemeral=True)
@app_commands.command(name="admin_ajouter",description="Ajoute de l'argent à un personnage")
@app_commands.describe(amount="Le montant à ajouter",short_name="Le personnage à qui ajouter l'argent")
async def add_money(self,interaction:discord.Interaction,amount:int,short_name:str):
if interaction.user.id!=super_owner_id:
await interaction.response.send_message("Vous n'êtes pas autorisé à utiliser cette commande",ephemeral=True)
return
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=?", (short_name,))
money = await check_exist.fetchone()
if money is None:
await interaction.response.send_message("Ce personnage n'existe pas",ephemeral=True)
return
await self.bot.db.execute("UPDATE personnages SET money=money+? WHERE nom_court=?", (amount,short_name))
await self.bot.db.commit()
await interaction.response.send_message(f"Vous avez ajouté {amount} pièces à {short_name}",ephemeral=True)

View file

@ -16,6 +16,7 @@ _sql_table="""CREATE TABLE personnages (
uuid TEXT,
age INTEGER,
sexe TEXT,
money INTEGER DEFAULT 50,
guild_id INTEGER NULL
)"""