From b659655dcaea3b55a58fb58c7d6c1391124188b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Wed, 27 Dec 2023 22:54:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/init.js | 74 ++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/lib/config/init.js b/lib/config/init.js index 1479906..f7b73ca 100644 --- a/lib/config/init.js +++ b/lib/config/init.js @@ -1,37 +1,37 @@ -import createQQ from './qq.js' -import setLog from './log.js' -import redisInit from './redis.js' -import { checkRun } from './check.js' -import fs from 'node:fs' -import yaml from 'yaml' +import createQQ from "./qq.js" +import setLog from "./log.js" +import redisInit from "./redis.js" +import { checkRun } from "./check.js" +import fs from "node:fs" +import yaml from "yaml" /** 设置标题 */ -process.title = 'Miao-Yunzai' +process.title = "Miao-Yunzai" async function UpdateTitle() { // 添加一些多余的标题内容 - let title = 'Miao-Yunzai' - let qq = await fs.promises.readFile('./config/config/qq.yaml', 'UTF-8').then(yaml.parse).catch(() => null) + let title = "Miao-Yunzai" + let qq = await fs.promises.readFile("./config/config/qq.yaml", "UTF-8").then(yaml.parse).catch(() => null) if (qq) { - title += `@${qq.qq || ''}` + title += `@${qq.qq || ""}` switch (qq.platform) { case 1: - title += ' 安卓手机' + title += " 安卓手机" break case 2: - title += ' aPad' + title += " aPad" break case 3: - title += ' 安卓手表' + title += " 安卓手表" break case 4: - title += ' MacOS' + title += " MacOS" break case 5: - title += ' iPad' + title += " iPad" break case 6: - title += ' Tim' + title += " Tim" break default: } @@ -41,42 +41,38 @@ async function UpdateTitle() { } /** 设置时区 */ -process.env.TZ = 'Asia/Shanghai' +process.env.TZ = "Asia/Shanghai" /** 捕获未处理的错误 */ -process.on('uncaughtException', (error) => { - let err = error - if (logger) { - logger.error(err) - } else { - console.log(err) - } +process.on("uncaughtException", error => { + if (typeof logger == "undefined") console.log(error) + else logger.error(error) }) /** 捕获未处理的Promise错误 */ -process.on('unhandledRejection', (error, promise) => { - let err = error - if (logger) { - logger.error(err) - } else { - console.log(err) - } +process.on("unhandledRejection", (error, promise) => { + if (typeof logger == "undefined") console.log(error) + else logger.error(error) }) /** 退出事件 */ -process.on('exit', async (code) => { - if (typeof redis != 'undefined' && typeof test == 'undefined') { +process.on("exit", async code => { + if (typeof redis != "undefined" && typeof test == "undefined") await redis.save() - } + + if (typeof logger == "undefined") + console.log("Miao-Yunzai 已停止运行") + else + logger.mark(logger.magenta("Miao-Yunzai 已停止运行")) }) await checkInit() /** 初始化事件 */ -async function checkInit () { +async function checkInit() { /** 检查node_modules */ - if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/icqq')) { - console.log('请先运行命令:pnpm install -P 安装依赖') + if (!fs.existsSync("./node_modules") || !fs.existsSync("./node_modules/icqq")) { + console.log("请先运行命令:pnpm install -P 安装依赖") process.exit() } @@ -86,7 +82,7 @@ async function checkInit () { /** 日志设置 */ setLog() - logger.mark('Miao-Yunzai 启动中...') + logger.mark("Miao-Yunzai 启动中...") await redisInit() @@ -94,4 +90,4 @@ async function checkInit () { //** 更新标题 */ await UpdateTitle() -} +} \ No newline at end of file