diff --git a/src/adapter/kritor/index.ts b/src/adapter/kritor/index.ts index 7ba1feea..a86bb594 100644 --- a/src/adapter/kritor/index.ts +++ b/src/adapter/kritor/index.ts @@ -357,7 +357,10 @@ export default class AdapterKritor implements KarinAdapter { * 响应解码 */ const response = kritor[type][`${cmd}Response`].decode(res.buf) - return response + return { + message_id: response.message_id, + message_time: Number(response.message_time), + } } /** diff --git a/src/core/plugin.loader.ts b/src/core/plugin.loader.ts index 18bdb582..f3fcba3e 100644 --- a/src/core/plugin.loader.ts +++ b/src/core/plugin.loader.ts @@ -8,7 +8,7 @@ import { listener } from './listener' import PluginApp from './plugin.app' import { render } from 'karin/render' import { common, handler, logger } from 'karin/utils' -import { PluginApps, PluginTask, dirName, fileName, AppInfo } from 'karin/types' +import { PluginApps, PluginTask, dirName, fileName, AppInfo, NewPlugin } from 'karin/types' class PluginLoader { dir: './plugins' @@ -52,7 +52,7 @@ class PluginLoader { /** * - 定时任务 */ - task: Array Plugin, schedule?: schedule.Job, file: { dir: dirName, name: fileName } }> + task: Array /** * - 监听器 @@ -277,7 +277,7 @@ class PluginLoader { let path = `${this.dirPath}plugins/${dir}/${name}` if (isOrderBy) path = path + `?${Date.now()}` - const tmp: Array<(new () => Plugin) | PluginApps> = await import(path) + const tmp: Array<(NewPlugin) | PluginApps> = await import(path) lodash.forEach(tmp, (App) => { const index = this.index @@ -301,7 +301,7 @@ class PluginLoader { if (typeof App !== 'function' || !App?.prototype?.constructor) return - const Class = new (App as new () => Plugin)() + const Class = new (App as NewPlugin)() if (!Class.name) return logger.error(`[${dir}][${name}] 插件名称错误`) logger.debug(`载入插件 [${name}][${Class.name}]`) @@ -390,7 +390,7 @@ class PluginLoader { /** * 新增task */ - async addTask (dir: dirName, name: fileName, index: number, Class: Plugin, App: new () => Plugin) { + async addTask (dir: dirName, name: fileName, index: number, Class: Plugin, App: NewPlugin) { /** 定时任务 */ lodash.forEach(Class.task, val => { if (!val.name) return logger.error(`[${dir}][${name}] 定时任务name错误`) diff --git a/src/event/message.handler.ts b/src/event/message.handler.ts index 5808a6f6..9e765fec 100644 --- a/src/event/message.handler.ts +++ b/src/event/message.handler.ts @@ -2,8 +2,8 @@ import lodash from 'lodash' import { review } from './review.handler' import EventHandler from './event.handler' import { logger, config } from 'karin/utils' -import { KarinMessageEvent } from 'karin/types' -import { listener, Plugin, stateArr, pluginLoader } from 'karin/core' +import { KarinMessageEvent, NewPlugin } from 'karin/types' +import { listener, stateArr, pluginLoader } from 'karin/core' /** * 消息事件 @@ -74,7 +74,7 @@ export class MessageHandler extends EventHandler { if (app.file.type === 'function' && typeof v.fnc === 'function') { res = await v.fnc(this.e) } else { - const cla = new (app.file.Fnc as new () => Plugin)() + const cla = new (app.file.Fnc as NewPlugin)() cla.e = this.e res = await (cla[v.fnc as keyof typeof cla] as Function)(this.e) as Promise } diff --git a/src/types/plugin.ts b/src/types/plugin.ts index 1dec3547..f7e4a2e6 100644 --- a/src/types/plugin.ts +++ b/src/types/plugin.ts @@ -1,7 +1,8 @@ import schedule from 'node-schedule' +import { Plugin } from 'karin/core' import { Reply, replyCallback, replyForward } from './reply' import { EventType, Event, Permission, SubEvent, KarinMessageEvent, KarinNoticeEvent, KarinRequestEvent } from './event' -import { Plugin } from 'karin/core' +import { KarinMessage } from 'karin/event' /** * - 插件根目录名称 @@ -282,3 +283,8 @@ export interface PluginApps { */ handler: Array } + +/** + * 未实例化的插件 + */ +export type NewPlugin = new (e?: KarinMessage) => Plugin diff --git a/src/utils/button.ts b/src/utils/button.ts index 14d41bca..002bd8a7 100644 --- a/src/utils/button.ts +++ b/src/utils/button.ts @@ -1,6 +1,6 @@ import logger from './logger' -import { KarinMessageEvent } from 'karin/types' -import { pluginLoader as loader, Plugin } from 'karin/core' +import { KarinMessageEvent, NewPlugin } from 'karin/types' +import { pluginLoader as loader } from 'karin/core' export const button = async (e: KarinMessageEvent) => { const button = [] @@ -19,7 +19,7 @@ export const button = async (e: KarinMessageEvent) => { if (typeof v.fnc === 'function') { res = await v.fnc(e, reject) } else { - const cla = new (info.file.Fnc as new () => Plugin)() + const cla = new (info.file.Fnc as NewPlugin)() cla.e = e res = await (cla[v.fnc as keyof typeof cla] as Function)(e, reject) } diff --git a/src/utils/handler.ts b/src/utils/handler.ts index 1009f4d8..59058352 100644 --- a/src/utils/handler.ts +++ b/src/utils/handler.ts @@ -1,7 +1,7 @@ import lodash from 'lodash' import logger from './logger' -import { EventType, PluginType, PluginApps } from 'karin/types' -import { Plugin, pluginLoader as loader } from 'karin/core' +import { pluginLoader as loader } from 'karin/core' +import { EventType, PluginType, PluginApps, NewPlugin } from 'karin/types' /** * 事件处理器类 @@ -92,7 +92,7 @@ export const handler = new (class EventHandler { if (info.file.type === 'function' && typeof v.fnc === 'function') { res = await v.fnc(args, reject) } else { - const cla = new (info.file.Fnc as new () => Plugin)() + const cla = new (info.file.Fnc as NewPlugin)() cla.e = args.e as EventType res = await (cla[v.fnc as keyof typeof cla] as Function)(args, reject) }