修复初始化错误

This commit is contained in:
🌌 2023-12-27 22:54:38 +08:00
parent 53cb65a944
commit b659655dca
1 changed files with 35 additions and 39 deletions

View File

@ -1,37 +1,37 @@
import createQQ from './qq.js' import createQQ from "./qq.js"
import setLog from './log.js' import setLog from "./log.js"
import redisInit from './redis.js' import redisInit from "./redis.js"
import { checkRun } from './check.js' import { checkRun } from "./check.js"
import fs from 'node:fs' import fs from "node:fs"
import yaml from 'yaml' import yaml from "yaml"
/** 设置标题 */ /** 设置标题 */
process.title = 'Miao-Yunzai' process.title = "Miao-Yunzai"
async function UpdateTitle() { async function UpdateTitle() {
// 添加一些多余的标题内容 // 添加一些多余的标题内容
let title = 'Miao-Yunzai' let title = "Miao-Yunzai"
let qq = await fs.promises.readFile('./config/config/qq.yaml', 'UTF-8').then(yaml.parse).catch(() => null) let qq = await fs.promises.readFile("./config/config/qq.yaml", "UTF-8").then(yaml.parse).catch(() => null)
if (qq) { if (qq) {
title += `@${qq.qq || ''}` title += `@${qq.qq || ""}`
switch (qq.platform) { switch (qq.platform) {
case 1: case 1:
title += ' 安卓手机' title += " 安卓手机"
break break
case 2: case 2:
title += ' aPad' title += " aPad"
break break
case 3: case 3:
title += ' 安卓手表' title += " 安卓手表"
break break
case 4: case 4:
title += ' MacOS' title += " MacOS"
break break
case 5: case 5:
title += ' iPad' title += " iPad"
break break
case 6: case 6:
title += ' Tim' title += " Tim"
break break
default: default:
} }
@ -41,42 +41,38 @@ async function UpdateTitle() {
} }
/** 设置时区 */ /** 设置时区 */
process.env.TZ = 'Asia/Shanghai' process.env.TZ = "Asia/Shanghai"
/** 捕获未处理的错误 */ /** 捕获未处理的错误 */
process.on('uncaughtException', (error) => { process.on("uncaughtException", error => {
let err = error if (typeof logger == "undefined") console.log(error)
if (logger) { else logger.error(error)
logger.error(err)
} else {
console.log(err)
}
}) })
/** 捕获未处理的Promise错误 */ /** 捕获未处理的Promise错误 */
process.on('unhandledRejection', (error, promise) => { process.on("unhandledRejection", (error, promise) => {
let err = error if (typeof logger == "undefined") console.log(error)
if (logger) { else logger.error(error)
logger.error(err)
} else {
console.log(err)
}
}) })
/** 退出事件 */ /** 退出事件 */
process.on('exit', async (code) => { process.on("exit", async code => {
if (typeof redis != 'undefined' && typeof test == 'undefined') { if (typeof redis != "undefined" && typeof test == "undefined")
await redis.save() await redis.save()
}
if (typeof logger == "undefined")
console.log("Miao-Yunzai 已停止运行")
else
logger.mark(logger.magenta("Miao-Yunzai 已停止运行"))
}) })
await checkInit() await checkInit()
/** 初始化事件 */ /** 初始化事件 */
async function checkInit () { async function checkInit() {
/** 检查node_modules */ /** 检查node_modules */
if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/icqq')) { if (!fs.existsSync("./node_modules") || !fs.existsSync("./node_modules/icqq")) {
console.log('请先运行命令pnpm install -P 安装依赖') console.log("请先运行命令pnpm install -P 安装依赖")
process.exit() process.exit()
} }
@ -86,7 +82,7 @@ async function checkInit () {
/** 日志设置 */ /** 日志设置 */
setLog() setLog()
logger.mark('Miao-Yunzai 启动中...') logger.mark("Miao-Yunzai 启动中...")
await redisInit() await redisInit()