Courses de chevaux complétées

This commit is contained in:
attilavs2 2025-05-12 23:06:57 +02:00
parent 6a7452c528
commit c06f6e412e
2 changed files with 77 additions and 8 deletions

Binary file not shown.

View file

@ -301,7 +301,7 @@ async def do_course(message):
print(f"Forme : {choice[2]},{msgchoice}")
await message.channel.send(f"La rumeur court que le cheval n°{select} {msg}")
if cetape == 3:
await message.channel.send("La course a commencé, et les paris sont fermés")
await message.channel.send("## La course a commencé, et les paris sont fermés")
if cetape > 3:
for i in range(10):
chev = cursor.execute(f"SELECT * FROM grid_{gid} WHERE n={i+1}").fetchone()
@ -312,12 +312,29 @@ async def do_course(message):
gagn = 0
n = 1
for chev in grid:
msgstr += f"{n} - n°{chev[0]}, {chev[2]*10}m\n"
if chev[0] > 50:
clmp_dist = 50
else:
clmp_dist = chev[0]
msgstr += f"{n} - n°{clmp_dist}, {chev[2]*10}m\n"
n += 1
if chev[2] >= 50:
if chev[2] >= 50 and not gagn:
gagn = chev[0]
if gagn:
msgstr += f"\nLe numéro {gagn} a remporté la course !"
cursor.execute(f"UPDATE courses SET fini = 1,etape=0 WHERE gid = {gid}")
wbets = cursor.execute(f"SELECT * FROM bets_{gid} WHERE pari_n = {gagn}").fetchall()
if wbets:
msgstr += "\n## Pari gagnants :\n"
for bet in wbets:
uid = bet[0]
gain = bet[2]*8
msgstr += f"<@{uid}> remporte {gain}$\n"
play = cursor.execute(f"SELECT * FROM tab_{gid} WHERE id = {uid}").fetchone()
ncash = play[1] + gain
cursor.execute(f"UPDATE tab_{gid} SET cash = {ncash} WHERE id = {uid}")
database.commit()
await message.channel.send(msgstr)
if gagn:
break
@ -332,22 +349,22 @@ async def do_course(message):
async def course(message):
gid = int(message.guild.id)
uid = int(message.author.id)
cursor.execute(f"CREATE TABLE IF NOT EXISTS courses (gid INT PRIMARY KEY, date INT, date_der INT, etape INT)")
cursor.execute(f"CREATE TABLE IF NOT EXISTS courses (gid INT PRIMARY KEY, date INT, date_der INT, etape INT, fini INT)")
try:
cursor.execute(f"CREATE TABLE bets_{gid} (id INT PRIMARY KEY, pari_n INT, pari_qtt INT)")
cursor.execute(f"CREATE TABLE bets_{gid} (id INT, pari_n INT, pari_qtt INT)")
cursor.execute(f"CREATE TABLE grid_{gid} (n INT PRIMARY KEY, speed INT, pos INT)")
except:
await message.reply("Une course est déja en cours")
return
ctime = int(time.time())
cursor.execute(f"INSERT OR REPLACE INTO courses (gid, date, date_der, etape) VALUES ({gid},{ctime},{ctime},0)")
cursor.execute(f"INSERT OR REPLACE INTO courses (gid, date, date_der, etape, fini) VALUES ({gid},{ctime},{ctime},0,0)")
grid=[]
for i in range(10):
grid.append(i+1)
while grid:
n = random.choice(grid)
grid.remove(n)
speed = 4 + random.randint(0,3) + random.randint(0,3)
speed = 5 + random.randint(0,2) + random.randint(0,3)
cursor.execute(f"INSERT INTO grid_{gid} (n,speed,pos) VALUES ({n},{speed},0)")
database.commit()
await message.channel.send(
@ -358,7 +375,58 @@ async def course(message):
await do_course(message)
async def bet(message):
pass
gid = int(message.guild.id)
uid = int(message.author.id)
ret = None
try:
ret = cursor.execute(f"SELECT * FROM courses WHERE gid = {gid}").fetchone()
if ret and ret[4]:
ret = None
except:
ret = None
if ret == None:
await message.reply("Aucune course n'est en cours.\n"\
"Lancez une course avec ?course")
return
if ret[3] >= 3:
await message.reply("La course est en cours !")
return
split = message.content.split(" ")
if len(split) < 3:
await message.reply("Vous devez spécifier au moins deux arguments\n"\
"Utilisation : ?bet <n° cheval> <quantité>")
return
n = 0
bet = 0
try:
n = int(split[1])
except:
await message.reply("Numéro invalide")
return
if n < 1 or n > 10:
await message.reply("Numéro invalide")
return
try:
bet = int(split[2])
except:
await message.reply("Quantité invalide")
return
if bet < 1:
await message.reply("Quantité invalide")
return
try:
play = cursor.execute(f"SELECT * FROM tab_{gid} WHERE id={uid}").fetchone()
except:
await message.reply(init_perso_str)
return
if play[1] < bet:
await message.reply("Vous n'avez pas assez d'argent")
return
ncash = play[1] - bet
cursor.execute(f"INSERT INTO bets_{gid} (id, pari_n, pari_qtt) VALUES ({uid},{n},{bet})")
cursor.execute(f"UPDATE tab_{gid} SET cash = {ncash} WHERE id = {uid}")
database.commit()
await message.reply("Pari placé")
async def casino_aide(message):
await message.channel.send("Commandes du casino Eco+\n"\
@ -474,6 +542,7 @@ cmd_dict = {\
"?transfer":transfer,\
"?casino":casino_aide,\
"?course":course,\
"?bet":bet,\
}
@client.event