From acb7421cc003d41e4115d36de626edcc81f39a71 Mon Sep 17 00:00:00 2001 From: zovos Date: Wed, 20 May 2026 10:24:38 +0000 Subject: [PATCH] fix: syntax error in betting.py after merge conflict resolution --- games/betting.py | 97 ++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/games/betting.py b/games/betting.py index d3e132c..c444cd2 100644 --- a/games/betting.py +++ b/games/betting.py @@ -532,6 +532,8 @@ async def settle_bets() -> list[tuple[int, str]]: if not winner: continue + is_draw = (winner.casefold() in _DRAW_NAMES or winner == "Draw") + try: with get_conn() as conn: cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) @@ -544,68 +546,41 @@ async def settle_bets() -> list[tuple[int, str]]: wcur = conn.cursor() for bet in bets: chosen = bet["chosen_team"] - bet_won = (chosen == winner) + if is_draw: + bet_won = chosen.casefold() in _DRAW_NAMES or chosen == "Draw" + else: + bet_won = chosen == winner - if len(score_values) >= 2 and score_values[0][1] == score_values[1][1]: - is_draw = True - winner = "Draw" - else: - max_score = -1 - for name, score_val in score_values: - if score_val > max_score: - max_score = score_val - winner = name - - if not winner: - continue - - try: - with get_conn() as conn: - cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) - cur.execute( - "SELECT * FROM bets WHERE match_id = %s AND status = 'pending'", - (match_id,), - ) - bets = cur.fetchall() - - wcur = conn.cursor() - for bet in bets: - chosen = bet["chosen_team"] - if is_draw: - bet_won = chosen.casefold() in _DRAW_NAMES or chosen == "Draw" - else: - bet_won = chosen == winner - - if bet_won: - winnings = round(bet["amount"] * bet["odds"], 1) - update_user_length(bet["user_id"], winnings) - wcur.execute( - "UPDATE bets SET status = 'won', payout = %s, resolved_ts = %s WHERE id = %s", - (winnings, now_ts, bet["id"]), - ) - notifications.append(( - bet["user_id"], - f"🎉 Ставка сыграла!\n" - f"🏟 {bet['home_team']} vs {bet['away_team']}\n" - f"📌 {bet['chosen_team']} (x{bet['odds']:.2f})\n" - f"💰 Выигрыш: +{winnings:.1f} см", - )) - logger.info("Bet won: user=%s match=%s winnings=%s", bet["user_id"], match_id, winnings) - else: - wcur.execute( - "UPDATE bets SET status = 'lost', payout = 0, resolved_ts = %s WHERE id = %s", - (now_ts, bet["id"]), - ) - notifications.append(( - bet["user_id"], - f"❌ Ставка не сыграла\n" - f"🏟 {bet['home_team']} vs {bet['away_team']}\n" - f"📌 {bet['chosen_team']} (x{bet['odds']:.2f})\n" - f"💸 Потеряно: {bet['amount']:.1f} см", - )) - logger.info("Bet lost: user=%s match=%s amount=%s", bet["user_id"], match_id, bet["amount"]) - except psycopg2.Error: - logger.exception("Failed to settle bets") + if bet_won: + winnings = round(bet["amount"] * bet["odds"], 1) + update_user_length(bet["user_id"], winnings) + wcur.execute( + "UPDATE bets SET status = 'won', payout = %s, resolved_ts = %s WHERE id = %s", + (winnings, now_ts, bet["id"]), + ) + notifications.append(( + bet["user_id"], + f"🎉 Ставка сыграла!\n" + f"🏟 {bet['home_team']} vs {bet['away_team']}\n" + f"📌 {bet['chosen_team']} (x{bet['odds']:.2f})\n" + f"💰 Выигрыш: +{winnings:.1f} см", + )) + logger.info("Bet won: user=%s match=%s winnings=%s", bet["user_id"], match_id, winnings) + else: + wcur.execute( + "UPDATE bets SET status = 'lost', payout = 0, resolved_ts = %s WHERE id = %s", + (now_ts, bet["id"]), + ) + notifications.append(( + bet["user_id"], + f"❌ Ставка не сыграла\n" + f"🏟 {bet['home_team']} vs {bet['away_team']}\n" + f"📌 {bet['chosen_team']} (x{bet['odds']:.2f})\n" + f"💸 Потеряно: {bet['amount']:.1f} см", + )) + logger.info("Bet lost: user=%s match=%s amount=%s", bet["user_id"], match_id, bet["amount"]) + except psycopg2.Error: + logger.exception("Failed to settle bets") cleanup_old_bets() return notifications