更新 handler

This commit is contained in:
🌌 2023-10-16 21:35:30 +08:00
parent bcd4e84807
commit 2c74aea32e
3 changed files with 12 additions and 7 deletions

View File

@ -1,9 +1,10 @@
import util from 'node:util'
import lodash from 'lodash'
let events = {}
let Handler = {
add (cfg) {
let { ns, fn, property = 50 } = cfg
let { ns, fn, self, property = 50 } = cfg
let key = cfg.key || cfg.event
if (!key || !fn) {
return
@ -15,6 +16,7 @@ let Handler = {
property,
fn,
ns,
self,
key
})
events[key] = lodash.orderBy(events[key], ['priority'], ['asc'])
@ -38,7 +40,8 @@ let Handler = {
}
},
async callAll (key, e, args) {
return await Handler.callAll(key, e, args, true)
// 暂时屏蔽调用
// return Handler.call(key, e, args, true)
},
async call (key, e, args, allHandler = false) {
let ret
@ -51,9 +54,9 @@ let Handler = {
}
done = false
}
ret = fn(e, args, reject)
if (ret) {
await ret
ret = fn.call(obj.self, e, args, reject)
if (util.types.isPromise(ret)) {
ret = await ret
}
if (done && !allHandler) {
logger.mark(`[Handler][Done]: [${obj.ns}][${key}]`)

View File

@ -83,6 +83,7 @@ class PluginsLoader {
Handler.add({
ns: plugin.namespace || File.name,
key: key,
self: plugin,
property: priority || plugin.priority || 500,
fn: plugin[fn]
})
@ -776,6 +777,7 @@ class PluginsLoader {
Handler.add({
ns: plugin.namespace || File.name,
key: key,
self: plugin,
property: priority || plugin.priority || 500,
fn: plugin[fn]
})

View File

@ -19,11 +19,11 @@ export class update extends plugin {
priority: 4000,
rule: [
{
reg: '^#更新日志$',
reg: '^#更新日志',
fnc: 'updateLog'
},
{
reg: '^#(强制)?更新$',
reg: '^#(强制)?更新',
fnc: 'update'
},
{