feat: 优化导出

This commit is contained in:
ningmengchongshui 2024-06-12 09:21:55 +08:00
parent 3ea075091a
commit c8a60391c3
6 changed files with 40 additions and 25 deletions

View File

@ -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' export class Client extends IcqqClient {
/**
* global.plugin
*/
global.plugin = plugin
/**
* global.segment
*/
global.segment = segment
/**
*
*/
export class Yunzai extends Client {
/** /**
* *
* @param conf * @param conf
@ -52,7 +40,7 @@ export class Yunzai extends Client {
* @returns * @returns
*/ */
static async run() { static async run() {
const bot = new Yunzai(cfg.bot) const bot = new Client(cfg.bot)
/** 加载监听事件 */ /** 加载监听事件 */
await ListenerLoader.load(bot) await ListenerLoader.load(bot)
@ -79,6 +67,8 @@ export class Yunzai extends Client {
/** 全局变量 bot */ /** 全局变量 bot */
global.Bot = 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

10
src/core/events.ts Normal file
View File

@ -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 }

View File

@ -1 +1 @@
export { Client, segment } from 'icqq' export { segment } from 'icqq'

View File

@ -3,3 +3,5 @@ export * from './plugins/functional.js'
export * from './plugins/types.js' export * from './plugins/types.js'
export * from './plugins/common.js' export * from './plugins/common.js'
export * from './icqq.js' export * from './icqq.js'
export * from './events.js'
export * from './bot.js'

5
src/global.d.ts vendored
View File

@ -1,7 +1,6 @@
import { segment as se } from 'icqq' import { segment as se } from 'icqq'
import { RedisClientType } from 'redis' import { RedisClientType } from 'redis'
import { Yunzai } from './bot.js' import { Client, plugin as p } from './core/index.js'
import { plugin as p } from './core/index.js'
import chalk, { type ChalkInstance } from 'chalk' import chalk, { type ChalkInstance } from 'chalk'
/** /**
@ -61,7 +60,7 @@ declare global {
* *
* @deprecated 使 * @deprecated 使
*/ */
var Bot: typeof Yunzai.prototype var Bot: typeof Client.prototype
/** /**
* @deprecated 使 * @deprecated 使
*/ */

View File

@ -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()