feat: 新增 %角色名别名 查看角色别名 - #186
Merged
Merged
Conversation
插件已有「添加别名 / 删除别名」,但没有查看入口,主人无法确认某个角色
当前有哪些别名,容易重复添加或忘记加过什么。
- `src/apps/manage/alias.ts` 新增 `listAlias`:去掉指令前缀后匹配
`^(\S+)别名$`,用既有的 `char.aliasToName` 反查角色(角色本名、全名、
任意已有别名都能查),再从 `settings.getConfig('alias')` 取实际生效的
别名列表回复,与 `aliasToName` 同源,添加后立即可见
- `src/apps/manage.ts` 注册规则,放在 `addAlias`、`deleteAlias` 之后,
不影响原有两条指令的匹配
- `src/apps/help.ts` 补充帮助条目
指令正则较为宽泛,未匹配到角色时返回 `false` 交还给后续插件处理,
避免误吞其他插件以「别名」结尾的指令。
验证:`tsc --noEmit` 与 `eslint` 均通过;用真实 alias 配置跑过
角色本名 / 别名 / 全名反查、无别名角色、残缺指令与规则命中顺序,
`添加xx别名xx`、`删除别名xx` 仍分别命中 addAlias、deleteAlias。
Collaborator
这是预期行为,你要改也可以pr,都可以 |
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.
背景
插件已有「添加别名 / 删除别名」,但没有查看入口。主人加过别名之后无法确认某个角色当前到底有哪些别名,容易重复添加(撞上「别名 xxx 已存在」),也记不住自己加过什么。
实现
新增
%角色名别名,例如%南宫羽别名、%小羽别名。src/apps/manage/alias.ts新增listAlias:去掉指令前缀后匹配^(\S+)别名$,用既有的
char.aliasToName反查角色,再从settings.getConfig('alias')取实际生效的别名列表回复。取数与
aliasToName同源,添加后立即可见。src/apps/manage.ts注册规则,位置放在addAlias、deleteAlias之后。src/apps/help.ts补充帮助条目。角色本名、全名、任意一个已有别名都能查。指令正则较为宽泛,未匹配到角色时
返回
false交还给后续插件处理,避免误吞其他插件以「别名」结尾的指令。只改了 3 个文件、纯新增 38 行,没有触碰
addAlias/deleteAlias的任何逻辑。验证
npx tsc --noEmit与npx eslint "src/**/*.ts" "src/**/*.js"均通过(0 报错)。用真实的
config/alias.yaml与PartnerId2Data.json跑过下列用例:规则命中顺序(Yunzai 按
rule数组顺序匹配,命中即执行,返回false才继续):顺带发现的既有问题(本 PR 未处理)
settings.getConfig对alias是{ ...defSet, ...config }的浅合并,某个角色一旦被写进
config/alias.yaml,该角色整键覆盖defSet的值。所以插件更新时给老角色新增的默认别名,在已经跑过一段时间的实例上不会生效。
以「南宫羽」为例,
defSet里的「南官」「南工」在本地实例上查不到。这属于配置合并策略问题,和本 PR 的查看功能是两件事,就没在这里一起改。
需要的话我可以另开 PR 处理。