From 7e2cab687a479441deb57b2ca4ada60953d308d8 Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Mon, 5 May 2025 21:43:18 +0200 Subject: [PATCH] =?UTF-8?q?S=C3=A9paration=20des=20bdds=20de=20casino=20+?= =?UTF-8?q?=20fix=20roulette?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecoplus.py | 53 +++++++++++++++++++++++++++++++++++++++-------------- start.sh | 2 +- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ecoplus.py b/ecoplus.py index 49bef8c..9fc0097 100644 --- a/ecoplus.py +++ b/ecoplus.py @@ -1,6 +1,7 @@ import sys import random import datetime +import time import threading import discord @@ -28,11 +29,11 @@ import forgejo database = sqlite3.connect(sys.argv[2]) cursor = database.cursor() -try: - cursor.execute("CREATE TABLE casino (id INT PRIMARY KEY, cash INT)") - database.commit() -except: - print("La table existe déja") +#try: +# cursor.execute("CREATE TABLE casino (id INT PRIMARY KEY, cash INT)") +# database.commit() +#except: +# print("La table existe déja") guilds = [] @@ -63,7 +64,6 @@ async def roulette(message): roll = random.random() if roll < 0.16666666666: tdelt = datetime.timedelta(minutes=1) - await message.author.timeout(tdelt, reason="Vous avez perdu à la roulette...") try: await message.author.timeout(tdelt, reason="Vous avez perdu à la roulette...") except: @@ -73,33 +73,58 @@ async def roulette(message): async def casino_init(message): usrid = int(message.author.id) + gid = int(message.guild.id) try: - cursor.execute(f"INSERT INTO casino (id, cash) VALUES ({usrid}, 0)") + cursor.execute(f"CREATE TABLE IF NOT EXISTS tab_{gid} (id INT PRIMARY KEY, cash INT, lst_coll INT)") + cursor.execute(f"INSERT INTO tab_{gid} (id, cash, lst_coll) VALUES ({usrid}, 0, 0)") database.commit() await message.channel.send(f"Casino initialisé pour <@{usrid}>") except: await message.channel.send(f"Échec ! Réessayez plus tard") +init_global_str = "Essayer d'initialiser le casino du serveur avec ?init" +init_perso_str = "Essayez d'initialiser votre portemonnaie avec ?init" + async def balance(message): usrid = int(message.author.id) - cash = cursor.execute(f"SELECT cash FROM casino WHERE id={usrid}").fetchone() - if cash: + gid = int(message.guild.id) + try: + cash = cursor.execute(f"SELECT cash FROM tab_{gid} WHERE id={usrid}").fetchone() + except: + await message.channel.send(init_global_str) + if cash != None: await message.channel.send(f"Vous avez {cash[0]}$") else: - await message.channel.send(f"Essayez d'initialiser votre portemonnaie avec ?init") + await message.channel.send(init_perso_str) async def collect(message): collect_gain = 50 + cooldown = 10 + curr_time = int(time.time()) usrid = int(message.author.id) - cash = cursor.execute(f"SELECT cash FROM casino WHERE id={usrid}").fetchone() + gid = int(message.guild.id) + lst_coll = 0 + try: + lst_coll = cursor.execute(f"SELECT lst_coll FROM tab_{gid} WHERE id={usrid}").fetchone()[0] + except: + await message.channel.send(init_perso_str) + return + if lst_coll >= curr_time - cooldown: + rtime = (-curr_time + cooldown + lst_coll) + await message.channel.send(f"Vous pourrez toucher votre RSA dans {rtime} minutes") + return + cash = None + cash = cursor.execute(f"SELECT cash FROM tab_{gid} WHERE id={usrid}").fetchone() if cash != None: cash = cash[0] cash += collect_gain - cursor.execute(f"UPDATE casino SET cash = {cash} WHERE id={usrid}") + cursor.execute(f"UPDATE tab_{gid} SET lst_coll = {curr_time} WHERE id={usrid}") + cursor.execute(f"UPDATE tab_{gid} SET cash = {cash} WHERE id={usrid}") database.commit() - await message.channel.send(f"Vous avez recu {collect_gain}$. Vous avez désormais {cash}$") + await message.channel.send(f"Vous avez recu {collect_gain}$ en RSA. Vous avez désormais {cash}$\n"\ + f"Revenez dans {cooldown} minutes pour votre prochain chèque") else: - await message.channel.send(f"Essayez d'initialiser votre portemonnaie avec ?init") + await message.channel.send(init_perso_str) async def ecoaide(message): await message.channel.send("Eco+, un bot Eco plus pour faire des conneries\n"\ diff --git a/start.sh b/start.sh index 4873386..7eb2439 100755 --- a/start.sh +++ b/start.sh @@ -1 +1 @@ -python3 ecoplus.py secrets.txt +python3 ecoplus.py secrets.txt bdd.db