删除多余匹配,hook可选是否继续响应

This commit is contained in:
UCPr 2024-03-26 13:25:21 +08:00
parent 657a1bf877
commit 4e94260843
2 changed files with 10 additions and 6 deletions

View File

@ -213,8 +213,12 @@ class PluginsLoader {
...plugin.getContext(false, true), ...plugin.getContext(false, true),
} }
if (!lodash.isEmpty(context)) { if (!lodash.isEmpty(context)) {
for (const fnc in context) let ret
plugin[fnc](context[fnc]) for (const fnc in context) {
ret ||= await plugin[fnc](context[fnc])
}
// 返回continue时继续响应后续插件
if (ret === 'continue') continue
return return
} }
} }
@ -250,8 +254,7 @@ class PluginsLoader {
if (plugin.rule) for (const v of plugin.rule) { if (plugin.rule) for (const v of plugin.rule) {
/** 判断事件 */ /** 判断事件 */
if (v.event && !this.filtEvent(e, v)) continue if (v.event && !this.filtEvent(e, v)) continue
/** 加入多行匹配符号 */ if (!new RegExp.test(e.msg)) continue
if (!new RegExp(v.reg, 'sg').test(e.msg)) continue
e.logFnc = `[${plugin.name}][${v.fnc}]` e.logFnc = `[${plugin.name}][${v.fnc}]`
if (v.log !== false) if (v.log !== false)

View File

@ -83,15 +83,16 @@ export default class plugin {
* @param type 执行方法 * @param type 执行方法
* @param isGroup 是否群聊 * @param isGroup 是否群聊
* @param time 操作时间默认120秒 * @param time 操作时间默认120秒
* @param {boolean} [silent=false] 是否静默超时不回复消息
*/ */
setContext(type, isGroup, time = 120) { setContext(type, isGroup, time = 120, silent = false) {
const key = this.conKey(isGroup) const key = this.conKey(isGroup)
if (!stateArr[key]) stateArr[key] = {} if (!stateArr[key]) stateArr[key] = {}
stateArr[key][type] = this.e stateArr[key][type] = this.e
if (time) stateArr[key][type].timeout = setTimeout(() => { if (time) stateArr[key][type].timeout = setTimeout(() => {
if (stateArr[key][type]) { if (stateArr[key][type]) {
delete stateArr[key][type] delete stateArr[key][type]
this.reply("操作超时已取消", true) silent || this.reply("操作超时已取消", true)
} }
}, time * 1000) }, time * 1000)
} }