52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
|
||
import createQQ from './qq.js'
|
||
import setLog from './log.js'
|
||
import redisInit from './redis.js'
|
||
import { checkRun } from './check.js'
|
||
import fs from 'fs'
|
||
|
||
/** 设置标题 */
|
||
process.title = 'Miao-Yunzai'
|
||
/** 设置时区 */
|
||
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')) {
|
||
console.log('请先运行命令:pnpm install 安装依赖')
|
||
process.exit()
|
||
}
|
||
|
||
/** 检查qq.yaml */
|
||
await createQQ()
|
||
|
||
/** 日志设置 */
|
||
setLog()
|
||
|
||
logger.mark('Miao-Yunzai 启动中...')
|
||
|
||
await redisInit()
|
||
|
||
checkRun()
|
||
}
|