From 2b8afcb1b03040eff066499f16ccf8630773ad91 Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Mon, 6 Apr 2026 23:33:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=B5=9B=E9=A9=AC=E6=8F=92=E4=BB=B6):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9B=E5=BA=A6=E6=9D=A1=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E5=B9=B6=E6=98=BE=E7=A4=BA=E7=A7=AF=E5=88=86=E4=BD=99=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复赛马进度条显示时中文字符宽度计算问题,使用全角空格进行对齐 在积分结算时异步获取并显示用户当前积分余额 --- danding_bot/plugins/group_horse_racing/commands.py | 7 ++++--- danding_bot/plugins/group_horse_racing/race_engine.py | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/danding_bot/plugins/group_horse_racing/commands.py b/danding_bot/plugins/group_horse_racing/commands.py index f4e24ef..ec07346 100644 --- a/danding_bot/plugins/group_horse_racing/commands.py +++ b/danding_bot/plugins/group_horse_racing/commands.py @@ -190,7 +190,7 @@ def _build_point_changes(room: Room, odds: dict[str, float]) -> tuple[dict[str, return point_changes, point_summaries -def _format_point_change_lines(room: Room, point_changes: dict[str, int], point_summaries: dict[str, str], name_map: dict[str, str]) -> list[str]: +async def _format_point_change_lines(room: Room, point_changes: dict[str, int], point_summaries: dict[str, str], name_map: dict[str, str]) -> list[str]: ordered_user_ids: list[str] = [] for horse in _get_horses_in_order(room): if horse.owner_id not in ordered_user_ids: @@ -204,7 +204,8 @@ def _format_point_change_lines(room: Room, point_changes: dict[str, int], point_ delta = point_changes.get(user_id, 0) summary = point_summaries.get(user_id, _describe_points_delta(delta)) display_name = name_map.get(user_id, user_id) - lines.append(f" {display_name} {delta:+d} 积分 · {summary}") + balance = await points_service.get_balance(user_id) + lines.append(f" {display_name} {delta:+d} 积分 · {summary}(余额: {balance})") return lines @@ -324,7 +325,7 @@ async def run_race_with_settlement(bot: Bot, room: Room, scope: str): bettor_name = name_map.get(b.user_id, b.user_id) result_lines.append(f" {bettor_name} 下注 {b.amount} -> 获得 {payout}") if result: - result_lines.extend(_format_point_change_lines(room, result.point_changes, result.point_change_summaries, name_map)) + result_lines.extend(await _format_point_change_lines(room, result.point_changes, result.point_change_summaries, name_map)) await _send_to_scope(bot, scope, "\n".join(result_lines)) diff --git a/danding_bot/plugins/group_horse_racing/race_engine.py b/danding_bot/plugins/group_horse_racing/race_engine.py index 9b8f67d..bf20a63 100644 --- a/danding_bot/plugins/group_horse_racing/race_engine.py +++ b/danding_bot/plugins/group_horse_racing/race_engine.py @@ -72,7 +72,9 @@ class RaceEngine: progress = min(horse.position / distance, 1.0) filled = int(progress * bar_width) bar = "█" * filled + "░" * (bar_width - filled) - pad = " " * (max_name_width - _display_width(horse.name)) + # Pad with fullwidth spaces (1 fullwidth space = 2 columns = 1 CJK char width) + diff = max_name_width - _display_width(horse.name) + pad = "\u3000" * (diff // 2) + (" " if diff % 2 else "") lines.append(f" {horse.index:02d}号 {horse.name}{pad} |{bar}| {horse.position:.1f}m") return "\n".join(lines)