Repository navigation
Conversation
Xbaiyz12
force-pushed
the
feat/role-alias
branch
3 times, most recently
from
October 3, 2026 16:47
e6b2d63 to
b537ca7
Compare
用户常按别名/简称称呼角色(小西王、dj、心月狐…),插件此前只做精确名匹配, 别名一律匹配不到,指定角色与台词查找都会落空。 新增 TodayWaifu/aliases.py,并加配置项 DailyWifeAliasSource(默认 off): - off:关闭别名解析(默认) - xwuid:使用 XWUID 的别名表,把它的内置表 data/XutheringWavesUID/resource/map/alias/char_alias.json 与用户自定义表 alias/char_alias.json 按 XWUID 语义合并(同一角色别名取并集);该插件未安装时 自动改用插件自带的别名表 - local:始终使用插件自带的别名表 配置描述里已写明适用人群:别名用于「指定老婆」这类需要匹配角色名的场景,而指定 角色仅限机器人主人或指定老婆白名单用户使用。 插件根随包分发 role_aliases.json,保证没装 XWUID 的用户也有别名可用;配置值异常时 一律关闭别名,不擅自挑一份表。 匹配只做精确匹配,不用子串模糊匹配:单字角色名(如「心」)用子串匹配会误命中 「鉴心」,这也是之前串台问题的成因之一。 _normalize_role_name 在间隔号归一之后接一层别名解析,因此指定角色、老婆列表、 抢老婆、送礼等所有走该函数的入口一起生效。索引按来源与文件 mtime 缓存,别名表更新 后无需重启即可生效。 同步更新 tests/compatibility_manifest.json,并新增 tests/test_role_alias.py(13 项行为 测试):默认关闭、xwuid 优先、未装 XWUID 回退本地、配置 local 时忽略 XWUID、异常配置 值关闭别名、标准名不被顶掉、未知名原样返回、缺文件降级、坏 JSON 跳过、别名表更新后 热生效,以及 _normalize_role_name 的集成。 验证:pytest tests/ -q -> 374 passed;ruff check -> All checks passed。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
用户经常按别名/简称称呼角色(
小西王、dj、心月狐…),但插件此前只做精确名匹配,别名一律匹配不到:指定角色会提示「未找到名为 XX 的角色」,台词查找也会落空。改动
新增
TodayWaifu/aliases.py:直接复用 XutheringWavesUID 的别名表,不另建一份数据。data/XutheringWavesUID/resource/map/alias/char_alias.jsondata/XutheringWavesUID/alias/char_alias.json按 XWUID 的语义把两份表合并(同一角色的别名取并集),因此用户在 XWUID 里加过的别名在这里同样生效。XWUID 未安装或文件缺失时降级为空表、名字原样返回,不影响插件运行。
_normalize_role_name在间隔号归一之后接一层别名解析,所以指定角色、老婆列表、抢老婆、送礼等所有走该函数的入口一起生效。索引按文件 mtime 缓存,别名表更新后无需重启即可生效。只做精确匹配,不用子串模糊匹配——单字角色名(如「心」)用子串匹配会误命中「鉴心」,这正是之前串台问题的成因之一。
验证
python -m pytest tests/ -q→ 369 passedruff.toml:ruff check→ All checks passedtests/test_role_alias.py(8 项行为级测试):别名解析、标准名不被别名顶掉、两份表合并、未知名字原样返回、首尾空白、缺文件时降级、别名表更新后热生效,以及_normalize_role_name的集成备注
测试用临时目录造出两份别名表,因此不依赖 XWUID 是否安装,CI 上同样能覆盖这些逻辑。