bug fix i think

This commit is contained in:
guams 2025-05-21 14:26:42 +02:00
parent 2449d0955b
commit 138b7aab90
3 changed files with 42 additions and 21 deletions

View File

@ -291,8 +291,8 @@ async def minus_user_points(conn: connection, user_id: str, bet_value: int):
cur.execute( cur.execute(
"UPDATE member " "UPDATE member "
"SET points = points - %s " "SET points = points - %s "
"WHERE user_id=%s", "WHERE user_id = %s AND points - %s >= 50",
(bet_value, user_id) (bet_value, user_id, bet_value)
) )
conn.commit() conn.commit()

View File

@ -35,7 +35,7 @@ CREATE TABLE member
user_id VARCHAR(255), user_id VARCHAR(255),
guild_id VARCHAR(255), guild_id VARCHAR(255),
username VARCHAR(255), username VARCHAR(255),
points bigint DEFAULT 50 NOT NULL CHECK (points >= 50), points bigint DEFAULT 50,
bet_value bigint DEFAULT 50, bet_value bigint DEFAULT 50,
PRIMARY KEY (user_id), PRIMARY KEY (user_id),
FOREIGN KEY (guild_id) REFERENCES guild (guild_id) FOREIGN KEY (guild_id) REFERENCES guild (guild_id)

41
main.py
View File

@ -542,30 +542,51 @@ async def change_bet_cmd(guild_id: str, command_option: int, user_id: str, usern
async def connect(): async def connect():
while True:
try:
async with websockets.connect(GATEWAY_URL) as websocket: async with websockets.connect(GATEWAY_URL) as websocket:
response = json.loads(await websocket.recv()) response = json.loads(await websocket.recv())
heartbeat_interval = response["d"]["heartbeat_interval"] heartbeat_interval = response["d"]["heartbeat_interval"]
asyncio.create_task(heartbeat(websocket, heartbeat_interval)) heartbeat_task = asyncio.create_task(heartbeat(websocket, heartbeat_interval))
await identify(websocket) await identify(websocket)
connected = True while True:
while connected: try:
response = json.loads(await websocket.recv()) response = json.loads(await websocket.recv())
match response["op"]: op = response.get("op")
match op:
case OpCode.DISPATCH: case OpCode.DISPATCH:
await get_event(response) await get_event(response)
case OpCode.RECONNECT: case OpCode.RECONNECT:
print("Reconnexion...") print("Reconnexion demandée...")
connected = False break
case OpCode.INVALID_SESSION:
print("Session invalide, réidentification...")
await asyncio.sleep(1)
await identify(websocket)
case _: case _:
pass pass
# Reconnexion except websockets.exceptions.ConnectionClosed as e:
await websocket.close() print(f"Connexion fermée : {e}")
break
except Exception as e:
print(f"Erreur dans le loop principal : {e}")
break
heartbeat_task.cancel()
try:
await heartbeat_task
except asyncio.CancelledError:
pass
except Exception as e:
print(f"Erreur de connexion WebSocket : {e}")
print("Tentative de reconnexion dans 5 secondes...")
await asyncio.sleep(5) await asyncio.sleep(5)
await connect()
async def main(): async def main():