forked from zovos/bot_tg
fix: syntax error in betting.py after merge conflict resolution
This commit is contained in:
parent
60e4cbfcfb
commit
acb7421cc0
1 changed files with 36 additions and 61 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue