From 60ac6e3479a0f23ff6697e9ee89892677f557028 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Wed, 12 Jun 2024 09:35:17 +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/config/config.ts | 8 ++++---- src/config/index.ts | 20 +------------------- src/config/log.ts | 10 +++++----- src/config/{init.ts => main.ts} | 30 +++++++++++++++--------------- src/config/qq.ts | 13 ++----------- src/config/redis.ts | 2 +- src/core/bot.ts | 10 +++++++++- src/global.d.ts | 5 ++++- 8 files changed, 41 insertions(+), 57 deletions(-) rename src/config/{init.ts => main.ts} (85%) diff --git a/src/config/config.ts b/src/config/config.ts index 9a3c6ce..63cc151 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -9,7 +9,7 @@ import { CONFIG_DEFAULT_PATH, CONFIG_INIT_PATH } from './system.js' * 配置文件 * ******** */ -class Cfg { +class ConfigController { /** * @@ -238,8 +238,8 @@ class Cfg { * 修改日志等级 */ async change_bot() { - const log = await import('./log.js') - log.default() + const { setLogger } = await import('./log.js') + setLogger && setLogger() } } @@ -249,4 +249,4 @@ class Cfg { * * *** */ -export default new Cfg() \ No newline at end of file +export default new ConfigController() \ No newline at end of file diff --git a/src/config/index.ts b/src/config/index.ts index 7507b17..4a8dae5 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,28 +1,10 @@ import config from './config.js' -import RedisInit from './redis.js' -import QQ from './qq.js' -/** - * - */ -export { checkRun } from './check.js' -/** - * - */ -export { checkInit, UpdateTitle as checkUpdateTitle } from './init.js' /** * 配置控制器 */ export const ConfigController = config /** - * 创建qq配置 - */ -export const createQQ = QQ -/** - * 初始化redis全局对象 - */ -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 3df286a..68ace94 100644 --- a/src/config/log.ts +++ b/src/config/log.ts @@ -2,7 +2,7 @@ import log4js from 'log4js' import chalk from 'chalk' import cfg from './config.js' import fs from 'node:fs' - + /** * 创建日志 @@ -52,7 +52,7 @@ function createLog() { const commandLogger = log4js.getLogger('command') const errorLogger = log4js.getLogger('error') - + /** * 调整error日志等级 */ @@ -86,7 +86,7 @@ function createLog() { /** * 设置日志样式 */ -export default function setLog() { +export function setLogger() { /** * @@ -96,12 +96,12 @@ export default function setLog() { /** * */ - if (!fs.existsSync(file)){ + if (!fs.existsSync(file)) { fs.mkdirSync(file, { 'recursive': true }) } - + /** * 全局变量 logger */ diff --git a/src/config/init.ts b/src/config/main.ts similarity index 85% rename from src/config/init.ts rename to src/config/main.ts index 4bc49cb..e32132c 100644 --- a/src/config/init.ts +++ b/src/config/main.ts @@ -1,16 +1,16 @@ import fs, { promises } from "node:fs" import yaml from "yaml" import { BOT_NAME, CONFIG_INIT_PATH } from "./system.js" -import createQQ from "./qq.js" -import setLog from "./log.js" -import redisInit from "./redis.js" +import { createQQ } from "./qq.js" +import { setLogger } from "./log.js" +import { redisInit } from "./redis.js" import { checkRun } from "./check.js" import { join } from "node:path" /** * */ -export async function UpdateTitle() { +async function UpdateTitle() { /** * 添加一些多余的标题内容 */ @@ -25,31 +25,31 @@ export async function UpdateTitle() { if (qq) { title += `@${qq.qq || ""}` switch (qq.platform) { - case 1:{ + case 1: { title += " 安卓手机" break } - case 2:{ + case 2: { title += " aPad" break } - case 3:{ + case 3: { title += " 安卓手表" break } - case 4:{ + case 4: { title += " MacOS" break } - case 5:{ + case 5: { title += " iPad" break } - case 6:{ + case 6: { title += " Tim" break } - default:{ + default: { break } } @@ -78,7 +78,7 @@ export async function checkInit() { /** * 检查node_modules/icqq */ - if(!fs.existsSync(join(process.cwd(), "./node_modules/icqq"))){ + if (!fs.existsSync(join(process.cwd(), "./node_modules/icqq"))) { console.log("未安装icqq。。。。") console.log("请先运行命令:pnpm install -P 安装依赖") process.exit() @@ -92,7 +92,7 @@ export async function checkInit() { /** * 日志设置 */ - setLog() + setLogger() /** * @@ -100,12 +100,12 @@ export async function checkInit() { logger.mark(`${BOT_NAME} 启动中...`) /** - * + * 初始化客户端 */ await redisInit() /** - * + * 检查程序 */ await checkRun() diff --git a/src/config/qq.ts b/src/config/qq.ts index e27a165..573fbef 100644 --- a/src/config/qq.ts +++ b/src/config/qq.ts @@ -10,7 +10,7 @@ import { sleep } from '../utils/common.js' * Git Bash 运行npm命令会无法选择列表 * @returns */ -export default async function createQQ() { +export async function createQQ() { /** 跳过登录ICQQ */ if (cfg.bot.skip_login) return @@ -63,12 +63,6 @@ export default async function createQQ() { } } } - // ,{ - // type: 'Input', - // message: '代理服务器地址,无需代理服务器请直接按下Enter:', - // name: 'proxyAddress', - // default: 'http://0.0.0.0:0' - // } ] /** @@ -103,8 +97,6 @@ export default async function createQQ() { const fileDef = `./${CONFIG_DEFAULT_PATH}` - - let qq = fs.readFileSync(`${fileDef}qq.yaml`, 'utf8') qq = qq.replace(/qq:/g, 'qq: ' + ret.QQ) @@ -113,7 +105,6 @@ export default async function createQQ() { fs.writeFileSync(`${file}qq.yaml`, qq, 'utf8') let bot = fs.readFileSync(`${fileDef}bot.yaml`, 'utf8') - // bot = bot.replace(/proxyAddress:/g, `proxyAddress: ${ret.proxyAddress}`) /** * @@ -133,7 +124,7 @@ export default async function createQQ() { fs.writeFileSync(`${file}bot.yaml`, bot, 'utf8') - console.log(`\nQQ配置完成,正在登录\n后续修改账号可以运行命令: ${chalk.green('node app login')}\n`) + console.log(`\nQQ配置完成,正在登录\n后续修改账号可以运行命令: ${chalk.green('npm run login')}\n`) /** * diff --git a/src/config/redis.ts b/src/config/redis.ts index 7790ee2..c3639bc 100644 --- a/src/config/redis.ts +++ b/src/config/redis.ts @@ -6,7 +6,7 @@ import { createClient } from "redis" * 初始化全局redis客户端 * @returns */ -export default async function redisInit() { +export async function redisInit() { const rc = cfg.redis const redisUn = rc.username || "" let redisPw = rc.password ? `:${rc.password}` : "" diff --git a/src/core/bot.ts b/src/core/bot.ts index dbda4f2..852bb6b 100644 --- a/src/core/bot.ts +++ b/src/core/bot.ts @@ -3,7 +3,7 @@ * 配置初始化 * ********** */ -import '../config/init.js' +import '../config/main.js' /** * ********** * 配置读取工具 @@ -71,4 +71,12 @@ export class Client extends IcqqClient { } } +/** + * 内置Redis + */ +export const Redis = global.redis + +/** + * 机器人客户端 + */ export const Bot = global.Bot as typeof Client.prototype diff --git a/src/global.d.ts b/src/global.d.ts index c9c54fc..8211ea7 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -53,19 +53,22 @@ type ChalkInstanceType = { declare global { /** + * import { Redis } from 'yunzai/core' * @deprecated 不推荐使用,未来将废弃 */ var redis: RedisClientType /** - * + * import { Bot } from 'yunzai/core' * @deprecated 不推荐使用,未来将废弃 */ var Bot: typeof Client.prototype /** + * import { segment } from 'yunzai/core' * @deprecated 不推荐使用,未来将废弃 */ var segment: typeof se /** + * import { plugin } from 'yunzai/core' * @deprecated 不推荐使用,未来将废弃 */ var plugin: typeof p