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 = [