优化 日志输出

This commit is contained in:
🌌 2023-06-30 21:20:06 +08:00
parent 76cf749182
commit 2a6b5cb21f
5 changed files with 24 additions and 18 deletions

View File

@ -23,7 +23,7 @@ process.on('unhandledRejection', (error, promise) => {
process.on('exit', async (code) => {
if (typeof redis != 'undefined' && typeof test == 'undefined')
await redis.save()
logger.mark(logger.green('TRSS-Yunzai 已停止运行'))
logger.mark(logger.magenta('TRSS-Yunzai 已停止运行'))
})
await checkInit()

View File

@ -31,7 +31,7 @@
"node-schedule": "^2.1.1",
"node-xlsx": "^0.23.0",
"pm2": "^5.3.0",
"puppeteer": "^20.7.3",
"puppeteer": "^20.7.4",
"redis": "^4.6.7",
"sequelize": "^6.32.1",
"sqlite3": "^5.1.6",

View File

@ -342,7 +342,7 @@ Bot.adapter.push(new class ComWeChatAdapter {
data.member = data.group.pickMember(data.user_id)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
Bot.emit(`${data.post_type}.${data.message_type}`, data)
@ -359,7 +359,7 @@ Bot.adapter.push(new class ComWeChatAdapter {
this.connect(data)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
}
@ -367,7 +367,7 @@ Bot.adapter.push(new class ComWeChatAdapter {
try {
data = JSON.parse(data)
} catch (err) {
return logger.error(err)
return logger.error(`解码数据失败:${logger.red(err)}`)
}
if (data.self?.user_id) {
@ -377,10 +377,13 @@ Bot.adapter.push(new class ComWeChatAdapter {
}
if (data.type) {
if (data.detail_type != "status_update" && !Bot.uin.includes(data.self_id))
if (data.type != "meta" && !Bot.uin.includes(data.self_id)) {
logger.warn(`${logger.blue(`[${data.self_id}]`)} 找不到对应Bot忽略消息${logger.magenta(JSON.stringify(data))}`)
return false
}
data.sendApi = (action, params) => this.sendApi(ws, action, params)
data.bot = Bot[data.self_id]
switch (data.type) {
case "meta":
this.makeMeta(data)
@ -397,13 +400,13 @@ Bot.adapter.push(new class ComWeChatAdapter {
break
*/
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
} else if (data.echo) {
logger.debug(`请求 API 返回:${logger.cyan(JSON.stringify(data))}`)
Bot.emit(data.echo, data)
} else {
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
}

View File

@ -609,7 +609,7 @@ Bot.adapter.push(new class gocqhttpAdapter {
data.friend = data.member
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
if (data.sub_type)
@ -669,7 +669,7 @@ Bot.adapter.push(new class gocqhttpAdapter {
logger.info(`${logger.blue(`[${data.self_id}]`)} 群头衔:[${data.group_id}, ${data.user_id}] ${data.title}`)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知通知:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知通知:${logger.magenta(JSON.stringify(data))}`)
}
break
case "group_card":
@ -709,7 +709,7 @@ Bot.adapter.push(new class gocqhttpAdapter {
Bot[data.self_id].gl = await this.getGroupMap(data)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知通知:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知通知:${logger.magenta(JSON.stringify(data))}`)
}
let notice = data.notice_type.split("_")
@ -749,7 +749,7 @@ Bot.adapter.push(new class gocqhttpAdapter {
data.member = data.group.pickMember(data.user_id)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知请求:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知请求:${logger.magenta(JSON.stringify(data))}`)
}
if (data.sub_type)
@ -781,7 +781,7 @@ Bot.adapter.push(new class gocqhttpAdapter {
this.connect(data)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
}
@ -789,14 +789,17 @@ Bot.adapter.push(new class gocqhttpAdapter {
try {
data = JSON.parse(data)
} catch (err) {
return logger.error(err)
return logger.error(`解码数据失败:${logger.red(err)}`)
}
if (data.post_type) {
if (data.meta_event_type != "lifecycle" && !Bot.uin.includes(data.self_id))
if (data.meta_event_type != "lifecycle" && !Bot.uin.includes(data.self_id)) {
logger.warn(`${logger.blue(`[${data.self_id}]`)} 找不到对应Bot忽略消息${logger.magenta(JSON.stringify(data))}`)
return false
}
data.sendApi = (action, params) => this.sendApi(ws, action, params)
data.bot = Bot[data.self_id]
switch (data.post_type) {
case "meta_event":
this.makeMeta(data)
@ -815,13 +818,13 @@ Bot.adapter.push(new class gocqhttpAdapter {
this.makeMessage(data)
break
default:
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
} else if (data.echo) {
logger.debug(`请求 API 返回:${logger.cyan(JSON.stringify(data))}`)
Bot.emit(data.echo, data)
} else {
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.red(JSON.stringify(data))}`)
logger.warn(`${logger.blue(`[${data.self_id}]`)} 未知消息:${logger.magenta(JSON.stringify(data))}`)
}
}

View File

@ -10,7 +10,7 @@ export class invite extends plugin {
}
async accept () {
if (!cfg.masterQQ || !cfg.masterQQ.includes(Number(this.e.user_id))) {
if (!this.e.isMaster) {
logger.mark(`[邀请加群]${this.e.group_name}${this.e.group_id}`)
return
}