2023-03-04 14:30:13 +08:00
|
|
|
|
import createQQ from './qq.js'
|
|
|
|
|
import setLog from './log.js'
|
|
|
|
|
import redisInit from './redis.js'
|
|
|
|
|
import { checkRun } from './check.js'
|
2023-03-11 09:35:53 +08:00
|
|
|
|
import fs from 'node:fs'
|
2023-03-08 01:54:36 +08:00
|
|
|
|
import yaml from 'yaml'
|
|
|
|
|
|
2023-03-08 14:10:45 +08:00
|
|
|
|
// 添加一些多余的标题内容
|
|
|
|
|
let title = 'Miao-Yunzai'
|
|
|
|
|
let qq = await fs.promises.readFile('./config/config/qq.yaml', 'UTF-8').then(yaml.parse).catch(() => null)
|
|
|
|
|
if (qq) {
|
2023-04-01 13:34:20 +08:00
|
|
|
|
title += `@${qq.qq || '首次启动'}`
|
|
|
|
|
switch (qq.platform) {
|
|
|
|
|
case 1:
|
|
|
|
|
title += ' 安卓手机'
|
|
|
|
|
break
|
|
|
|
|
case 2:
|
|
|
|
|
title += ' aPad'
|
|
|
|
|
break
|
|
|
|
|
case 3:
|
|
|
|
|
title += ' 安卓手表'
|
|
|
|
|
break
|
|
|
|
|
case 4:
|
|
|
|
|
title += ' MacOS'
|
|
|
|
|
break
|
|
|
|
|
case 5:
|
|
|
|
|
title += ' iPad'
|
2023-04-25 15:29:44 +08:00
|
|
|
|
case 6:
|
|
|
|
|
title += ' 安卓8.8.88'
|
2023-04-01 13:34:20 +08:00
|
|
|
|
}
|
2023-03-08 14:10:45 +08:00
|
|
|
|
}
|
2023-03-04 14:30:13 +08:00
|
|
|
|
|
|
|
|
|
/** 设置标题 */
|
2023-03-08 14:10:45 +08:00
|
|
|
|
process.title = title
|
|
|
|
|
|
2023-03-04 14:30:13 +08:00
|
|
|
|
/** 设置时区 */
|
|
|
|
|
process.env.TZ = 'Asia/Shanghai'
|
|
|
|
|
|
|
|
|
|
/** 捕获未处理的Promise错误 */
|
|
|
|
|
process.on('unhandledRejection', (error, promise) => {
|
|
|
|
|
let err = error
|
|
|
|
|
if (logger) {
|
|
|
|
|
logger.error(err)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/** 退出事件 */
|
|
|
|
|
process.on('exit', async (code) => {
|
|
|
|
|
if (typeof redis != 'undefined' && typeof test == 'undefined') {
|
|
|
|
|
await redis.save()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await checkInit()
|
|
|
|
|
|
|
|
|
|
/** 初始化事件 */
|
|
|
|
|
async function checkInit () {
|
|
|
|
|
/** 检查node_modules */
|
|
|
|
|
if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/icqq')) {
|
2023-03-11 09:35:53 +08:00
|
|
|
|
console.log('请先运行命令:pnpm install -P 安装依赖')
|
2023-03-04 14:30:13 +08:00
|
|
|
|
process.exit()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 检查qq.yaml */
|
|
|
|
|
await createQQ()
|
|
|
|
|
|
|
|
|
|
/** 日志设置 */
|
|
|
|
|
setLog()
|
|
|
|
|
|
2023-03-06 10:00:25 +08:00
|
|
|
|
logger.mark('Miao-Yunzai 启动中...')
|
2023-03-04 14:30:13 +08:00
|
|
|
|
|
|
|
|
|
await redisInit()
|
|
|
|
|
|
|
|
|
|
checkRun()
|
|
|
|
|
}
|