From c8a60391c3e5643e7d0d62e6822f69888f0f06e0 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Wed, 12 Jun 2024 09:21:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{ => core}/bot.ts | 28 +++++++++------------------- src/core/events.ts | 10 ++++++++++ src/core/icqq.ts | 2 +- src/core/index.ts | 2 ++ src/global.d.ts | 5 ++--- src/main.ts | 18 ++++++++++++++++-- 6 files changed, 40 insertions(+), 25 deletions(-) rename src/{ => core}/bot.ts (65%) create mode 100644 src/core/events.ts diff --git a/src/bot.ts b/src/core/bot.ts similarity index 65% rename from src/bot.ts rename to src/core/bot.ts index e150bbb..dbda4f2 100644 --- a/src/bot.ts +++ b/src/core/bot.ts @@ -3,39 +3,27 @@ * 配置初始化 * ********** */ -import './config/init.js' +import '../config/init.js' /** * ********** * 配置读取工具 * ********** */ -import cfg from './config/config.js' +import cfg from '../config/config.js' /** * ********** * 监听 * ********** */ -import ListenerLoader from './core/events.loader.js' +import ListenerLoader from './events.loader.js' /** * 扩展 */ -import { Client, segment } from 'icqq' +import { Client as IcqqClient } from 'icqq' /** * */ -import { plugin } from './core/plugins/index.js' -/** - * global.plugin - */ -global.plugin = plugin -/** - * global.segment - */ -global.segment = segment -/** - * - */ -export class Yunzai extends Client { +export class Client extends IcqqClient { /** * * @param conf @@ -52,7 +40,7 @@ export class Yunzai extends Client { * @returns */ static async run() { - const bot = new Yunzai(cfg.bot) + const bot = new Client(cfg.bot) /** 加载监听事件 */ await ListenerLoader.load(bot) @@ -79,6 +67,8 @@ export class Yunzai extends Client { /** 全局变量 bot */ global.Bot = bot /** 加载插件 */ - return await (await import('./core/plugins.loader.js')).default.load() + return await (await import('./plugins.loader.js')).default.load() } } + +export const Bot = global.Bot as typeof Client.prototype diff --git a/src/core/events.ts b/src/core/events.ts new file mode 100644 index 0000000..1b8ffff --- /dev/null +++ b/src/core/events.ts @@ -0,0 +1,10 @@ +import EventLogin from './events/login' +import EventMessage from './events/message' +import EventNotice from './events/notice' +import EventOffine from './events/offline' +import EventOnline from './events/online' +export { EventLogin } +export { EventMessage } +export { EventNotice } +export { EventOffine } +export { EventOnline } diff --git a/src/core/icqq.ts b/src/core/icqq.ts index 8570ada..ff982ce 100644 --- a/src/core/icqq.ts +++ b/src/core/icqq.ts @@ -1 +1 @@ -export { Client, segment } from 'icqq' +export { segment } from 'icqq' diff --git a/src/core/index.ts b/src/core/index.ts index 70b6f58..5e79063 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -3,3 +3,5 @@ export * from './plugins/functional.js' export * from './plugins/types.js' export * from './plugins/common.js' export * from './icqq.js' +export * from './events.js' +export * from './bot.js' diff --git a/src/global.d.ts b/src/global.d.ts index 7eef82c..c9c54fc 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,7 +1,6 @@ import { segment as se } from 'icqq' import { RedisClientType } from 'redis' -import { Yunzai } from './bot.js' -import { plugin as p } from './core/index.js' +import { Client, plugin as p } from './core/index.js' import chalk, { type ChalkInstance } from 'chalk' /** @@ -61,7 +60,7 @@ declare global { * * @deprecated 不推荐使用,未来将废弃 */ - var Bot: typeof Yunzai.prototype + var Bot: typeof Client.prototype /** * @deprecated 不推荐使用,未来将废弃 */ diff --git a/src/main.ts b/src/main.ts index a7f8398..a9e7c37 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,2 +1,16 @@ -import { Yunzai } from './bot.js' -await Yunzai.run() +/** + * + */ +import { plugin, segment, Client } from './core/index.js' +/** + * global.plugin + */ +global.plugin = plugin +/** + * global.segment + */ +global.segment = segment +/** + * run + */ +await Client.run()