koishi-plugin-command-help 0.0.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.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { Context, Schema } from 'koishi';
2
+ export declare const name = "command-help";
3
+ export interface MenuItem {
4
+ command: string;
5
+ label?: string;
6
+ }
7
+ export interface MenuConfig {
8
+ cmdName: string;
9
+ description: string;
10
+ title: string;
11
+ subtitle: string;
12
+ items: MenuItem[];
13
+ }
14
+ export interface Config {
15
+ menus: MenuConfig[];
16
+ }
17
+ export declare const Config: Schema<Config>;
18
+ export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js ADDED
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Config: () => Config,
24
+ apply: () => apply,
25
+ name: () => name
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+ var import_koishi = require("koishi");
29
+ var name = "command-help";
30
+ var Config = import_koishi.Schema.object({
31
+ menus: import_koishi.Schema.array(import_koishi.Schema.object({
32
+ cmdName: import_koishi.Schema.string().description("触发菜单的指令名").required(),
33
+ description: import_koishi.Schema.string().description("该菜单指令本身的简短说明").default("显示功能菜单"),
34
+ title: import_koishi.Schema.string().description("菜单标题(如:指令:analyse)").required(),
35
+ subtitle: import_koishi.Schema.string().description("菜单副标题(如:数据分析)"),
36
+ items: import_koishi.Schema.array(import_koishi.Schema.object({
37
+ command: import_koishi.Schema.string().description("链接到的指令名").required(),
38
+ label: import_koishi.Schema.string().description("自定义说明(留空则自动获取指令原说明)")
39
+ })).role("table").description("菜单包含的内容列表")
40
+ })).description("自定义菜单列表")
41
+ });
42
+ function apply(ctx, config) {
43
+ for (const menu of config.menus) {
44
+ ctx.command(menu.cmdName, menu.description).action(async ({ session }) => {
45
+ let output = `指令:${menu.title}
46
+ `;
47
+ if (menu.subtitle) output += `${menu.subtitle}
48
+ `;
49
+ if (menu.items && menu.items.length > 0) {
50
+ output += `可用的子指令有:
51
+ `;
52
+ for (const item of menu.items) {
53
+ const targetCmd = ctx.command(item.command);
54
+ let desc = item.label;
55
+ if (!desc && targetCmd) {
56
+ const i18nKey = `commands.${targetCmd.name}.description`;
57
+ const text = session.text(i18nKey);
58
+ if (text && text !== i18nKey) {
59
+ desc = text;
60
+ } else {
61
+ desc = targetCmd._description || "";
62
+ }
63
+ }
64
+ output += ` /${item.command} ${desc || "暂无说明"}
65
+ `;
66
+ }
67
+ }
68
+ return output.trim();
69
+ });
70
+ }
71
+ }
72
+ __name(apply, "apply");
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ Config,
76
+ apply,
77
+ name
78
+ });
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "koishi-plugin-command-help",
3
+ "description": "Koishi 插件,为指令自定义仿help的聚合菜单",
4
+ "version": "0.0.1",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "files": [
8
+ "lib",
9
+ "dist"
10
+ ],
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "chatbot",
14
+ "koishi",
15
+ "plugin",
16
+ "command",
17
+ "help"
18
+ ],
19
+ "peerDependencies": {
20
+ "koishi": "^4.18.7"
21
+ }
22
+ }
package/readme.md ADDED
@@ -0,0 +1,5 @@
1
+ # koishi-plugin-command-help
2
+
3
+ [![npm](https://img.shields.io/npm/v/koishi-plugin-command-help?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-command-help)
4
+
5
+ Koishi 插件,为指令自定义仿help的聚合菜单