feat: 补充插件类型声明

This commit is contained in:
ningmengchongshui 2024-06-12 10:40:10 +08:00
parent d76c0c447f
commit 884b21c7ae
2 changed files with 75 additions and 81 deletions

View File

@ -1,5 +1,6 @@
import { MessageCallBackType } from './types.js'
import { plugin } from './index.js'
import { EventMap } from 'icqq'
/**
* super默认值
@ -7,7 +8,7 @@ import { plugin } from './index.js'
export const PluginSuperDefine: {
name?: string
dsc?: string
event?: string
event?: keyof EventMap
priority?: number
} = {
name: 'group-app',

View File

@ -2,105 +2,98 @@
import { Common } from '../../miao.js'
import { EventType } from './types.js'
import { type EventMap } from 'icqq'
const State = {}
const SymbolTimeout = Symbol('Timeout')
const SymbolResolve = Symbol('Resolve')
export class Plugin {
/**
* @deprecated
*/
name = 'your-plugin'
/**
* @deprecated
*/
dsc = '无'
/**
* @deprecated
*/
task = null
/**
*
*/
rule: {
reg?: RegExp | string
fnc: string
event?: string
log?: boolean
permission?: string
}[] = []
/**
*
*/
event = 'message'
/**
*
*/
priority = 9999
/**
*
*/
namespace = null
/**
*
*/
handler = null
/**
*
*/
e: EventType
type PluginSuperType = {
/**
* @param name
* @deprecated
*/
name?: string
/**
* @param dsc
* @deprecated
*/
dsc?: string
/**
* namespacehandler时建议设置
* @deprecated
*/
namespace?: any
/**
* @param handler handler配置
* @param handler.key handler支持的事件key
* @param handler.fn handler的处理func
* @param namespace namespacehandler时建议设置
* @deprecated
*/
handler?: any
/**
* task
* task.name
* task.cron cron表达式
* task.fnc
* task.log false时不显示执行日志
* @deprecated
*/
task?: any
/**
*
*/
priority?: number
/**
*
*/
event?: keyof EventMap
/**
* rule
* rule.reg
* rule.fnc
* rule.event message
* rule.log false时不显示执行日志
* rule.permission master,owner,admin,all
*/
rule?: {
reg?: RegExp,
fnc?: string,
event?: keyof EventMap,
log?: boolean
permission?: 'master' | 'owner' | 'admin' | 'all'
}[]
}
export class Plugin {
name: PluginSuperType['name'] = 'your-plugin'
dsc: PluginSuperType['dsc'] = '无'
task: PluginSuperType['task'] = null
rule: PluginSuperType['rule'] = []
event: PluginSuperType['event'] = 'message'
priority: PluginSuperType['priority'] = 9999
namespace: PluginSuperType['namespace'] = null
handler: PluginSuperType['handler'] = null
e: EventType
/**
* @param event message
* @param priority
* @param rule
* @param rule.reg
* @param rule.fnc
* @param rule.event message
* @param rule.log false时不显示执行日志
* @param rule.permission master,owner,admin,all
* @param task
* @param task.name
* @param task.cron cron表达式
* @param task.fnc
* @param task.log false时不显示执行日志
* @param rule
*/
constructor({
event,
priority = 5000,
rule,
name,
dsc,
handler,
namespace,
event,
priority = 5000,
task,
rule
}: {
/**
* @deprecated
*/
name?: typeof this.name
/**
* @deprecated
*/
dsc?: typeof this.dsc
namespace?: typeof this.namespace
priority?: typeof this.priority
handler?: typeof this.handler
event?: typeof this.event
/**
* @deprecated
*/
task?: typeof this.task
rule?: typeof this.rule
}) {
}: PluginSuperType) {
name && (this.name = name)
dsc && (this.dsc = dsc)
event && (this.event = event)