@kotori-bot/kotori-plugin-core 1.5.0 → 1.5.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 CHANGED
@@ -1,3 +1,8 @@
1
- import { type Context } from 'kotori-bot';
1
+ import { type Context, Tsu } from 'kotori-bot';
2
2
  export declare const lang: string[];
3
- export declare function main(ctx: Context): void;
3
+ export declare const config: import("kotori-bot").ObjectParser<{
4
+ alias: import("kotori-bot").Parser<string | undefined>;
5
+ keywords: import("kotori-bot").Parser<string[]>;
6
+ content: import("kotori-bot").Parser<string | undefined>;
7
+ }>;
8
+ export declare function main(ctx: Context, cfg: Tsu.infer<typeof config>): void;
package/lib/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * @Package @kotori-bot/kotori-plugin-core
3
- * @Version 1.4.5
3
+ * @Version 1.5.0
4
4
  * @Author Hotaru <me@hotaru.icu>
5
5
  * @Copyright 2024-2025 Hotaru. All rights reserved.
6
- * @License BAN-ZHINESE-USING
6
+ * @License GPL-3.0
7
7
  * @Link https://github.com/kotorijs/kotori
8
- * @Date 2025/8/4 17:28:54
8
+ * @Date 2026/2/14 15:08:34
9
9
  */
10
10
  "use strict";
11
11
  var __defProp = Object.defineProperty;
@@ -27,14 +27,30 @@ var __copyProps = (to, from, except, desc) => {
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var index_exports = {};
29
29
  __export(index_exports, {
30
+ config: () => config,
30
31
  lang: () => lang,
31
32
  main: () => main
32
33
  });
33
34
  module.exports = __toCommonJS(index_exports);
34
35
  var import_kotori_bot = require("kotori-bot");
35
36
  const lang = [__dirname, "../locales"];
36
- function main(ctx) {
37
+ const config = import_kotori_bot.Tsu.Object({
38
+ alias: import_kotori_bot.Tsu.String().optional().describe("Menu command alias"),
39
+ keywords: import_kotori_bot.Tsu.Array(import_kotori_bot.Tsu.String()).default(["\u83DC\u5355", "\u529F\u80FD"]).describe("Menu command shortcuts"),
40
+ content: import_kotori_bot.Tsu.String().optional().describe("Custom menu command content")
41
+ });
42
+ function main(ctx, cfg) {
37
43
  ctx.on("before_command", (data) => {
44
+ if (data.command.meta.options.some((val) => val.realname === "help" || val.name === "H")) return;
45
+ if ([" -ihelp", " -H", " -h"].some((val) => data.raw.includes(val))) {
46
+ data.cancel();
47
+ ctx.emit(
48
+ "on_message",
49
+ Object.assign(data.session, {
50
+ message: /* @__PURE__ */ kotoriHTs("text", null, `${data.session.api.adapter.config.commandPrefix}help ${data.command.meta.root}`)
51
+ })
52
+ );
53
+ }
38
54
  const quick = data.session.quick.bind(data.session);
39
55
  if (!(data.result instanceof import_kotori_bot.CommandError)) {
40
56
  const { scope, access } = data.command.meta;
@@ -73,6 +89,10 @@ function main(ctx) {
73
89
  default:
74
90
  }
75
91
  });
92
+ if (cfg.content) {
93
+ const cmd = ctx.command("menu - core.descr.menu").shortcut(cfg.keywords).action((_, session) => session.format(String(cfg.content), { at: session.userId }));
94
+ if (cfg.alias) cmd.alias(cfg.alias);
95
+ }
76
96
  ctx.on("command", ({ result, session }) => {
77
97
  if (!(result instanceof import_kotori_bot.CommandError)) return;
78
98
  const { value } = result;
@@ -124,15 +144,11 @@ function main(ctx) {
124
144
  default:
125
145
  }
126
146
  });
127
- ctx.filter({
128
- test: import_kotori_bot.FilterTestList.USER_ID,
129
- operator: "==",
130
- value: "114514"
131
- }).command("core - core.descr.core").action((_, session) => {
132
- const { config, baseDir, options } = session.api.adapter.ctx;
147
+ ctx.command("core - core.descr.core").action((_, session) => {
148
+ const { config: config2, baseDir, options } = session.api.adapter.ctx;
133
149
  const botsLength = Array.from(ctx[import_kotori_bot.Symbols.bot].values()).map((set) => Array.from(set.values()).length).reduce((a, b) => a + b, 0);
134
150
  return session.format("core.msg.core", {
135
- lang: config.global.lang,
151
+ lang: config2.global.lang,
136
152
  root: baseDir.root,
137
153
  mode: options.mode,
138
154
  modules: ctx[import_kotori_bot.Symbols.modules] ? ctx[import_kotori_bot.Symbols.modules].size : 0,
@@ -144,10 +160,10 @@ function main(ctx) {
144
160
  });
145
161
  });
146
162
  ctx.command("bot - core.descr.bot").action((_, session) => {
147
- const { identity, platform, selfId, config, status } = session.api.adapter;
163
+ const { identity, platform, selfId, config: config2, status } = session.api.adapter;
148
164
  return session.format("core.msg.bot", {
149
165
  identity,
150
- lang: config.lang,
166
+ lang: config2.lang,
151
167
  platform,
152
168
  self_id: selfId,
153
169
  create_time: session.i18n.time(status.createTime),
@@ -161,9 +177,9 @@ function main(ctx) {
161
177
  (_, session) => session.format("core.msg.bots", {
162
178
  list: Array.from(ctx[import_kotori_bot.Symbols.bot].values()).map(
163
179
  (bots) => Array.from(bots.values()).map(
164
- ({ adapter: { identity, platform, config, status } }) => session.format("core.msg.bots.list", {
180
+ ({ adapter: { identity, platform, config: config2, status } }) => session.format("core.msg.bots.list", {
165
181
  identity,
166
- lang: config.lang,
182
+ lang: config2.lang,
167
183
  platform,
168
184
  status: status.value
169
185
  })
@@ -218,9 +234,66 @@ function main(ctx) {
218
234
  await session.quick("core.msg.restart");
219
235
  setTimeout(() => process.exit(233), 1);
220
236
  });
237
+ ctx.command("help [...command] - core.descr.help").action((data, session) => {
238
+ const args = data.args.join(" ");
239
+ const filterResult = [];
240
+ for (const command of ctx[import_kotori_bot.Symbols.command]) {
241
+ if (command.meta.hide) continue;
242
+ if (!command.meta.root.startsWith(args) && !command.meta.alias.some((alias) => alias.startsWith(args))) continue;
243
+ filterResult.push(command.meta);
244
+ }
245
+ if (filterResult.length === 0) return "core.msg.descr.fail";
246
+ let commands = "";
247
+ const short = filterResult.length === 1;
248
+ for (const cmd of filterResult) {
249
+ const alias = cmd.alias.length > 0 ? session.format("core.template.alias", {
250
+ content: cmd.alias.join(session.i18n.locale("core.template.alias.delimiter"))
251
+ }) : "";
252
+ let args2 = "";
253
+ let options = "";
254
+ const handle = (values) => {
255
+ for (const value of values) {
256
+ let defaultValue = "";
257
+ if ("rest" in value) {
258
+ const valueType = typeof value.default;
259
+ if (valueType === "string" || valueType === "number") {
260
+ defaultValue = session.format("core.template.default", { content: value.default });
261
+ } else if (valueType === "boolean") {
262
+ defaultValue = session.format("core.template.default", { content: value.default ? "true" : "false" });
263
+ }
264
+ args2 += session.format(`core.template.arg.${value.optional ? "optional" : "required"}`, {
265
+ name: value.rest ? `...${value.name}` : value.name,
266
+ type: value.type === "string" ? "" : session.format("core.template.arg.type", { content: value.type }),
267
+ default: defaultValue
268
+ });
269
+ }
270
+ if (!("realname" in value) || !("description" in value)) return;
271
+ options += session.format("core.template.option", {
272
+ name: value.name,
273
+ realname: value.realname,
274
+ type: value.type === "string" ? "" : session.format("core.template.arg.type", { content: value.type }),
275
+ description: value.description ? session.format("core.template.description", { content: session.i18n.locale(value.description) }) : ""
276
+ });
277
+ }
278
+ };
279
+ handle(cmd.args);
280
+ if (short) handle(cmd.options);
281
+ if (options) options = session.format("core.template.options", { content: options });
282
+ commands += session.format(`core.msg.descr.command${short ? "2" : ""}`, {
283
+ root: `${session.api.adapter.config.commandPrefix}${cmd.root}`,
284
+ args: args2,
285
+ description: cmd.description ? session.format("core.template.description", { content: session.i18n.locale(cmd.description) }) : "",
286
+ options,
287
+ help: cmd.help && short ? session.format("core.template.help", { content: session.i18n.locale(cmd.help) }) : "",
288
+ alias: short ? alias : ""
289
+ });
290
+ }
291
+ return short ? commands : session.format("core.msg.help", { content: commands });
292
+ });
221
293
  }
222
294
  // Annotate the CommonJS export names for ESM import in node:
223
295
  0 && (module.exports = {
296
+ config,
224
297
  lang,
225
298
  main
226
299
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kotori-bot/kotori-plugin-core",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "core plugin",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "author": "Hotaru <me@hotaru.icu>",
19
19
  "peerDependencies": {
20
- "kotori-bot": "^1.7.1"
20
+ "kotori-bot": "^1.7.3"
21
21
  },
22
22
  "kotori": {
23
23
  "meta": {