Début des courses de cheveaux
This commit is contained in:
parent
0d2d1fe52a
commit
6a7452c528
2 changed files with 115 additions and 11 deletions
BIN
.ecoplus.py.swn
Normal file
BIN
.ecoplus.py.swn
Normal file
Binary file not shown.
126
ecoplus.py
126
ecoplus.py
|
@ -3,6 +3,7 @@ import random
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
@ -20,7 +21,7 @@ intents.message_content = True
|
||||||
intents.members = True
|
intents.members = True
|
||||||
intents.moderation = True
|
intents.moderation = True
|
||||||
|
|
||||||
client = discord.Client(intents=intents, activity=discord.Game(name='En train de niquer des mères'))
|
client = discord.Client(intents=intents, activity=discord.Game(name='En train de parier aux courses'))
|
||||||
|
|
||||||
interface.client = client
|
interface.client = client
|
||||||
|
|
||||||
|
@ -29,12 +30,6 @@ import forgejo
|
||||||
database = sqlite3.connect(sys.argv[2])
|
database = sqlite3.connect(sys.argv[2])
|
||||||
cursor = database.cursor()
|
cursor = database.cursor()
|
||||||
|
|
||||||
#try:
|
|
||||||
# cursor.execute("CREATE TABLE casino (id INT PRIMARY KEY, cash INT)")
|
|
||||||
# database.commit()
|
|
||||||
#except:
|
|
||||||
# print("La table existe déja")
|
|
||||||
|
|
||||||
guilds = []
|
guilds = []
|
||||||
|
|
||||||
globals()["gmembers"] = {}
|
globals()["gmembers"] = {}
|
||||||
|
@ -210,11 +205,11 @@ async def leaderboard(message):
|
||||||
uid = int(message.author.id)
|
uid = int(message.author.id)
|
||||||
gid = int(message.guild.id)
|
gid = int(message.guild.id)
|
||||||
lb = None
|
lb = None
|
||||||
result = cursor.execute(f"SELECT * FROM tab_{gid} ORDER BY cash DESC").fetchall()
|
result = cursor.execute(f"SELECT * FROM tab_{gid} ORDER BY cash DESC LIMIT 10").fetchall()
|
||||||
msgstr = "## ===== Leaderboard =====\n"
|
msgstr = "## ===== Leaderboard =====\n"
|
||||||
i = 0
|
i = 0
|
||||||
rlen = len(result)
|
rlen = len(result)
|
||||||
while i < 10 and i < rlen:
|
while i < rlen:
|
||||||
uid = result[i][0]
|
uid = result[i][0]
|
||||||
ucash = result[i][1]
|
ucash = result[i][1]
|
||||||
msgstr += " "+str(i+1)+f". <@{uid}> - {ucash}$\n"
|
msgstr += " "+str(i+1)+f". <@{uid}> - {ucash}$\n"
|
||||||
|
@ -242,11 +237,13 @@ async def transfer(message):
|
||||||
return
|
return
|
||||||
amnt = 0
|
amnt = 0
|
||||||
try:
|
try:
|
||||||
amnt = int(split[2])
|
amnt = int(split[-1])
|
||||||
except:
|
except:
|
||||||
await message.reply("Quantité non valide")
|
await message.reply(f"Quantité non valide (`{split[2]}`)")
|
||||||
return
|
return
|
||||||
taxamnt = int(round(amnt*0.05))
|
taxamnt = int(round(amnt*0.05))
|
||||||
|
if taxamnt < 1:
|
||||||
|
taxamnt = 1
|
||||||
if amnt + taxamnt > utili[1]:
|
if amnt + taxamnt > utili[1]:
|
||||||
await message.reply("Vous n'avez pas assez d'argent")
|
await message.reply("Vous n'avez pas assez d'argent")
|
||||||
return
|
return
|
||||||
|
@ -257,6 +254,112 @@ async def transfer(message):
|
||||||
database.commit()
|
database.commit()
|
||||||
await message.reply(f"Transfert effectué. Une taxe de 5% ({taxamnt}$) a été prélevée.")
|
await message.reply(f"Transfert effectué. Une taxe de 5% ({taxamnt}$) a été prélevée.")
|
||||||
|
|
||||||
|
forme_msg = [\
|
||||||
|
"n'est pas très en forme",\
|
||||||
|
"va bien",\
|
||||||
|
"est très remonté",\
|
||||||
|
"a laissé des seringues vides dans son box",\
|
||||||
|
]
|
||||||
|
|
||||||
|
async def do_course(message):
|
||||||
|
gid = int(message.guild.id)
|
||||||
|
nxt_tick = 0
|
||||||
|
ret = cursor.execute(f"SELECT * FROM courses WHERE gid={gid}").fetchone()
|
||||||
|
start_time = ret[1]
|
||||||
|
elaps_time = time.time()-ret[2]
|
||||||
|
cetape = ret[3]
|
||||||
|
while True:
|
||||||
|
ctime = time.time()
|
||||||
|
detape = 0
|
||||||
|
if ctime < nxt_tick:
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
continue
|
||||||
|
ret = cursor.execute(f"SELECT * FROM courses WHERE gid={gid}").fetchone()
|
||||||
|
elaps_time = ctime - ret[2]
|
||||||
|
if elaps_time > 20 and cetape <= 3:
|
||||||
|
detape = 1
|
||||||
|
if elaps_time > 20 and cetape > 3:
|
||||||
|
detape = 1
|
||||||
|
if detape:
|
||||||
|
cetape+=1
|
||||||
|
itime = int(ctime)
|
||||||
|
cursor.execute(f"UPDATE courses SET date_der={itime},etape={cetape} WHERE gid={gid}")
|
||||||
|
database.commit()
|
||||||
|
if cetape < 3:
|
||||||
|
select = random.randint(1,10)
|
||||||
|
choice = cursor.execute(f"SELECT * FROM grid_{gid} WHERE n = {select}").fetchone()
|
||||||
|
msgchoice = 1
|
||||||
|
if choice[1] < 6:
|
||||||
|
msgchoice = 0
|
||||||
|
if choice[1] >= 6 and choice[1] < 8:
|
||||||
|
msgchoice = 1
|
||||||
|
if choice[1] >= 8 and choice[1] < 10:
|
||||||
|
msgchoice = 2
|
||||||
|
if choice[1] == 10:
|
||||||
|
msgchoice = 3
|
||||||
|
msg = forme_msg[msgchoice]
|
||||||
|
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")
|
||||||
|
if cetape > 3:
|
||||||
|
for i in range(10):
|
||||||
|
chev = cursor.execute(f"SELECT * FROM grid_{gid} WHERE n={i+1}").fetchone()
|
||||||
|
cpos = chev[2] + chev[1] - random.randint(0,2)
|
||||||
|
cursor.execute(f"UPDATE grid_{gid} SET pos={cpos} WHERE n={chev[0]}")
|
||||||
|
grid = cursor.execute(f"SELECT * FROM grid_{gid} ORDER BY pos DESC")
|
||||||
|
msgstr = "## Grille de la course\n"
|
||||||
|
gagn = 0
|
||||||
|
n = 1
|
||||||
|
for chev in grid:
|
||||||
|
msgstr += f"{n} - n°{chev[0]}, {chev[2]*10}m\n"
|
||||||
|
n += 1
|
||||||
|
if chev[2] >= 50:
|
||||||
|
gagn = chev[0]
|
||||||
|
if gagn:
|
||||||
|
msgstr += f"\nLe numéro {gagn} a remporté la course !"
|
||||||
|
await message.channel.send(msgstr)
|
||||||
|
if gagn:
|
||||||
|
break
|
||||||
|
nxt_tick += 10
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
|
cursor.execute(f"DROP TABLE bets_{gid}")
|
||||||
|
cursor.execute(f"DROP TABLE grid_{gid}")
|
||||||
|
database.commit()
|
||||||
|
print("Tables de course DROP")
|
||||||
|
|
||||||
|
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)")
|
||||||
|
try:
|
||||||
|
cursor.execute(f"CREATE TABLE bets_{gid} (id INT PRIMARY KEY, 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)")
|
||||||
|
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)
|
||||||
|
cursor.execute(f"INSERT INTO grid_{gid} (n,speed,pos) VALUES ({n},{speed},0)")
|
||||||
|
database.commit()
|
||||||
|
await message.channel.send(
|
||||||
|
f"### Course de chevaux lancée par <@{uid}>\n"\
|
||||||
|
"Vous avez 10min pour placer vos paris avec ?bet"\
|
||||||
|
)
|
||||||
|
|
||||||
|
await do_course(message)
|
||||||
|
|
||||||
|
async def bet(message):
|
||||||
|
pass
|
||||||
|
|
||||||
async def casino_aide(message):
|
async def casino_aide(message):
|
||||||
await message.channel.send("Commandes du casino Eco+\n"\
|
await message.channel.send("Commandes du casino Eco+\n"\
|
||||||
"?init : initialiser votre portefeuille\n"\
|
"?init : initialiser votre portefeuille\n"\
|
||||||
|
@ -370,6 +473,7 @@ cmd_dict = {\
|
||||||
"?roll":roll,\
|
"?roll":roll,\
|
||||||
"?transfer":transfer,\
|
"?transfer":transfer,\
|
||||||
"?casino":casino_aide,\
|
"?casino":casino_aide,\
|
||||||
|
"?course":course,\
|
||||||
}
|
}
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
|
|
Loading…
Add table
Reference in a new issue