Séparation des bdds de casino + fix roulette
This commit is contained in:
parent
7168187c08
commit
7e2cab687a
2 changed files with 40 additions and 15 deletions
53
ecoplus.py
53
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"\
|
||||
|
|
2
start.sh
2
start.sh
|
@ -1 +1 @@
|
|||
python3 ecoplus.py secrets.txt
|
||||
python3 ecoplus.py secrets.txt bdd.db
|
||||
|
|
Loading…
Add table
Reference in a new issue