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:
|
if not winner:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
is_draw = (winner.casefold() in _DRAW_NAMES or winner == "Draw")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||||
|
|
@ -544,68 +546,41 @@ async def settle_bets() -> list[tuple[int, str]]:
|
||||||
wcur = conn.cursor()
|
wcur = conn.cursor()
|
||||||
for bet in bets:
|
for bet in bets:
|
||||||
chosen = bet["chosen_team"]
|
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]:
|
if bet_won:
|
||||||
is_draw = True
|
winnings = round(bet["amount"] * bet["odds"], 1)
|
||||||
winner = "Draw"
|
update_user_length(bet["user_id"], winnings)
|
||||||
else:
|
wcur.execute(
|
||||||
max_score = -1
|
"UPDATE bets SET status = 'won', payout = %s, resolved_ts = %s WHERE id = %s",
|
||||||
for name, score_val in score_values:
|
(winnings, now_ts, bet["id"]),
|
||||||
if score_val > max_score:
|
)
|
||||||
max_score = score_val
|
notifications.append((
|
||||||
winner = name
|
bet["user_id"],
|
||||||
|
f"🎉 Ставка сыграла!\n"
|
||||||
if not winner:
|
f"🏟 {bet['home_team']} vs {bet['away_team']}\n"
|
||||||
continue
|
f"📌 {bet['chosen_team']} (x{bet['odds']:.2f})\n"
|
||||||
|
f"💰 Выигрыш: +{winnings:.1f} см",
|
||||||
try:
|
))
|
||||||
with get_conn() as conn:
|
logger.info("Bet won: user=%s match=%s winnings=%s", bet["user_id"], match_id, winnings)
|
||||||
cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
else:
|
||||||
cur.execute(
|
wcur.execute(
|
||||||
"SELECT * FROM bets WHERE match_id = %s AND status = 'pending'",
|
"UPDATE bets SET status = 'lost', payout = 0, resolved_ts = %s WHERE id = %s",
|
||||||
(match_id,),
|
(now_ts, bet["id"]),
|
||||||
)
|
)
|
||||||
bets = cur.fetchall()
|
notifications.append((
|
||||||
|
bet["user_id"],
|
||||||
wcur = conn.cursor()
|
f"❌ Ставка не сыграла\n"
|
||||||
for bet in bets:
|
f"🏟 {bet['home_team']} vs {bet['away_team']}\n"
|
||||||
chosen = bet["chosen_team"]
|
f"📌 {bet['chosen_team']} (x{bet['odds']:.2f})\n"
|
||||||
if is_draw:
|
f"💸 Потеряно: {bet['amount']:.1f} см",
|
||||||
bet_won = chosen.casefold() in _DRAW_NAMES or chosen == "Draw"
|
))
|
||||||
else:
|
logger.info("Bet lost: user=%s match=%s amount=%s", bet["user_id"], match_id, bet["amount"])
|
||||||
bet_won = chosen == winner
|
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()
|
cleanup_old_bets()
|
||||||
return notifications
|
return notifications
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue