mioki 0.7.7 → 0.8.0

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/dist/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_package = require('./package-CxmBPusE.cjs');
2
+ const require_package = require('./package-D-IT6tID.cjs');
3
3
  let node_fs = require("node:fs");
4
4
  node_fs = require_package.__toESM(node_fs);
5
5
  let node_path = require("node:path");
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as version } from "./package-DnOvcNSm.mjs";
2
+ import { t as version } from "./package-BbEBqdaV.mjs";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import mri from "mri";
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_package = require('./package-CxmBPusE.cjs');
1
+ const require_package = require('./package-D-IT6tID.cjs');
2
2
  let node_fs = require("node:fs");
3
3
  node_fs = require_package.__toESM(node_fs);
4
4
  let node_util = require("node:util");
@@ -204,6 +204,11 @@ function formatDuration(ms) {
204
204
  /**
205
205
  * 匹配输入文本与匹配模式,如果匹配成功,则回复匹配结果
206
206
  *
207
+ * 支持:
208
+ * - 精确匹配
209
+ * - 正则表达式匹配(以 `/` 开头和结尾的字符串)
210
+ * - 通配符匹配(使用 `*` 作为通配符)
211
+ *
207
212
  * @param event 消息事件
208
213
  * @param pattern 匹配模式
209
214
  * @param quote 是否引用回复
@@ -211,9 +216,35 @@ function formatDuration(ms) {
211
216
  */
212
217
  async function match(event, pattern, quote = true) {
213
218
  const inputText = text(event);
214
- for (const [key, value] of Object.entries(pattern)) if (key === inputText) {
215
- const res = await (typeof value === "function" ? value() : value);
216
- if (res) return event.reply(res, quote);
219
+ async function handleMatch(key, value) {
220
+ let isMatched = false;
221
+ let matches = null;
222
+ const isRegExpLikeString = key.match(/^\/.+\/$/);
223
+ const hasWildcard = key.includes("*");
224
+ if (isRegExpLikeString) try {
225
+ const regex = new RegExp(key.slice(1, -1));
226
+ const matchesValue = inputText.match(regex);
227
+ if (matchesValue) {
228
+ isMatched = true;
229
+ matches = matchesValue;
230
+ }
231
+ } catch (err) {
232
+ throw new Error(`无效的正则表达式: ${key}`, { cause: err });
233
+ }
234
+ else if (hasWildcard) {
235
+ const regexPattern = `^${key.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`;
236
+ const regex = new RegExp(regexPattern);
237
+ const matchesValue = inputText.match(regex);
238
+ if (matchesValue) {
239
+ isMatched = true;
240
+ matches = matchesValue;
241
+ }
242
+ } else if (key === inputText) isMatched = true;
243
+ if (isMatched) return typeof value === "function" ? await value(matches, event) : value;
244
+ }
245
+ for (const [key, value] of Object.entries(pattern)) {
246
+ const result = await handleMatch(key, value);
247
+ if (result) return event.reply(result, quote);
217
248
  }
218
249
  return null;
219
250
  }
@@ -1826,7 +1857,7 @@ async function start(options = {}) {
1826
1857
  const failedCount = failedImportPlugins.length + failedEnablePlugins.length;
1827
1858
  const failedInfo = failedCount > 0 ? `${consola_utils.colors.red(failedCount)} 个失败 (导入 ${consola_utils.colors.red(failedImportPlugins.length)},启用 ${consola_utils.colors.red(failedEnablePlugins.length)})` : "";
1828
1859
  napcat.logger.info(`成功加载了 ${consola_utils.colors.green(runtimePlugins.size)} 个插件,${failedInfo ? failedInfo : ""}总耗时 ${consola_utils.colors.green(costTime.toFixed(2))} 毫秒`);
1829
- napcat.logger.info(consola_utils.colors.green(`mioki v${require_package.version} 启动完成,祝您使用愉快 🎉️`));
1860
+ napcat.logger.info(consola_utils.colors.green(`mioki v${require_package.version} 启动完成,向机器人发送「${consola_utils.colors.magentaBright(`${botConfig.prefix}帮助`)}」查看消息指令`));
1830
1861
  if (botConfig.online_push) await noticeMainOwner(napcat, `✅ mioki v${require_package.version} 已就绪`).catch((err) => {
1831
1862
  napcat.logger.error(`发送就绪通知失败: ${stringifyError(err)}`);
1832
1863
  });