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

Merge pull request !155 from UCPr/master
This commit is contained in:
Kokomi 2024-04-03 02:45:11 +00:00 committed by Gitee
commit ab08ea8775
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 10 additions and 6 deletions

View File

@ -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(v.reg).test(e.msg)) continue
e.logFnc = `[${plugin.name}][${v.fnc}]`
if (v.log !== false)

View File

@ -83,15 +83,16 @@ export default class plugin {
* @param type 执行方法
* @param isGroup 是否群聊
* @param time 操作时间默认120秒
* @param reply 超时时回复的内容false则不回复
*/
setContext(type, isGroup, time = 120) {
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]
this.reply("操作超时已取消", true)
this.reply(reply, true)
}
}, time * 1000)
}