fix(赛马插件): 修复进度条对齐并显示积分余额

修复赛马进度条显示时中文字符宽度计算问题,使用全角空格进行对齐
在积分结算时异步获取并显示用户当前积分余额
This commit is contained in:
2026-04-06 23:33:01 +08:00
parent 4aefb18435
commit 2b8afcb1b0
2 changed files with 7 additions and 4 deletions

View File

@@ -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))

View File

@@ -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)