From a2b7e1fc11782f42417492cb24fc37d678ae8341 Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Fri, 1 May 2026 23:04:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20settle=5Frace=E8=BF=94=E5=9B=9Etuple?= =?UTF-8?q?=E6=B6=88=E9=99=A4odds=E9=87=8D=E5=A4=8D=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - settle_race() 返回 tuple[RaceResult, odds] | None - run_race_with_settlement 解包使用,移除多余 calculate_odds 调用 - _test_send_to_scope 签名已兼容(含*args/**kwargs) --- danding_bot/plugins/group_horse_racing/commands.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/danding_bot/plugins/group_horse_racing/commands.py b/danding_bot/plugins/group_horse_racing/commands.py index 6f480ed..7a5aaec 100644 --- a/danding_bot/plugins/group_horse_racing/commands.py +++ b/danding_bot/plugins/group_horse_racing/commands.py @@ -226,8 +226,8 @@ def calculate_odds(room: Room) -> dict[str, float]: return odds -async def settle_race(room: Room) -> RaceResult | None: - """Settle bets and rewards after race finishes.""" +async def settle_race(room: Room) -> tuple[RaceResult, dict[str, float]] | None: + """Settle bets and rewards after race finishes. Returns (result, odds) or None.""" champion = room.horses.get(room.champion_name) if not champion: return None @@ -261,7 +261,7 @@ async def settle_race(room: Room) -> RaceResult | None: odds_snapshot=odds, ) await room_store.save_race_result(result) - return result + return result, odds async def _send_to_scope(bot: Bot, scope: str, message: str, message_type: str = "race_update"): @@ -303,14 +303,15 @@ async def run_race_with_settlement(bot: Bot, room: Room, scope: str): await points_service.refund_bet_points(bet.user_id, bet.amount, "比赛中断退还") return - # Settle - result = await settle_race(room) + # Settle (returns (result, odds) or None) + settlement = await settle_race(room) + result = settlement[0] if settlement else None + odds = settlement[1] if settlement else {} # Build user_id -> display name mapping all_user_ids = [h.owner_id for h in room.horses.values()] + [b.user_id for b in room.bets] name_map = await _build_name_map(bot, scope, all_user_ids) - odds = calculate_odds(room) champion = room.horses.get(room.champion_name) champion_name_display = name_map.get(champion.owner_id, champion.owner_id) if champion else '?' result_lines = [