From e1f53b1cc658c6610c52f9e6f1c47cf827eb83c8 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Tue, 11 Jun 2024 17:41:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bot.ts | 14 ++++---- src/config/index.ts | 10 +++++- src/config/log.ts | 2 +- src/config/redis.ts | 2 +- src/core/icqq.ts | 1 + src/core/index.ts | 1 + src/core/plugins/index.ts | 2 +- src/db/BaseModel.ts | 2 +- src/global.d.ts | 76 +++++++++++++++++++++++++++++++++++---- src/global.ts | 7 ---- src/index.ts | 5 --- src/{local.ts => miao.ts} | 0 src/mys/MysUser.ts | 2 +- src/mys/MysUtil.ts | 2 +- src/mys/NoteUser.ts | 2 +- src/mys/gsCfg.ts | 2 +- 16 files changed, 95 insertions(+), 35 deletions(-) create mode 100644 src/core/icqq.ts delete mode 100644 src/global.ts delete mode 100644 src/index.ts rename src/{local.ts => miao.ts} (100%) diff --git a/src/bot.ts b/src/bot.ts index d1403ab..99ad7a0 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -4,12 +4,6 @@ * ********** */ import './config/init.js' -/** - * ********** - * 全局变量配置 - * ********* - */ -import './global.js' /** * ********** * 配置读取工具 @@ -25,7 +19,13 @@ import ListenerLoader from './core/events.loader.js' /** * 扩展 */ -import { Client } from 'icqq' +import { Client, segment } from 'icqq' +import { plugin } from './core/plugins/index.js' +/** + * global + */ +global.plugin = plugin +global.segment = segment /** * */ diff --git a/src/config/index.ts b/src/config/index.ts index 693da49..5728445 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1 +1,9 @@ -export {} \ No newline at end of file +export { checkRun } from './check.js' +import config from './config.js' +export { checkInit, UpdateTitle as checkUpdateTitle } from './init.js' +export const ConfigController = config +import QQ from './qq.js' +export const createQQ = QQ +import RedisInit from './redis.js' +export const redisInit = RedisInit +export * from './system.js' \ No newline at end of file diff --git a/src/config/log.ts b/src/config/log.ts index 6d7cafd..329880f 100644 --- a/src/config/log.ts +++ b/src/config/log.ts @@ -101,7 +101,7 @@ export default function setLog() { } /** 全局变量 logger */ - global.logger = createLog() + global.logger = createLog() as any logger.chalk = chalk logger.red = chalk.red diff --git a/src/config/redis.ts b/src/config/redis.ts index c46d948..7745926 100644 --- a/src/config/redis.ts +++ b/src/config/redis.ts @@ -56,7 +56,7 @@ export default async function redisInit() { * * @returns */ -export async function aarch64() { +async function aarch64() { if (process.platform == "win32") { return "" } diff --git a/src/core/icqq.ts b/src/core/icqq.ts new file mode 100644 index 0000000..8570ada --- /dev/null +++ b/src/core/icqq.ts @@ -0,0 +1 @@ +export { Client, segment } from 'icqq' diff --git a/src/core/index.ts b/src/core/index.ts index 221ffa9..02f91b3 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,3 +1,4 @@ export * from './plugins/index.js' export * from './plugins/functional.js' export * from './plugins/types.js' +export * from './icqq.js' diff --git a/src/core/plugins/index.ts b/src/core/plugins/index.ts index 863f5a1..5afaadb 100644 --- a/src/core/plugins/index.ts +++ b/src/core/plugins/index.ts @@ -1,4 +1,4 @@ -import { Common } from '../../local.js' +import { Common } from '../../miao.js' import { EventType } from './types.js' const stateArr = {} diff --git a/src/db/BaseModel.ts b/src/db/BaseModel.ts index 0a61221..8e1ce1b 100644 --- a/src/db/BaseModel.ts +++ b/src/db/BaseModel.ts @@ -1,5 +1,5 @@ import { Sequelize, DataTypes, Model } from 'sequelize' -import { Data } from '../local.js' +import { Data } from '../miao.js' import { join } from 'path' /** diff --git a/src/global.d.ts b/src/global.d.ts index c8b0366..61b4b80 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -2,13 +2,75 @@ import { segment as se } from 'icqq' import { RedisClientType } from 'redis' import { Yunzai } from './bot.js' import { plugin as p } from './core/index.js' +import chalk, { type ChalkInstance } from 'chalk' + /** - * 全局变量声明 + * */ -declare global { - var redis: RedisClientType - var Bot: typeof Yunzai.prototype - var segment: typeof se - var plugin: typeof p - var logger: any +type LogType = string | Error | unknown + +/** + * + */ +type LoggerType = { + trace(...arg: LogType[]): any + debug(...arg: LogType[]): any + info(...arg: LogType[]): any + warn(...arg: LogType[]): any + error(...arg: LogType[]): any + fatal(...arg: LogType[]): any + mark(...arg: LogType[]): any +} + +/** + * @deprecated 不推荐使用 + */ +type ChalkInstanceType = { + /** + * @deprecated 不推荐使用 + */ + red: ChalkInstance.red + /** + * @deprecated 不推荐使用 + */ + green: ChalkInstance.green + /** + * @deprecated 不推荐使用 + */ + blue: ChalkInstance.blue + /** + * @deprecated 不推荐使用 + */ + yellow: ChalkInstance.yellow + /** + * @deprecated 不推荐使用 + */ + magenta: ChalkInstance.magenta + /** + * @deprecated 不推荐使用 + */ + cyan: ChalkInstance.cyan +} + +declare global { + /** + * @deprecated 不推荐使用 + */ + var redis: RedisClientType + /** + * @deprecated 不推荐使用 + */ + var Bot: typeof Yunzai.prototype + /** + * @deprecated 不推荐使用 + */ + var segment: typeof se + /** + * @deprecated 不推荐使用 + */ + var plugin: typeof p + var logger: LoggerType & + ChalkInstanceType & { + chalk: ChalkInstance + } } diff --git a/src/global.ts b/src/global.ts deleted file mode 100644 index cafcd4f..0000000 --- a/src/global.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { segment } from 'icqq' -import { plugin } from './core/plugins/index.js' -/** - * global - */ -global.plugin = plugin -global.segment = segment diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 9c4f07d..0000000 --- a/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './config/index.js' -export * from './core/index.js' -export * from './db/index.js' -export * from './mys/index.js' -export * from './utils/index.js' diff --git a/src/local.ts b/src/miao.ts similarity index 100% rename from src/local.ts rename to src/miao.ts diff --git a/src/mys/MysUser.ts b/src/mys/MysUser.ts index 425c492..feed735 100644 --- a/src/mys/MysUser.ts +++ b/src/mys/MysUser.ts @@ -15,7 +15,7 @@ import fetch from 'node-fetch' import { MysUserDB } from '../db/index.js' -import { Data } from '../local.js' +import { Data } from '../miao.js' const tables = { // ltuid-uid 查询表 diff --git a/src/mys/MysUtil.ts b/src/mys/MysUtil.ts index 0ec09bc..cd17314 100644 --- a/src/mys/MysUtil.ts +++ b/src/mys/MysUtil.ts @@ -1,4 +1,4 @@ -import { Data } from '../local.js' +import { Data } from '../miao.js' /** * diff --git a/src/mys/NoteUser.ts b/src/mys/NoteUser.ts index e5c0282..adb04fa 100644 --- a/src/mys/NoteUser.ts +++ b/src/mys/NoteUser.ts @@ -3,7 +3,7 @@ import lodash from 'lodash' import MysUser from './MysUser.js' import MysUtil from './MysUtil.js' import { UserDB } from '../db/index.js' -import { Data } from '../local.js' +import { Data } from '../miao.js' /** * ******************* * Bot实际User用户类 diff --git a/src/mys/gsCfg.ts b/src/mys/gsCfg.ts index cc6e01a..1e5ab8a 100644 --- a/src/mys/gsCfg.ts +++ b/src/mys/gsCfg.ts @@ -4,7 +4,7 @@ import fs from 'node:fs' import lodash from 'lodash' import MysInfo from './mysInfo.js' import NoteUser from './NoteUser.js' -import { Character, Weapon } from '../local.js' +import { Character, Weapon } from '../miao.js' /** * ***********