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 +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +36 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.mts +8 -2
- package/dist/index.mjs +36 -5
- package/dist/index.mjs.map +1 -1
- package/dist/package-BbEBqdaV.mjs +6 -0
- package/dist/package-BbEBqdaV.mjs.map +1 -0
- package/dist/{package-CxmBPusE.cjs → package-D-IT6tID.cjs} +2 -2
- package/dist/package-D-IT6tID.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/package-CxmBPusE.cjs.map +0 -1
- package/dist/package-DnOvcNSm.mjs +0 -6
- package/dist/package-DnOvcNSm.mjs.map +0 -1
package/dist/cli.cjs
CHANGED
package/dist/cli.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_package = require('./package-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
});
|