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] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=EF=BC=8Chook=E5=8F=AF=E9=80=89=E6=98=AF=E5=90=A6?= =?UTF-8?q?=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) }