fix: 增加插件函数类型判断

This commit is contained in:
ningmengchongshui 2024-06-15 09:43:49 +08:00
parent 54aa32d0e4
commit 61163fbe30
1 changed files with 36 additions and 35 deletions

View File

@ -306,6 +306,24 @@ class PluginsLoader {
*/
await Runtime.init(e)
// 判断是否是星铁命令,若是星铁命令则标准化处理
// e.isSr = true且命令标准化为 #星铁 开头
Object.defineProperty(e, 'isSr', {
get: () => e.game === 'sr',
set: v => (e.game = v ? 'sr' : 'gs')
})
Object.defineProperty(e, 'isGs', {
get: () => e.game === 'gs',
set: v => (e.game = v ? 'gs' : 'sr')
})
/**
*
*/
if (this.srReg.test(e.msg)) {
e.game = 'sr'
e.msg = e.msg.replace(this.srReg, '#星铁')
}
/**
*
*/
@ -315,8 +333,8 @@ class PluginsLoader {
*
*/
for (const i of this.priority) {
// tudo e 为参数将废弃
const p = new i.class(e)
// 现在给e后续e将无法访问新增字段
p.e = e
/**
*
@ -339,6 +357,11 @@ class PluginsLoader {
if (!lodash.isEmpty(context)) {
let ret
for (const fnc in context) {
// 不是函数,错误插件错误写法
if (typeof plugin[fnc] !== 'function') {
// logger.info(plugin, fnc, '不是函数')
continue
}
ret ||= await plugin[fnc](context[fnc])
}
// 返回continue时继续响应后续插件
@ -352,26 +375,6 @@ class PluginsLoader {
*/
if (!this.onlyReplyAt(e)) return
// 判断是否是星铁命令,若是星铁命令则标准化处理
// e.isSr = true且命令标准化为 #星铁 开头
Object.defineProperty(e, 'isSr', {
get: () => e.game === 'sr',
set: v => (e.game = v ? 'sr' : 'gs')
})
Object.defineProperty(e, 'isGs', {
get: () => e.game === 'gs',
set: v => (e.game = v ? 'gs' : 'sr')
})
/**
*
*/
if (this.srReg.test(e.msg)) {
e.game = 'sr'
e.msg = e.msg.replace(this.srReg, '#星铁')
}
/**
* accept
*/
@ -423,21 +426,17 @@ class PluginsLoader {
*/
try {
const start = Date.now()
/**
*
*/
const res = plugin[v.fnc] && (await plugin[v.fnc](e))
/**
* res false ,
* return false
* tudo
*
* return true的时候
*
*
*/
if (res !== false) {
// 不是函数。
if (typeof plugin[v.fnv] !== 'function') {
continue
}
const res = await plugin[v.fnc](e)
// 非常规返回不是true直接结束。
if (typeof res != 'boolean' && res !== true) {
/**
* cd
*/
@ -449,6 +448,8 @@ class PluginsLoader {
}
break
}
//
} catch (error) {
logger.error(`${e.logFnc}`)
logger.error(error.stack)