bug fix i think
This commit is contained in:
parent
2449d0955b
commit
138b7aab90
@ -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()
|
||||||
|
@ -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)
|
||||||
|
57
main.py
57
main.py
@ -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():
|
||||||
async with websockets.connect(GATEWAY_URL) as websocket:
|
while True:
|
||||||
response = json.loads(await websocket.recv())
|
try:
|
||||||
heartbeat_interval = response["d"]["heartbeat_interval"]
|
async with websockets.connect(GATEWAY_URL) as websocket:
|
||||||
|
response = json.loads(await websocket.recv())
|
||||||
|
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)
|
while True:
|
||||||
|
try:
|
||||||
|
response = json.loads(await websocket.recv())
|
||||||
|
op = response.get("op")
|
||||||
|
|
||||||
connected = True
|
match op:
|
||||||
while connected:
|
case OpCode.DISPATCH:
|
||||||
response = json.loads(await websocket.recv())
|
await get_event(response)
|
||||||
match response["op"]:
|
case OpCode.RECONNECT:
|
||||||
case OpCode.DISPATCH:
|
print("Reconnexion demandée...")
|
||||||
await get_event(response)
|
break
|
||||||
case OpCode.RECONNECT:
|
case OpCode.INVALID_SESSION:
|
||||||
print("Reconnexion...")
|
print("Session invalide, réidentification...")
|
||||||
connected = False
|
await asyncio.sleep(1)
|
||||||
case _:
|
await identify(websocket)
|
||||||
|
case _:
|
||||||
|
pass
|
||||||
|
|
||||||
|
except websockets.exceptions.ConnectionClosed as e:
|
||||||
|
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
|
pass
|
||||||
|
|
||||||
# Reconnexion
|
except Exception as e:
|
||||||
await websocket.close()
|
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():
|
||||||
|
Loading…
Reference in New Issue
Block a user