From 884b21c7ae2bf940426cafe7ebc6cc35d24c61eb Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Wed, 12 Jun 2024 10:40:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/plugins/functional.ts | 3 +- src/core/plugins/index.ts | 153 ++++++++++++++++----------------- 2 files changed, 75 insertions(+), 81 deletions(-) diff --git a/src/core/plugins/functional.ts b/src/core/plugins/functional.ts index c930ce9..586815c 100644 --- a/src/core/plugins/functional.ts +++ b/src/core/plugins/functional.ts @@ -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', diff --git a/src/core/plugins/index.ts b/src/core/plugins/index.ts index 642a681..b79aac3 100644 --- a/src/core/plugins/index.ts +++ b/src/core/plugins/index.ts @@ -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 + /** + * namespace,设置handler时建议设置 + * @deprecated 已废弃 + */ + namespace?: any + /** * @param handler handler配置 * @param handler.key handler支持的事件key * @param handler.fn handler的处理func - * @param namespace namespace,设置handler时建议设置 + * @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)