roulette v2

This commit is contained in:
attilavs2 2025-05-06 21:11:55 +02:00
parent 7e2cab687a
commit 32d0433b5c

View file

@ -60,16 +60,47 @@ async def pingrand(message):
choice = random.choice(globals()["gmembers"][str(message.guild.id)])
await message.channel.send("<@"+str(choice.id)+">")
async def reload(message):
cursor.execute(f"CREATE TABLE IF NOT EXISTS roulette (gid INT PRIMARY KEY, shots INT)")
gid = int(message.guild.id)
ret = cursor.execute(f"SELECT shots FROM roulette WHERE gid = {gid}").fetchone()
shots = random.randint(0,5)
if ret == None:
cursor.execute(f"INSERT INTO roulette (gid,shots) VALUES ({gid},{shots})")
else:
cursor.execute(f"UPDATE roulette SET shots = {shots} WHERE gid = {gid}")
database.commit()
await message.channel.send("Revolver rechargé")
async def roulette(message):
roll = random.random()
if roll < 0.16666666666:
tdelt = datetime.timedelta(minutes=1)
cursor.execute(f"CREATE TABLE IF NOT EXISTS roulette (gid INT PRIMARY KEY, shots INT)")
database.commit()
gid = int(message.guild.id)
ret = cursor.execute(f"SELECT shots FROM roulette WHERE gid = {gid}").fetchone()
if ret == None:
shots = random.randint(0,5)
cursor.execute(f"INSERT INTO roulette (gid,shots) VALUES ({gid},{shots})")
database.commit()
else:
shots = ret[0]
print("Shots : ", shots)
if shots <= 0:
tdelt = datetime.timedelta(minutes=5)
uid = message.author.id
try:
await message.author.timeout(tdelt, reason="Vous avez perdu à la roulette...")
except:
await message.channel.send("Une erreur s'est produite ! (Je ne peux probablement pas vous timeout)")
await message.channel.send(f"<@{uid}> s'est tiré une balle, et est dans un coma pendant 5 minutes")
except Exception as err:
await message.channel.send("Une erreur s'est produite : `" + str(err) + "`")
nshots = random.randint(0,5)
cursor.execute(f"UPDATE roulette SET shots = {nshots} WHERE gid = {gid}")
database.commit()
else:
await message.channel.send("Ouf ! Il n'y avait pas de cartouche dans la chambre...")
shots -= 1
cursor.execute(f"UPDATE roulette SET shots = {shots} WHERE gid = {gid}")
database.commit()
await message.channel.send("Clic... il n'y avait pas de cartouche dans la chambre...")
async def casino_init(message):
usrid = int(message.author.id)
@ -126,6 +157,21 @@ async def collect(message):
else:
await message.channel.send(init_perso_str)
async def leaderboard(message):
uid = int(message.author.id)
gid = int(message.guild.id)
lb = None
result = cursor.execute(f"SELECT * FROM tab_{gid} ORDER BY cash DESC").fetchall()
msgstr = "## ===== Leaderboard =====\n"
i = 0
rlen = len(result)
while i < 10 and i < rlen:
uid = result[i][0]
ucash = result[i][1]
msgstr += " "+str(i+1)+f". <@{uid}> - {ucash}$\n"
i += 1
await message.channel.send(msgstr, allowed_mentions=discord.AllowedMentions().none())
async def ecoaide(message):
await message.channel.send("Eco+, un bot Eco plus pour faire des conneries\n"\
"?pinguncon : Ping le con local\n"\
@ -219,6 +265,8 @@ cmd_dict = {\
"?init":casino_init,\
"?cash":balance,\
"?collect":collect,\
"?lb":leaderboard,\
"?reload":reload,\
}
@client.event
@ -232,15 +280,17 @@ async def on_message(message):
return
if content[0] != "?":
return
if not content in cmd_dict:
await message.channel.send("Commande non reconnue !")
return
try:
await cmd_dict[content](message)
except Exception as err:
print(err)
await message.channel.send("Commande non reconnue !")
await message.channel.send("Une erreur s'est produite : `" + str(err) + "`")
def do_forgejo_thread():
print("229")
forgejo.app.run(port=5000)
forgejo_thread = threading.Thread()