koishi-plugin-newapi-status 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +31 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -553,6 +553,37 @@ function apply(ctx, config) {
|
|
|
553
553
|
return testAction(model ? String(model) : undefined, credential ? String(credential) : undefined);
|
|
554
554
|
}));
|
|
555
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Koishi help 的 formatCommands 只迭代 command.children——只列一层子指令,
|
|
558
|
+
* 所以 `nekoapi` 的帮助里看不到 `nekoapi model status` 这类二级指令。
|
|
559
|
+
* showHelp 会 emit('help/command', output, command, session),这里从指令注册表里
|
|
560
|
+
* 把二级指令补进同一个 output;仍然是一条 Koishi help 消息,不额外多发一条。
|
|
561
|
+
*/
|
|
562
|
+
// 事件名由 @koishijs/plugin-help 声明,宿主没装它时类型里没有这个 key,这里放宽类型
|
|
563
|
+
ctx.on('help/command', (output, command, session) => {
|
|
564
|
+
const scope = String(command?.name ?? '');
|
|
565
|
+
if (!prefixes.includes(scope))
|
|
566
|
+
return;
|
|
567
|
+
const lines = [];
|
|
568
|
+
for (const child of command.children ?? []) {
|
|
569
|
+
for (const grand of child.children ?? []) {
|
|
570
|
+
if (session && session.resolve(grand.config?.hidden))
|
|
571
|
+
continue;
|
|
572
|
+
const title = String(grand.displayName ?? grand.name).replace(/\./g, ' ');
|
|
573
|
+
const desc = session ? session.text([`commands.${grand.name}.description`, '']) : '';
|
|
574
|
+
lines.push(` /${title}${grand.declaration ?? ''}${desc ? ' ' + desc : ''}`);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
// `test list` 不是独立指令,但它是最常用的用法之一,单独补一行
|
|
578
|
+
const usage = commandList(scope, clampHours(config.healthHours, 1))
|
|
579
|
+
.find(item => item.usage === `${scope} test list`);
|
|
580
|
+
if (usage && (command.children ?? []).some((child) => child.name === `${scope}.test`)) {
|
|
581
|
+
lines.push(` /${usage.usage} ${(0, api_1.sanitize)(usage.desc, ...secrets())}`);
|
|
582
|
+
}
|
|
583
|
+
if (!lines.length)
|
|
584
|
+
return;
|
|
585
|
+
output.push('', '二级子指令:', ...lines);
|
|
586
|
+
});
|
|
556
587
|
logger.info('插件已加载:前缀 %s,站点 %s,渲染 %s,日志等级 %s', prefixes.join(', '), (0, view_1.hostOf)(config.baseUrl), config.render, config.logLevel);
|
|
557
588
|
if (config.monitor.enabled) {
|
|
558
589
|
ctx.on('ready', () => {
|