From 4e942608438188431abc6e2689ece79144f93db8 Mon Sep 17 00:00:00 2001 From: UCPr <2032385471@qq.com> Date: Tue, 26 Mar 2024 13:25:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=EF=BC=8Chook=E5=8F=AF=E9=80=89=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E7=BB=A7=E7=BB=AD=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins/loader.js | 11 +++++++---- lib/plugins/plugin.js | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index e92168d..b420898 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -213,8 +213,12 @@ class PluginsLoader { ...plugin.getContext(false, true), } if (!lodash.isEmpty(context)) { - for (const fnc in context) - plugin[fnc](context[fnc]) + let ret + for (const fnc in context) { + ret ||= await plugin[fnc](context[fnc]) + } + // 返回continue时,继续响应后续插件 + if (ret === 'continue') continue return } } @@ -250,8 +254,7 @@ class PluginsLoader { if (plugin.rule) for (const v of plugin.rule) { /** 判断事件 */ if (v.event && !this.filtEvent(e, v)) continue - /** 加入多行匹配符号 */ - if (!new RegExp(v.reg, 'sg').test(e.msg)) continue + if (!new RegExp.test(e.msg)) continue e.logFnc = `[${plugin.name}][${v.fnc}]` if (v.log !== false) diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js index 79e978c..16bcfe6 100644 --- a/lib/plugins/plugin.js +++ b/lib/plugins/plugin.js @@ -83,15 +83,16 @@ export default class plugin { * @param type 执行方法 * @param isGroup 是否群聊 * @param time 操作时间,默认120秒 + * @param {boolean} [silent=false] 是否静默,超时不回复消息 */ - setContext(type, isGroup, time = 120) { + setContext(type, isGroup, time = 120, silent = false) { const key = this.conKey(isGroup) if (!stateArr[key]) stateArr[key] = {} stateArr[key][type] = this.e if (time) stateArr[key][type].timeout = setTimeout(() => { if (stateArr[key][type]) { delete stateArr[key][type] - this.reply("操作超时已取消", true) + silent || this.reply("操作超时已取消", true) } }, time * 1000) } From ccbeafc390162863cf30907e9bc9ef36cfc6b8ce Mon Sep 17 00:00:00 2001 From: UCPr <2032385471@qq.com> Date: Tue, 26 Mar 2024 13:47:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins/plugin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js index 16bcfe6..38c0375 100644 --- a/lib/plugins/plugin.js +++ b/lib/plugins/plugin.js @@ -83,16 +83,16 @@ export default class plugin { * @param type 执行方法 * @param isGroup 是否群聊 * @param time 操作时间,默认120秒 - * @param {boolean} [silent=false] 是否静默,超时不回复消息 + * @param reply 超时时回复的内容,false则不回复 */ - setContext(type, isGroup, time = 120, silent = false) { + setContext(type, isGroup, time = 120, reply = "操作超时已取消") { const key = this.conKey(isGroup) if (!stateArr[key]) stateArr[key] = {} stateArr[key][type] = this.e if (time) stateArr[key][type].timeout = setTimeout(() => { if (stateArr[key][type]) { delete stateArr[key][type] - silent || this.reply("操作超时已取消", true) + this.reply(reply, true) } }, time * 1000) } From 3628a4c7f40795adc7ad67d93c2549a1b137ad6b Mon Sep 17 00:00:00 2001 From: UCPr <2032385471@qq.com> Date: Tue, 26 Mar 2024 14:20:45 +0800 Subject: [PATCH 3/3] update --- lib/plugins/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/loader.js b/lib/plugins/loader.js index b420898..0bb6854 100644 --- a/lib/plugins/loader.js +++ b/lib/plugins/loader.js @@ -254,7 +254,7 @@ class PluginsLoader { if (plugin.rule) for (const v of plugin.rule) { /** 判断事件 */ if (v.event && !this.filtEvent(e, v)) continue - if (!new RegExp.test(e.msg)) continue + if (!new RegExp(v.reg).test(e.msg)) continue e.logFnc = `[${plugin.name}][${v.fnc}]` if (v.log !== false)