From 8fc1051c84e143040647d8004528b6f5f48343a4 Mon Sep 17 00:00:00 2001 From: ZeroCal Su <3146312184@qq.com> Date: Tue, 3 Dec 2024 04:55:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/Challenge.js | 2 +- apps/Gacha.js | 8 ++--- apps/Guide.js | 22 ++++-------- apps/Manage.js | 4 +-- apps/News.js | 2 +- apps/Sanity.js | 14 ++++---- apps/Simulator.js | 68 +++++++++++++++++------------------ apps/Task.js | 4 +-- apps/Update.js | 2 +- apps/imgUpload.js | 12 ++----- components/Code.js | 70 ++++++++++++++++++------------------- components/Config.js | 10 +++--- components/Kuro.js | 36 +++++++++---------- components/Render.js | 2 +- components/Server.js | 12 +++---- components/Version.js | 2 +- components/Wiki.js | 20 +++++------ model/init.js | 4 +-- package.json | 2 +- resources/server/error.html | 2 +- resources/server/login.html | 2 +- utils/Calculate.js | 2 +- 22 files changed, 142 insertions(+), 160 deletions(-) diff --git a/apps/Challenge.js b/apps/Challenge.js index 3106306..c5a36cd 100644 --- a/apps/Challenge.js +++ b/apps/Challenge.js @@ -84,7 +84,7 @@ export class Challenge extends plugin { }); for (let i = 0; i < result.length; i++) { - const passTime = result[i].passTime; + const { passTime } = result[i]; const hours = Math.floor(passTime / 3600); const minutes = Math.floor((passTime % 3600) / 60); const seconds = passTime % 60; diff --git a/apps/Gacha.js b/apps/Gacha.js index 0948112..32ba82a 100644 --- a/apps/Gacha.js +++ b/apps/Gacha.js @@ -199,7 +199,7 @@ export class Gacha extends plugin { } if (fs.existsSync(`${_path}/data/wavesGacha/${jsonData.playerId}_Export.json`)) { - const list = JSON.parse(fs.readFileSync(`${_path}/data/wavesGacha/${jsonData.playerId}_Export.json`, 'utf-8')).list; + const { list } = JSON.parse(fs.readFileSync(`${_path}/data/wavesGacha/${jsonData.playerId}_Export.json`, 'utf-8')); const filteredList = Object.values(list.reduce((acc, item) => { (acc[item.gacha_id] = acc[item.gacha_id] || []).push(item); @@ -213,7 +213,7 @@ export class Gacha extends plugin { } fs.writeFileSync(`${_path}/data/wavesGacha/${jsonData.playerId}_Export.json`, JSON.stringify(json, null, 2)); - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`已写入本地文件 ${jsonData.playerId}_Export.json`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`已将抽卡记录写入本地文件`), logger.green(`${jsonData.playerId}_Export.json`)); return true; } @@ -250,7 +250,7 @@ export class Gacha extends plugin { try { await Bot.download(fileUrl, path); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`文件下载错误:${error.stack}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`文件下载错误`), logger.red(error.stack)); await this.reply(`导入抽卡记录失败:${error.message || '未知错误'}`, true); return true; } @@ -289,7 +289,7 @@ export class Gacha extends plugin { await this.e.reply(`导入UID为 ${uid} 的抽卡记录成功,共计${json.list.length}条记录`); await redis.set(`Yunzai:waves:gachaHistory:${this.e.user_id}`, uid); - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`已写入本地文件 ${uid}_Export.json`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`已将抽卡记录写入本地文件`), logger.green(`${uid}_Export.json`)); return true; } diff --git a/apps/Guide.js b/apps/Guide.js index 3e95c1a..df5af2b 100644 --- a/apps/Guide.js +++ b/apps/Guide.js @@ -68,7 +68,7 @@ export class Guide extends plugin { logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`尝试搜索图鉴:${message}`)); let result = await wiki.search(message) if (!result.status) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`未能搜索到图鉴内容:${message}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`未能搜索到图鉴内容`), logger.red(message)); await e.reply(`未能获取到${message}的图鉴,请检查输入是否正确`) return false } else { @@ -151,11 +151,9 @@ export class Guide extends plugin { data.content.modules[1].components[0].tabs[4].content = replace(data.content.modules[1].components[0].tabs[4].content) data.content.modules[1].components[0].tabs[5].content = replace(data.content.modules[1].components[0].tabs[5].content) - const base64 = await Render.render('Wiki/role/role', { + return await Render.render('Wiki/role/role', { data, }, { e: this.e, retType: 'base64' }); - - return base64 }, wikiWeapon: async (data) => { @@ -168,11 +166,9 @@ export class Guide extends plugin { data.content.modules[0].components[2].content = replace(data.content.modules[0].components[2].content) data.content.modules[1].components[0].content = replace(data.content.modules[1].components[0].content) - const base64 = await Render.render('Wiki/weapon/weapon', { + return await Render.render('Wiki/weapon/weapon', { data, }, { e: this.e, retType: 'base64' }); - - return base64 }, wikiRelics: async (data) => { @@ -184,11 +180,9 @@ export class Guide extends plugin { data.content.modules[1].components[0].content = replace(data.content.modules[1].components[0].content) data.content.modules[0].components[1].content = replace(data.content.modules[0].components[1].content) - const base64 = await Render.render('Wiki/relics/relics', { + return await Render.render('Wiki/relics/relics', { data, }, { e: this.e, retType: 'base64' }); - - return base64 }, wikiEnemy: async (data) => { @@ -199,11 +193,9 @@ export class Guide extends plugin { data.content.modules[0].components[0].content = replace(data.content.modules[0].components[0].content) data.content.modules[0].components[1].tabs[0].content = replace(data.content.modules[0].components[1].tabs[0].content) - const base64 = await Render.render('Wiki/enemy/enemy', { + return await Render.render('Wiki/enemy/enemy', { data, }, { e: this.e, retType: 'base64' }); - - return base64 }, wikiProps: async (data) => { @@ -213,11 +205,9 @@ export class Guide extends plugin { data.content.modules[0].components[0].content = replace(data.content.modules[0].components[0].content) - const base64 = await Render.render('Wiki/props/props', { + return await Render.render('Wiki/props/props', { data, }, { e: this.e, retType: 'base64' }); - - return base64 } } } diff --git a/apps/Manage.js b/apps/Manage.js index 51fa7f4..e339972 100644 --- a/apps/Manage.js +++ b/apps/Manage.js @@ -65,7 +65,7 @@ export class Manage extends plugin { await e.reply(imageCard); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`计算总用户数时出现错误:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`计算总用户数时出现错误`), logger.red(error)); await e.reply('[Waves-Plugin] 账号总数\n计算总用户数时出现错误,请检查日志'); } } @@ -95,7 +95,7 @@ export class Manage extends plugin { await e.reply(`[Waves-Plugin] 删除失效账号\n删除了 ${deleted} 个失效账号`); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`删除失效账号时出现错误:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`删除失效账号时出现错误`), logger.red(error)); await e.reply('[Waves-Plugin] 删除失效账号\n删除失效账号时出现错误,请检查日志'); } return true; diff --git a/apps/News.js b/apps/News.js index 3635fca..f8fac9c 100644 --- a/apps/News.js +++ b/apps/News.js @@ -58,7 +58,7 @@ export class News extends plugin { return true; } - const postId = newsData.data.list[0].postId; + const { postId } = newsData.data.list[0]; if (postId != await redis.get(`Yunzai:waves:news`)) { const limit = pLimit(Config.getConfig().limit); await Promise.all(autoPushList.map(user => diff --git a/apps/Sanity.js b/apps/Sanity.js index 77be9b8..b1bc09f 100644 --- a/apps/Sanity.js +++ b/apps/Sanity.js @@ -129,13 +129,13 @@ export class Sanity extends plugin { await Bot[botId]?.pickGroup(groupId).sendMsg([segment.at(userId), data[0].message]) } return true; - } else { - if (!groupId) { - await Bot[botId]?.pickUser(userId).sendMsg(Bot.makeForwardMsg([{ message: `用户 ${userId}` }, ...data])) - } else { - await Bot[botId]?.pickGroup(groupId).sendMsg(segment.at(userId)) - await Bot[botId]?.pickGroup(groupId).sendMsg(Bot.makeForwardMsg([{ message: `用户 ${userId}` }, ...data])) - } + } + else if (!groupId) { + await Bot[botId]?.pickUser(userId).sendMsg(Bot.makeForwardMsg([{ message: `用户 ${userId}` }, ...data])) + } + else { + await Bot[botId]?.pickGroup(groupId).sendMsg(segment.at(userId)) + await Bot[botId]?.pickGroup(groupId).sendMsg(Bot.makeForwardMsg([{ message: `用户 ${userId}` }, ...data])) } } return true; diff --git a/apps/Simulator.js b/apps/Simulator.js index e77f757..2946ed3 100644 --- a/apps/Simulator.js +++ b/apps/Simulator.js @@ -31,31 +31,29 @@ export class Simulator extends plugin { let userData = JSON.parse(await redis.get(`Yunzai:waves:simulator:${type}:${e.user_id}`)) || { five_star_time: 0, five_star_other: true, four_star_time: 0, four_star_other: true }; let { five_star_time, five_star_other, four_star_time, four_star_other } = userData; - if (five_star_time < 70) { - if (Math.random() < data.five_star.basic) { - if (five_star_other) { - if (Math.random() < data.five_star.other) { - gachaData.push({ role: data.five_star.other_pool[Math.floor(Math.random() * data.five_star.other_pool.length)].name, star: 5 }); - five_star_other = false - five_star_time = 0 - await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) - continue - - } else { - gachaData.push({ role: data.five_star.up_pool[Math.floor(Math.random() * data.five_star.up_pool.length)].name, star: 5 }); - five_star_other = true - five_star_time = 0 - await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) - continue - } + if (five_star_time < 70 && Math.random() < data.five_star.basic) { + if (five_star_other) { + if (Math.random() < data.five_star.other) { + gachaData.push({ role: data.five_star.other_pool[Math.floor(Math.random() * data.five_star.other_pool.length)].name, star: 5 }); + five_star_other = false + five_star_time = 0 + await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) + continue + } else { gachaData.push({ role: data.five_star.up_pool[Math.floor(Math.random() * data.five_star.up_pool.length)].name, star: 5 }); five_star_other = true five_star_time = 0 await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) continue - } + } else { + gachaData.push({ role: data.five_star.up_pool[Math.floor(Math.random() * data.five_star.up_pool.length)].name, star: 5 }); + five_star_other = true + five_star_time = 0 + await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) + continue + } } @@ -89,24 +87,15 @@ export class Simulator extends plugin { five_star_time++ - if (four_star_time < 9) { - if (Math.random() < data.four_star.basic) { - if (four_star_other) { - if (Math.random() < data.four_star.other) { - gachaData.push({ role: data.four_star.other_pool[Math.floor(Math.random() * data.four_star.other_pool.length)].name, star: 4 }); - four_star_other = false - four_star_time = 0 - await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) - continue - - } else { - gachaData.push({ role: data.four_star.up_pool[Math.floor(Math.random() * data.four_star.up_pool.length)].name, star: 4 }); - four_star_other = true - four_star_time = 0 - await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) - continue - - } + if (four_star_time < 9 && Math.random() < data.four_star.basic) { + if (four_star_other) { + if (Math.random() < data.four_star.other) { + gachaData.push({ role: data.four_star.other_pool[Math.floor(Math.random() * data.four_star.other_pool.length)].name, star: 4 }); + four_star_other = false + four_star_time = 0 + await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) + continue + } else { gachaData.push({ role: data.four_star.up_pool[Math.floor(Math.random() * data.four_star.up_pool.length)].name, star: 4 }); four_star_other = true @@ -115,6 +104,13 @@ export class Simulator extends plugin { continue } + } else { + gachaData.push({ role: data.four_star.up_pool[Math.floor(Math.random() * data.four_star.up_pool.length)].name, star: 4 }); + four_star_other = true + four_star_time = 0 + await redis.set(`Yunzai:waves:simulator:${type}:${e.user_id}`, JSON.stringify({ five_star_time, five_star_other, four_star_time, four_star_other })) + continue + } } diff --git a/apps/Task.js b/apps/Task.js index 5503776..4502133 100644 --- a/apps/Task.js +++ b/apps/Task.js @@ -60,7 +60,7 @@ export class Task extends plugin { return { message: `获取帖子失败,无法继续任务` }; } - let postId = postData.data.postList[0].postId; + let { postId } = postData.data.postList[0]; let toUserId = postData.data.postList[0].userId; let message = `账号 ${account.userId} 的任务结果\n\n`; @@ -184,7 +184,7 @@ export class Task extends plugin { return { message: `获取帖子失败,无法继续任务` }; } - let postId = postData.data.postList[0].postId; + let { postId } = postData.data.postList[0]; let toUserId = postData.data.postList[0].userId; const signData = await kuro.signIn(account.token); diff --git a/apps/Update.js b/apps/Update.js index dd128c9..a857b32 100644 --- a/apps/Update.js +++ b/apps/Update.js @@ -184,7 +184,7 @@ export class Update extends plugin { * @returns */ async makeForwardMsg(title, msg, end) { - let nickname = (this.e.bot ?? Bot).nickname + let { nickname } = this.e.bot ?? Bot if (this.e.isGroup) { let info = await (this.e.bot ?? Bot).getGroupMemberInfo(this.e.group_id, (this.e.bot ?? Bot).uin) nickname = info.card || info.nickname diff --git a/apps/imgUpload.js b/apps/imgUpload.js index 9329a4b..33748b4 100644 --- a/apps/imgUpload.js +++ b/apps/imgUpload.js @@ -63,7 +63,7 @@ export class ImgUploader extends plugin { try { source = (await e[e.isGroup ? 'group' : 'friend']?.getChatHistory(e.isGroup ? e.source?.seq : e.source?.time + 1, 1))?.pop(); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取历史消息出错:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取历史消息出错`), logger.red(error)); } if (source) { @@ -142,7 +142,7 @@ export class ImgUploader extends plugin { e.isGroup ? e.source.seq : e.source.time + 1, 1 ))?.pop(); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取历史消息出错:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取历史消息出错`), logger.red(error)); return null; } })(); @@ -241,13 +241,7 @@ export class ImgUploader extends plugin { return true; } catch (error) { - const errorMessage = error.response - ? `下载文件失败: ${error.response.statusText}` - : error.code === 'ECONNABORTED' - ? `下载超时` - : `保存文件失败: ${error.message}`; - - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(errorMessage)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`下载面板图出错`), logger.red(error)); return false; } } diff --git a/components/Code.js b/components/Code.js index b6d35ff..9192714 100644 --- a/components/Code.js +++ b/components/Code.js @@ -44,15 +44,15 @@ class Waves { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`验证码登录成功,库街区用户:${response.data.data.userName}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`验证码登录成功,库街区用户`), logger.green(response.data.data.userName)); } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`验证码登录失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`验证码登录失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`验证码登录失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`验证码登录失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '登录失败,疑似网络问题,请检查控制台日志' }; } } @@ -70,17 +70,17 @@ class Waves { const response = await axios.post(CONSTANTS.GAME_DATA_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, 'token': token } }); if (response.data.code === 220) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取可用性成功:账号已过期`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取可用性成功,账号已过期`)); return false; } else { if (Config.getConfig().enable_log) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取可用性成功:账号可用`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取可用性成功,账号可用`)); } return true; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取可用性失败,疑似网络问题:\n${error}`)); - return strict ? false : true; + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取可用性失败,疑似网络问题`), logger.red(error)); + return !strict; } } @@ -102,11 +102,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`刷新资料失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`刷新资料失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`刷新资料失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`刷新资料失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '刷新资料失败,疑似网络问题,请检查控制台日志' }; } } @@ -134,11 +134,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取日常数据失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取日常数据失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取日常数据失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取日常数据失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取日常数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -168,11 +168,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取我的资料失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取我的资料失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取我的资料失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取我的资料失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取我的资料失败,疑似网络问题,请检查控制台日志' }; } } @@ -202,11 +202,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取共鸣者失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取共鸣者失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取共鸣者失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取共鸣者失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取共鸣者失败,疑似网络问题,请检查控制台日志' }; } } @@ -236,11 +236,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取数据坞失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取数据坞失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取数据坞失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取数据坞失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取数据坞失败,疑似网络问题,请检查控制台日志' }; } } @@ -271,11 +271,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取挑战数据失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取挑战数据失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取挑战数据失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取挑战数据失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取挑战数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -306,11 +306,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取探索数据失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取探索数据失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取探索数据失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取探索数据失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取探索数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -340,11 +340,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取角色详细信息失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取角色详细信息失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取角色详细信息失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取角色详细信息失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取角色详细信息失败,疑似网络问题,请检查控制台日志' }; } @@ -376,11 +376,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`签到失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`签到失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`签到失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`签到失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '签到失败,疑似网络问题,请检查控制台日志' }; } } @@ -409,11 +409,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`查询签到领取记录失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`查询签到领取记录失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`查询签到领取记录失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`查询签到领取记录失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '查询签到领取记录失败,疑似网络问题,请检查控制台日志' }; } } @@ -446,7 +446,7 @@ class Waves { } return { status: true, data: other.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取逆境深塔数据失败:${other.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取逆境深塔数据失败`), logger.red(other.data.msg)); return { status: false, msg: other.data.msg }; } } @@ -455,11 +455,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取逆境深塔数据失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取逆境深塔数据失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取逆境深塔数据失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取逆境深塔数据失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取逆境深塔数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -467,7 +467,7 @@ class Waves { // 抽卡记录 async getGaCha(data) { - const isCN = data.serverId == "76402e5b20be2c39f095a152090afddc" ? true : false; + const isCN = !!(data.serverId == "76402e5b20be2c39f095a152090afddc"); try { const response = await axios.post(isCN ? CONSTANTS.GACHA_URL : CONSTANTS.INTL_GACHA_URL, data); @@ -482,11 +482,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取抽卡记录失败:${response.data.message}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取抽卡记录失败`), logger.red(response.data.message)); return { status: false, msg: response.data.message }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取抽卡记录失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取抽卡记录失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取抽卡记录失败,疑似网络问题,请检查控制台日志' }; } } @@ -532,11 +532,11 @@ class Waves { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取活动列表失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取活动列表失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取活动列表失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取活动列表失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取活动列表失败,疑似网络问题,请检查控制台日志' }; } } diff --git a/components/Config.js b/components/Config.js index 64f614f..cec1451 100644 --- a/components/Config.js +++ b/components/Config.js @@ -25,7 +25,8 @@ class Config { try { return YAML.parse(fs.readFileSync(filePath, 'utf-8')); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`读取 ${filePath} 失败:\n${error}`)); + const fileName = filePath.split('/').pop(); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`读取 ${fileName} 失败`), logger.red(error)); return null; } } @@ -35,7 +36,8 @@ class Config { fs.writeFileSync(filePath, YAML.stringify(data)); return true; } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`写入 ${filePath} 失败:\n${error}`)); + const fileName = filePath.split('/').pop(); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`写入 ${fileName} 失败`), logger.red(error)); return false; } } @@ -93,7 +95,7 @@ class Config { try { return fs.existsSync(userConfigData) ? this.loadYAML(userConfigData) : []; } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`读取用户配置 ${userId}.yaml 失败:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`读取用户数据 ${userId}.yaml 失败`), logger.red(error)); return []; } } @@ -111,7 +113,7 @@ class Config { redis.set(`Yunzai:waves:users:${userId}`, JSON.stringify(userData)); return true; } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`写入用户配置 ${userId}.yaml 失败:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`写入用户数据 ${userId}.yaml 失败`), logger.red(error)); return false; } } diff --git a/components/Kuro.js b/components/Kuro.js index a4cb181..017dc4f 100644 --- a/components/Kuro.js +++ b/components/Kuro.js @@ -32,17 +32,17 @@ class Kuro { const response = await axios.post(CONSTANTS.TASK_PROCESS_URL, data, { headers: { ...CONSTANTS.REQUEST_HEADERS_BASE, 'token': token, devcode: '' } }); if (response.data.code === 220) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取可用性成功:账号已过期`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取可用性成功,账号已过期`)); return false; } else { if (Config.getConfig().enable_log) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取可用性成功:账号可用`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取可用性成功,账号可用`)); } return true; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取可用性失败,疑似网络问题:\n${error}`)); - return strict ? false : true; + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取可用性失败,疑似网络问题`), logger.red(error)); + return !strict; } } @@ -62,11 +62,11 @@ class Kuro { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区用户签到失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区用户签到失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区用户签到失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区用户签到失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '库街区用户签到失败,疑似网络问题,请检查控制台日志' }; } } @@ -90,11 +90,11 @@ class Kuro { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区点赞失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区点赞失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区点赞失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区点赞失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '库街区点赞失败,疑似网络问题,请检查控制台日志' }; } } @@ -114,11 +114,11 @@ class Kuro { } return { status: true, data: response.data.msg }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区分享失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区分享失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区分享失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区分享失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '库街区分享失败,疑似网络问题,请检查控制台日志' }; } } @@ -138,11 +138,11 @@ class Kuro { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区浏览帖子失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区浏览帖子失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区浏览帖子失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区浏览帖子失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '库街区浏览帖子失败,疑似网络问题,请检查控制台日志' }; } } @@ -163,10 +163,10 @@ class Kuro { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取帖子失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区获取帖子失败`), logger.red(response.data.msg)); } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取帖子失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区获取帖子失败,疑似网络问题`), logger.red(error)); } } @@ -185,11 +185,11 @@ class Kuro { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取任务进度失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区获取任务进度失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取任务进度失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区获取任务进度失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '库街区获取任务进度失败,疑似网络问题,请检查控制台日志' }; } } @@ -206,11 +206,11 @@ class Kuro { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取库洛币总数失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区获取库洛币总数失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取库洛币总数失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`库街区获取库洛币总数失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '库街区获取库洛币总数失败,疑似网络问题,请检查控制台日志' }; } } diff --git a/components/Render.js b/components/Render.js index bc8f619..6b12337 100644 --- a/components/Render.js +++ b/components/Render.js @@ -40,7 +40,7 @@ const Render = { currentVersion = package_json.version } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`读取 package.json 失败:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`读取 package.json 失败`), logger.red(error)); } return e.runtime.render('waves-plugin', path, params, { retType: cfg.retType || (cfg.retMsgId ? 'msgId' : 'default'), diff --git a/components/Server.js b/components/Server.js index 9a218ec..a2dc0bd 100644 --- a/components/Server.js +++ b/components/Server.js @@ -21,7 +21,7 @@ class Server { }, 5000); this.app.get('/login/:id', async (req, res) => { - const id = req.params.id; + const { id } = req.params; const filePath = this.data[id] ? '/server/login.html' : '/server/error.html'; try { @@ -33,13 +33,13 @@ class Server { data = data.replace(/background_image/g, await Config.getConfig().background_api); res.send(data); } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`发送登录页失败:\n${error}}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`发送登录页失败`), logger.red(error)); res.status(500).send('Internal Server Error'); } }); this.app.post('/code/:id', async (req, res) => { - const id = req.params.id; + const { id } = req.params; const { mobile, code } = req.body; if (!this.data[id]) return res.status(200).json({ code: 400, msg: 'Authorization is required' }); @@ -64,16 +64,16 @@ class Server { if (allowLogin && !this.server) { const port = await Config.getConfig().server_port; this.server = this.app.listen(port, () => { - logger.mark(logger.blue('[Waves PLUGIN]'), logger.white(`在线登录服务端点`), logger.green(`http://localhost:${port}`)); + logger.mark(logger.blue('[Waves PLUGIN]'), logger.cyan(`已开启 HTTP 登录服务器,本地端口为`), logger.green(port)); }); } if (!allowLogin && this.server) { this.server.close((error) => { if (error) { - logger.mark(logger.blue('[Waves PLUGIN]'), logger.white(`无法关闭登录服务器`), logger.red(error)); + logger.mark(logger.blue('[Waves PLUGIN]'), logger.cyan(`无法关闭登录服务器`), logger.red(error)); } else { - logger.mark(logger.blue('[Waves PLUGIN]'), logger.white(`已关闭登录服务器`)); + logger.mark(logger.blue('[Waves PLUGIN]'), logger.cyan(`已关闭登录服务器`)); } }); this.server = null; diff --git a/components/Version.js b/components/Version.js index 83d9b64..41370f9 100644 --- a/components/Version.js +++ b/components/Version.js @@ -4,7 +4,7 @@ let packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')) const yunzaiVersion = packageJson.version const isMiao = packageJson.name === 'miao-yunzai' -const isTrss = Array.isArray(Bot.uin) ? true : false +const isTrss = !!Array.isArray(Bot.uin) let Version = { isMiao, diff --git a/components/Wiki.js b/components/Wiki.js index 07d00a2..72e2db2 100644 --- a/components/Wiki.js +++ b/components/Wiki.js @@ -50,11 +50,11 @@ class Wiki { if (response.data.code === 200) { return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 列表失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取 Wiki 列表失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取Wiki列表失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取Wiki列表失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取 Wiki 列表失败,疑似网络问题,请检查控制台日志' }; } } @@ -64,7 +64,7 @@ class Wiki { if (type) { const response = await this.getPage(type); if (response.status) { - const records = response.data.results.records; + const { records } = response.data.results; for (const record of records) { if (record.name === name) { return { status: true, record: record, type: type } @@ -94,7 +94,7 @@ class Wiki { async getEntry(name, type = '') { const recordData = await this.getRecord(name, type); if (recordData.status) { - const linkId = recordData.record.content.linkId; + const { linkId } = recordData.record.content; const entryData = await this.getEntryDetail(linkId); if (entryData.status) { return { status: true, record: entryData.data, type: recordData.type }; @@ -122,11 +122,11 @@ class Wiki { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 详情失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取 Wiki 详情失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 详情失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取 Wiki 详情失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取 Wiki 详情失败,疑似网络问题,请检查控制台日志' }; } } @@ -173,11 +173,11 @@ class Wiki { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`搜索 Wiki 失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`搜索 Wiki 失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`搜索 Wiki 失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`搜索 Wiki 失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '搜索 Wiki 失败,疑似网络问题,请检查控制台日志' }; } } @@ -208,11 +208,11 @@ class Wiki { } return { status: true, data: response.data.data }; } else { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 首页失败:${response.data.msg}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取 Wiki 首页失败`), logger.red(response.data.msg)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 首页失败,疑似网络问题:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`获取 Wiki 首页失败,疑似网络问题`), logger.red(error)); return { status: false, msg: '获取 Wiki 首页失败,疑似网络问题,请检查控制台日志' }; } } diff --git a/model/init.js b/model/init.js index 10275ff..a48dd21 100644 --- a/model/init.js +++ b/model/init.js @@ -8,7 +8,7 @@ class Init { this.compatible() this.initConfig() this.syncConfig().then(syncCount => { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.white(`同步了`), logger.green(syncCount), logger.white(`个用户信息`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`同步了`), logger.green(syncCount), logger.cyan(`个用户信息`)); }); } @@ -105,7 +105,7 @@ class Init { await redis.set(`Yunzai:waves:users:${fileName.split('.')[0]}`, JSON.stringify(userInfo)); successCount++; } catch (error) { - logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`同步用户信息失败:\n${error}`)); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.cyan(`同步用户信息失败`), logger.red(error)); } } diff --git a/package.json b/package.json index efae83d..3d9145c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waves-plugin", - "version": "1.5.14", + "version": "1.5.15", "description": "基于 Yunzai 的鸣潮游戏数据查询插件", "main": "index.js", "scripts": { diff --git a/resources/server/error.html b/resources/server/error.html index 47719cd..566963b 100644 --- a/resources/server/error.html +++ b/resources/server/error.html @@ -1 +1 @@ -