From 510dbb7c205a90946b6a33339e1f44c28e27f10f Mon Sep 17 00:00:00 2001 From: ZeroCal Su <3146312184@qq.com> Date: Thu, 28 Nov 2024 21:47:21 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BC=98=E5=8C=96=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=95=B4=E4=BD=93=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/Bind.js | 10 +-- apps/Calabash.js | 4 +- apps/Challenge.js | 4 +- apps/Character.js | 4 +- apps/Explore.js | 4 +- apps/Gacha.js | 10 +-- apps/Guide.js | 4 +- apps/Manage.js | 16 +++-- apps/News.js | 47 ++++++------- apps/Sanity.js | 112 ++++++++++++++++--------------- apps/Setting.js | 30 ++++----- apps/SignIn.js | 15 +++-- apps/Task.js | 15 +++-- apps/Tower.js | 4 +- apps/Training.js | 4 +- apps/Update.js | 2 +- apps/User.js | 4 +- apps/imgUpload.js | 6 +- components/Code.js | 118 ++++++++++++++++----------------- components/Config.js | 131 ++++++++++++++++++++++++------------- components/Kuro.js | 48 +++++++------- components/Render.js | 6 +- components/Server.js | 52 ++++++++++----- components/Wiki.js | 34 +++++----- config/config_default.yaml | 14 +--- config/user_default.yaml | 9 +++ guoba.support.js | 87 ++++++++++++++---------- model/init.js | 86 +++++++++++------------- package.json | 7 +- utils/Calculate.js | 2 +- utils/logs.js | 46 ------------- 31 files changed, 485 insertions(+), 450 deletions(-) create mode 100644 config/user_default.yaml delete mode 100644 utils/logs.js diff --git a/apps/Bind.js b/apps/Bind.js index 68c3397..f1b68ea 100644 --- a/apps/Bind.js +++ b/apps/Bind.js @@ -84,17 +84,17 @@ export class Bind extends plugin { return await e.reply(`登录失败!原因:${gameData.msg}\n使用[~登录帮助]查看登录方法!`); } - const userConfig = Config.getUserConfig(e.user_id); + const userConfig = Config.getUserData(e.user_id); const userData = { token, userId: gameData.data.userId, serverId: gameData.data.serverId, roleId: gameData.data.roleId }; const userIndex = userConfig.findIndex(item => item.userId === gameData.data.userId); userIndex !== -1 ? (userConfig[userIndex] = userData) : userConfig.push(userData); await redis.set(`Yunzai:waves:bind:${e.user_id}`, gameData.data.roleId); - Config.setUserConfig(e.user_id, userConfig); + Config.setUserData(e.user_id, userConfig); return await e.reply(`${gameData.data.roleName}(${gameData.data.roleId}) 登录成功!`, true); } async unLogin(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); @@ -112,13 +112,13 @@ export class Bind extends plugin { let index = accountList.findIndex(item => item.roleId == roleId); accountList.splice(index, 1); await e.reply(`已删除账号 ${roleId}`); - Config.setUserConfig(e.user_id, accountList); + Config.setUserData(e.user_id, accountList); } return true; } async getToken(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); diff --git a/apps/Calabash.js b/apps/Calabash.js index 645783a..cfe8c97 100644 --- a/apps/Calabash.js +++ b/apps/Calabash.js @@ -21,7 +21,7 @@ export class Calabash extends plugin { async calabash(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); const [, roleId] = e.msg.match(this.rule[0].reg); @@ -89,7 +89,7 @@ export class Calabash extends plugin { if (deleteroleId.length) { const newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { diff --git a/apps/Challenge.js b/apps/Challenge.js index 3fb3ae1..3106306 100644 --- a/apps/Challenge.js +++ b/apps/Challenge.js @@ -21,7 +21,7 @@ export class Challenge extends plugin { async challenge(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); const [, roleId] = e.msg.match(this.rule[0].reg); @@ -103,7 +103,7 @@ export class Challenge extends plugin { if (deleteroleId.length) { const newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { diff --git a/apps/Character.js b/apps/Character.js index aa9c6e3..80a8275 100644 --- a/apps/Character.js +++ b/apps/Character.js @@ -26,7 +26,7 @@ export class Character extends plugin { async character(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); const [, message, roleId] = e.msg.match(this.rule[0].reg); @@ -135,7 +135,7 @@ export class Character extends plugin { if (deleteroleId.length) { const newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } imgList = [...new Set(imgList)]; diff --git a/apps/Explore.js b/apps/Explore.js index 7f7344c..55c05ae 100644 --- a/apps/Explore.js +++ b/apps/Explore.js @@ -21,7 +21,7 @@ export class Explore extends plugin { async explore(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); const [, roleId] = e.msg.match(this.rule[0].reg); @@ -83,7 +83,7 @@ export class Explore extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { diff --git a/apps/Gacha.js b/apps/Gacha.js index 851802f..0948112 100644 --- a/apps/Gacha.js +++ b/apps/Gacha.js @@ -213,7 +213,7 @@ export class Gacha extends plugin { } fs.writeFileSync(`${_path}/data/wavesGacha/${jsonData.playerId}_Export.json`, JSON.stringify(json, null, 2)); - logger.info(`[Waves-Plugin] 已写入本地文件 ${jsonData.playerId}_Export.json`) + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`已写入本地文件 ${jsonData.playerId}_Export.json`)); return true; } @@ -249,9 +249,9 @@ export class Gacha extends plugin { try { await Bot.download(fileUrl, path); - } catch (err) { - logger.error(`文件下载错误:${logger.red(err.stack)}`); - await this.reply(`导入抽卡记录失败:${err.message || '未知错误'}`, true); + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), 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.info(`[Waves-Plugin] 已写入本地文件 ${uid}_Export.json`); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`已写入本地文件 ${uid}_Export.json`)); return true; } diff --git a/apps/Guide.js b/apps/Guide.js index 35a9e8b..3e95c1a 100644 --- a/apps/Guide.js +++ b/apps/Guide.js @@ -65,10 +65,10 @@ export class Guide extends plugin { if (!entryData.status) { if (/^(~|~|鸣潮)/.test(e.msg)) { - logger.info(`[Waves-Plugin] 尝试搜索图鉴:${message}`) + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`尝试搜索图鉴:${message}`)); let result = await wiki.search(message) if (!result.status) { - logger.warn(`[Waves-Plugin] 未能搜索到图鉴内容:${message}`) + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`未能搜索到图鉴内容:${message}`)); await e.reply(`未能获取到${message}的图鉴,请检查输入是否正确`) return false } else { diff --git a/apps/Manage.js b/apps/Manage.js index 1b3d103..51fa7f4 100644 --- a/apps/Manage.js +++ b/apps/Manage.js @@ -4,6 +4,7 @@ import Waves from "../components/Code.js"; import { _path } from '../model/path.js'; import Render from '../components/Render.js'; import fs from 'fs/promises'; +import pLimit from 'p-limit'; import YAML from 'yaml'; export class Manage extends plugin { @@ -40,7 +41,10 @@ export class Manage extends plugin { return YAML.parse(content); })); - const results = await Promise.all(userCounts.flat().map(user => waves.isAvailable(user.token, true))); + const limit = pLimit(Config.getConfig().limit); + const results = await Promise.all( + userCounts.flat().map(user => limit(() => waves.isAvailable(user.token, true))) + ) const available = results.filter(Boolean).length; const expired = results.length - available; @@ -60,8 +64,8 @@ export class Manage extends plugin { }, { e, retType: 'base64' }); await e.reply(imageCard); - } catch (err) { - logger.error('计算总用户数时出现错误', err); + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`计算总用户数时出现错误:\n${error}`)); await e.reply('[Waves-Plugin] 账号总数\n计算总用户数时出现错误,请检查日志'); } } @@ -86,12 +90,12 @@ export class Manage extends plugin { return valid ? user : null; })); - Config.setUserConfig(file.slice(0, -5), validUsers.filter(Boolean)); + Config.setUserData(file.slice(0, -5), validUsers.filter(Boolean)); })); await e.reply(`[Waves-Plugin] 删除失效账号\n删除了 ${deleted} 个失效账号`); - } catch (err) { - logger.error('删除失效账号时出现错误', err); + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`删除失效账号时出现错误:\n${error}`)); await e.reply('[Waves-Plugin] 删除失效账号\n删除失效账号时出现错误,请检查日志'); } return true; diff --git a/apps/News.js b/apps/News.js index 55a8086..3635fca 100644 --- a/apps/News.js +++ b/apps/News.js @@ -1,6 +1,7 @@ import plugin from '../../../lib/plugins/plugin.js' import Waves from "../components/Code.js"; import Config from "../components/Config.js"; +import pLimit from 'p-limit'; export class News extends plugin { constructor() { @@ -43,7 +44,7 @@ export class News extends plugin { } async autoNews() { - const { waves_auto_news_list: autoPushList } = Config.getConfig(); + const { waves_auto_news_list: autoPushList } = Config.getUserConfig(); if (!autoPushList.length) { return true; @@ -53,36 +54,38 @@ export class News extends plugin { const newsData = await waves.getEventList(); if (!newsData.status) { - logger.info(newsData.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(newsData.msg)); return true; } const postId = newsData.data.list[0].postId; if (postId != await redis.get(`Yunzai:waves:news`)) { - await Promise.all(autoPushList.map(async (user) => { - const { botId, groupId, userId } = user; + const limit = pLimit(Config.getConfig().limit); + await Promise.all(autoPushList.map(user => + limit(async () => { + const { botId, groupId, userId } = user; - let isGroup = !!groupId; - let id = isGroup ? groupId : userId; + let isGroup = !!groupId; + let id = isGroup ? groupId : userId; - if (isGroup) { - await Bot[botId]?.pickGroup(id).sendMsg([ - segment.image(newsData.data.list[0].coverUrl), - `${newsData.data.list[0].postTitle}\nhttps://www.kurobbs.com/mc/post/${newsData.data.list[0].postId}\n\n${new Date(newsData.data.list[0].publishTime).toLocaleString()}` - ]); - } else { - await Bot[botId]?.pickUser(id).sendMsg([ - segment.image(newsData.data.list[0].coverUrl), - `${newsData.data.list[0].postTitle}\nhttps://www.kurobbs.com/mc/post/${newsData.data.list[0].postId}\n\n${new Date(newsData.data.list[0].publishTime).toLocaleString()}` - ]); - } + if (isGroup) { + await Bot[botId]?.pickGroup(id).sendMsg([ + segment.image(newsData.data.list[0].coverUrl), + `${newsData.data.list[0].postTitle}\nhttps://www.kurobbs.com/mc/post/${newsData.data.list[0].postId}\n\n${new Date(newsData.data.list[0].publishTime).toLocaleString()}` + ]); + } else { + await Bot[botId]?.pickUser(id).sendMsg([ + segment.image(newsData.data.list[0].coverUrl), + `${newsData.data.list[0].postTitle}\nhttps://www.kurobbs.com/mc/post/${newsData.data.list[0].postId}\n\n${new Date(newsData.data.list[0].publishTime).toLocaleString()}` + ]); + } - redis.set(`Yunzai:waves:news`, postId); - logger.info(`[Waves-Plugin] 新闻推送: 已推送最新公告`); - return true; - })); + redis.set(`Yunzai:waves:news`, postId); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`已推送最新公告`)); + return true; + }))); } else { - logger.info(`[Waves-Plugin] 新闻推送: 未获取到新公告`); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`未获取到新公告`)); return true; } } diff --git a/apps/Sanity.js b/apps/Sanity.js index f5a9b28..77be9b8 100644 --- a/apps/Sanity.js +++ b/apps/Sanity.js @@ -2,6 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js' import Waves from "../components/Code.js"; import Config from "../components/Config.js"; import Render from '../components/Render.js'; +import pLimit from 'p-limit'; export class Sanity extends plugin { constructor() { @@ -25,7 +26,7 @@ export class Sanity extends plugin { } async sanity(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); @@ -60,7 +61,7 @@ export class Sanity extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { @@ -73,69 +74,72 @@ export class Sanity extends plugin { } async autoPush() { - const { waves_auto_push_list: autoPushList } = Config.getConfig(); - await Promise.all(autoPushList.map(async user => { - const { botId, groupId, userId } = user; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${userId}`)) || await Config.getUserConfig(userId); - if (!accountList.length) { - return - } + const { waves_auto_push_list: autoPushList } = Config.getUserConfig(); + const limit = pLimit(Config.getConfig().limit); + await Promise.all(autoPushList.map(user => + limit(async () => { + const { botId, groupId, userId } = user; + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${userId}`)) || await Config.getUserData(userId); + if (!accountList.length) { + return + } - const waves = new Waves(); - let data = []; - let deleteroleId = []; + const waves = new Waves(); + let data = []; + let deleteroleId = []; - for (let account of accountList) { - const usability = await waves.isAvailable(account.token); + for (let account of accountList) { + const usability = await waves.isAvailable(account.token); - if (!usability) { - data.push({ message: `账号 ${account.roleId} 的Token已失效\n请重新登录Token` }); - deleteroleId.push(account.roleId); - continue; - } + if (!usability) { + data.push({ message: `账号 ${account.roleId} 的Token已失效\n请重新登录Token` }); + deleteroleId.push(account.roleId); + continue; + } - const result = await waves.getGameData(account.token); + const result = await waves.getGameData(account.token); - if (!result.status) { - data.push({ message: result.msg }) - return true; - } + if (!result.status) { + data.push({ message: result.msg }) + return true; + } - const key = `Yunzai:waves:pushed:${result.data.roleId}`; - const isPushed = await redis.get(key); - const threshold = await redis.get(`Yunzai:waves:sanity_threshold:${userId}`) || result.data.energyData.total; - const isFull = result.data.energyData.cur >= threshold; - if (isFull && !isPushed) { - data.push({ message: `漂泊者${result.data.roleName}(${result.data.roleId}),你的结晶波片已经恢复至 ${threshold} 了哦~` }) - await redis.set(key, 'true'); - } else if (!isFull && isPushed) { - await redis.del(key); + const key = `Yunzai:waves:pushed:${result.data.roleId}`; + const isPushed = await redis.get(key); + const threshold = await redis.get(`Yunzai:waves:sanity_threshold:${userId}`) || result.data.energyData.total; + const isFull = result.data.energyData.cur >= threshold; + if (isFull && !isPushed) { + data.push({ message: `漂泊者${result.data.roleName}(${result.data.roleId}),你的结晶波片已经恢复至 ${threshold} 了哦~` }) + await redis.set(key, 'true'); + } else if (!isFull && isPushed) { + await redis.del(key); + } } - } - if (deleteroleId.length) { - let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(userId, newAccountList); - } + if (deleteroleId.length) { + let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); + Config.setUserData(userId, newAccountList); + } - if (data.length) { - if (data.length === 1) { - if (!groupId) { - await Bot[botId]?.pickUser(userId).sendMsg(data[0].message) + if (data.length) { + if (data.length === 1) { + if (!groupId) { + await Bot[botId]?.pickUser(userId).sendMsg(data[0].message) + } else { + await Bot[botId]?.pickGroup(groupId).sendMsg([segment.at(userId), data[0].message]) + } + return true; } else { - 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])) + 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; - })) + return true; + }) + )); } } \ No newline at end of file diff --git a/apps/Setting.js b/apps/Setting.js index a82439c..fc5d73b 100644 --- a/apps/Setting.js +++ b/apps/Setting.js @@ -33,10 +33,10 @@ export class Setting extends plugin { } async setAutoSign(e) { - const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList.length) return e.reply("你还没有登录任何账号呢,请使用[~登录]进行登录"); - const config = await Config.getConfig(); + const config = await Config.getUserConfig(); const newUser = { botId: e.self_id || '', groupId: e.group_id || '', @@ -50,7 +50,7 @@ export class Setting extends plugin { if (e.msg.includes('开启')) { if (index === -1) { config.waves_auto_signin_list.push(newUser); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已开启自动签到", true); } return e.reply("你已经开启了自动签到,无需再次开启", true); @@ -58,17 +58,17 @@ export class Setting extends plugin { if (index !== -1) { config.waves_auto_signin_list.splice(index, 1); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已关闭自动签到", true); } return e.reply("你已经关闭了自动签到,无需再次关闭", true); } async setAutoTask(e) { - const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList.length) return e.reply("你还没有登录任何账号呢,请使用[~登录]进行登录"); - const config = await Config.getConfig(); + const config = await Config.getUserConfig(); const newUser = { botId: e.self_id || '', groupId: e.group_id || '', @@ -84,7 +84,7 @@ export class Setting extends plugin { if (e.msg.includes('开启')) { if (index === -1) { config.waves_auto_task_list.push(newUser); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已开启自动任务", true); } return e.reply("你已经开启了自动任务,无需再次开启", true); @@ -92,17 +92,17 @@ export class Setting extends plugin { if (index !== -1) { config.waves_auto_task_list.splice(index, 1); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已关闭自动任务", true); } return e.reply("你已经关闭了自动任务,无需再次关闭", true); } async setAutoPush(e) { - const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList.length) return e.reply("你还没有登录任何账号呢,请使用[~登录]进行登录"); - const config = await Config.getConfig(); + const config = await Config.getUserConfig(); const newUser = { botId: e.self_id || '', groupId: e.group_id || '', @@ -118,7 +118,7 @@ export class Setting extends plugin { if (e.msg.includes('开启')) { if (index === -1) { config.waves_auto_push_list.push(newUser); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已开启结晶波片推送,可以使用[~体力阈值]来自定义提醒阈值", true); } return e.reply("你已经开启了结晶波片推送,,无需再次开启", true); @@ -126,7 +126,7 @@ export class Setting extends plugin { if (index !== -1) { config.waves_auto_push_list.splice(index, 1); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已关闭结晶波片推送", true); } return e.reply("你已经关闭了结晶波片推送,无需再次关闭", true); @@ -146,7 +146,7 @@ export class Setting extends plugin { } } - const config = await Config.getConfig(); + const config = await Config.getUserConfig(); const index = config.waves_auto_news_list.findIndex(user => user.botId === newUser.botId && user.groupId === newUser.groupId && @@ -156,7 +156,7 @@ export class Setting extends plugin { if (e.msg.includes('开启')) { if (index === -1) { config.waves_auto_news_list.push(newUser); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已开启活动推送", true); } return e.reply("你已经开启了活动推送,无需再次开启", true); @@ -164,7 +164,7 @@ export class Setting extends plugin { if (index !== -1) { config.waves_auto_news_list.splice(index, 1); - Config.setConfig(config); + Config.setUserConfig(config); return e.reply("已关闭活动推送", true); } return e.reply("你已经关闭了活动推送,无需再次关闭", true); diff --git a/apps/SignIn.js b/apps/SignIn.js index 749ad2e..64a98a8 100644 --- a/apps/SignIn.js +++ b/apps/SignIn.js @@ -36,7 +36,7 @@ export class SignIn extends plugin { } async signIn(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); @@ -69,7 +69,7 @@ export class SignIn extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { @@ -82,7 +82,7 @@ export class SignIn extends plugin { } async signInList(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); @@ -117,7 +117,7 @@ export class SignIn extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { @@ -135,11 +135,12 @@ export class SignIn extends plugin { if (this.e) await this.e.reply('正在执行全部签到,稍后会推送签到结果'); - const { waves_auto_signin_list: autoSignInList, signin_interval: interval } = Config.getConfig(); + const { waves_auto_signin_list: autoSignInList } = Config.getUserConfig(); + const { signin_interval: interval } = Config.getConfig(); let success = 0; for (let user of autoSignInList) { const { botId, groupId, userId } = user; - const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${userId}`)) || await Config.getUserConfig(userId); + const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${userId}`)) || await Config.getUserData(userId); if (!accountList.length) { continue; } @@ -166,7 +167,7 @@ export class SignIn extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(userId, newAccountList); + Config.setUserData(userId, newAccountList); } if (data.length) Bot[botId]?.pickUser(userId).sendMsg(Bot.makeForwardMsg(data)) diff --git a/apps/Task.js b/apps/Task.js index af51bf6..5503776 100644 --- a/apps/Task.js +++ b/apps/Task.js @@ -36,7 +36,7 @@ export class Task extends plugin { } async doTask(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); @@ -87,7 +87,7 @@ export class Task extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { @@ -100,7 +100,7 @@ export class Task extends plugin { } async taskList(e) { - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); if (!accountList || !accountList.length) { return await e.reply('当前没有登录任何账号,请使用[~登录]进行登录'); @@ -138,7 +138,7 @@ export class Task extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { @@ -156,11 +156,12 @@ export class Task extends plugin { if (this.e) await this.e.reply('正在执行全部任务,稍后会推送签到结果'); - const { waves_auto_task_list: autoTaskList, task_interval: interval } = Config.getConfig(); + const { waves_auto_task_list: autoTaskList } = Config.getUserConfig(); + const { task_interval: interval } = Config.getConfig(); let success = 0; for (let user of autoTaskList) { const { botId, groupId, userId } = user; - const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${userId}`)) || await Config.getUserConfig(userId); + const accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${userId}`)) || await Config.getUserData(userId); if (!accountList.length) { continue; } @@ -207,7 +208,7 @@ export class Task extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(userId, newAccountList); + Config.setUserData(userId, newAccountList); } if (data.length) Bot[botId]?.pickUser(userId).sendMsg(Bot.makeForwardMsg(data)) diff --git a/apps/Tower.js b/apps/Tower.js index 5c36ba3..2957ef6 100644 --- a/apps/Tower.js +++ b/apps/Tower.js @@ -21,7 +21,7 @@ export class TowerInfo extends plugin { async tower(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); let [, key, roleId] = e.msg.match(this.rule[0].reg) @@ -89,7 +89,7 @@ export class TowerInfo extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { diff --git a/apps/Training.js b/apps/Training.js index fb75ebd..536047e 100644 --- a/apps/Training.js +++ b/apps/Training.js @@ -22,7 +22,7 @@ export class Training extends plugin { async training(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); const [, roleId] = e.msg.match(this.rule[0].reg); @@ -97,7 +97,7 @@ export class Training extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { diff --git a/apps/Update.js b/apps/Update.js index 96a0e2c..dd128c9 100644 --- a/apps/Update.js +++ b/apps/Update.js @@ -15,7 +15,7 @@ let uping = false export class Update extends plugin { constructor() { super({ - name: 'Waves-更新插件', + name: '鸣潮-更新插件', event: 'message', priority: 1009, rule: [ diff --git a/apps/User.js b/apps/User.js index 60a8a20..d179921 100644 --- a/apps/User.js +++ b/apps/User.js @@ -21,7 +21,7 @@ export class UserInfo extends plugin { async user(e) { if (e.at) e.user_id = e.at; - let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserConfig(e.user_id); + let accountList = JSON.parse(await redis.get(`Yunzai:waves:users:${e.user_id}`)) || await Config.getUserData(e.user_id); const waves = new Waves(); const [, roleId] = e.msg.match(this.rule[0].reg); @@ -86,7 +86,7 @@ export class UserInfo extends plugin { if (deleteroleId.length) { let newAccountList = accountList.filter(account => !deleteroleId.includes(account.roleId)); - Config.setUserConfig(e.user_id, newAccountList); + Config.setUserData(e.user_id, newAccountList); } if (data.length === 1) { diff --git a/apps/imgUpload.js b/apps/imgUpload.js index 938d17d..9329a4b 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.error(error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取历史消息出错:\n${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.error(error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取历史消息出错:\n${error}`)); return null; } })(); @@ -247,7 +247,7 @@ export class ImgUploader extends plugin { ? `下载超时` : `保存文件失败: ${error.message}`; - logger.error(errorMessage); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(errorMessage)); return false; } } diff --git a/components/Code.js b/components/Code.js index 2226d37..b6d35ff 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.info(`验证码登录成功,库街区用户:${response.data.data.userName}`); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`验证码登录成功,库街区用户:${response.data.data.userName}`)); } return { status: true, data: response.data.data }; } else { - logger.error('验证码登录失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`验证码登录失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('验证码登录失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`验证码登录失败,疑似网络问题:\n${error}`)); return { status: false, msg: '登录失败,疑似网络问题,请检查控制台日志' }; } } @@ -70,16 +70,16 @@ 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.info('获取可用性成功:账号已过期'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取可用性成功:账号已过期`)); return false; } else { if (Config.getConfig().enable_log) { - logger.info('获取可用性成功:账号可用'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取可用性成功:账号可用`)); } return true; } } catch (error) { - logger.error('获取可用性失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取可用性失败,疑似网络问题:\n${error}`)); return strict ? false : true; } } @@ -98,15 +98,15 @@ class Waves { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('刷新资料成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`刷新资料成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('刷新资料失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`刷新资料失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('刷新资料失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`刷新资料失败,疑似网络问题:\n${error}`)); return { status: false, msg: '刷新资料失败,疑似网络问题,请检查控制台日志' }; } } @@ -126,19 +126,19 @@ class Waves { if (response.data.code === 200) { if (response.data.data === null) { - logger.info('获取日常数据失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取日常数据失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取日常数据成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取日常数据成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取日常数据失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取日常数据失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取日常数据失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取日常数据失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取日常数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -160,19 +160,19 @@ class Waves { if (response.data.code === 200) { response.data.data = JSON.parse(response.data.data) if (response.data.data === null || !response.data.data.showToGuest) { - logger.info('获取我的资料失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取我的资料失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取我的资料成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取我的资料成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取我的资料失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取我的资料失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取我的资料失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取我的资料失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取我的资料失败,疑似网络问题,请检查控制台日志' }; } } @@ -194,19 +194,19 @@ class Waves { if (response.data.code === 200) { response.data.data = JSON.parse(response.data.data) if (response.data.data === null || !response.data.data.showToGuest) { - logger.info('获取共鸣者失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取共鸣者失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取共鸣者成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取共鸣者成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取共鸣者失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取共鸣者失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取共鸣者失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取共鸣者失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取共鸣者失败,疑似网络问题,请检查控制台日志' }; } } @@ -228,19 +228,19 @@ class Waves { if (response.data.code === 200) { response.data.data = JSON.parse(response.data.data) if (response.data.data === null) { - logger.info('获取数据坞失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取数据坞失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取数据坞成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取数据坞成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取数据坞失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取数据坞失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取数据坞失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取数据坞失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取数据坞失败,疑似网络问题,请检查控制台日志' }; } } @@ -263,19 +263,19 @@ class Waves { if (response.data.code === 200) { response.data.data = JSON.parse(response.data.data) if (response.data.data === null || !response.data.data.open) { - logger.info('获取挑战数据失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取挑战数据失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取挑战数据成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取挑战数据成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取挑战数据失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取挑战数据失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取挑战数据失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取挑战数据失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取挑战数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -298,19 +298,19 @@ class Waves { if (response.data.code === 200) { response.data.data = JSON.parse(response.data.data) if (response.data.data === null || !response.data.data.open) { - logger.info('获取探索数据失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取探索数据失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取探索数据成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取探索数据成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取探索数据失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取探索数据失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取探索数据失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取探索数据失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取探索数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -332,19 +332,19 @@ class Waves { if (response.data.code === 200) { response.data.data = JSON.parse(response.data.data) if (response.data.data === null) { - logger.info('获取角色详细信息失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取角色详细信息失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取角色详细信息成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取角色详细信息成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取角色详细信息失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取角色详细信息失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取角色详细信息失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取角色详细信息失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取角色详细信息失败,疑似网络问题,请检查控制台日志' }; } @@ -368,19 +368,19 @@ class Waves { if (response.data.code === 200) { if (response.data.data === null) { - logger.info('签到失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`签到失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('签到成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`签到成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('签到失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`签到失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('签到失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`签到失败,疑似网络问题:\n${error}`)); return { status: false, msg: '签到失败,疑似网络问题,请检查控制台日志' }; } } @@ -401,19 +401,19 @@ class Waves { if (response.data.code === 200) { if (response.data.data === null) { - logger.info('查询签到领取记录失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`查询签到领取记录失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('查询签到领取记录成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`查询签到领取记录成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('查询签到领取记录失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`查询签到领取记录失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('查询签到领取记录失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`查询签到领取记录失败,疑似网络问题:\n${error}`)); return { status: false, msg: '查询签到领取记录失败,疑似网络问题,请检查控制台日志' }; } } @@ -438,28 +438,28 @@ class Waves { if (other.data.code === 200) { other.data.data = JSON.parse(other.data.data) if (other.data.data === null) { - logger.info('获取逆境深塔数据失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取逆境深塔数据失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取逆境深塔数据成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取逆境深塔数据成功`)); } return { status: true, data: other.data.data }; } else { - logger.error('获取逆境深塔数据失败:', other.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取逆境深塔数据失败:${other.data.msg}`)); return { status: false, msg: other.data.msg }; } } if (Config.getConfig().enable_log) { - logger.info('获取逆境深塔数据成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取逆境深塔数据成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取逆境深塔数据失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取逆境深塔数据失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取逆境深塔数据失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取逆境深塔数据失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取逆境深塔数据失败,疑似网络问题,请检查控制台日志' }; } } @@ -474,19 +474,19 @@ class Waves { if (response.data.code === 0) { if (response.data.data === null) { - logger.info('获取抽卡记录失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取抽卡记录失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取抽卡记录成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取抽卡记录成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取抽卡记录失败:', response.data.message); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取抽卡记录失败:${response.data.message}`)); return { status: false, msg: response.data.message }; } } catch (error) { - logger.error('获取抽卡记录失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取抽卡记录失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取抽卡记录失败,疑似网络问题,请检查控制台日志' }; } } @@ -524,19 +524,19 @@ class Waves { if (response.data.code === 200) { if (response.data.data === null) { - logger.info('获取活动列表失败,返回空数据'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取活动列表失败,返回空数据`)); return { status: false, msg: "查询信息失败,请检查库街区数据终端中对应板块的对外展示开关是否打开" }; } if (Config.getConfig().enable_log) { - logger.info('获取活动列表成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取活动列表成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取活动列表失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取活动列表失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取活动列表失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取活动列表失败,疑似网络问题:\n${error}`)); return { status: false, msg: '获取活动列表失败,疑似网络问题,请检查控制台日志' }; } } diff --git a/components/Config.js b/components/Config.js index 3591b09..64f614f 100644 --- a/components/Config.js +++ b/components/Config.js @@ -1,79 +1,120 @@ -import YAML from 'yaml' -import fs from 'fs' -import { pluginRoot, _path } from '../model/path.js' +import YAML from 'yaml'; +import fs from 'fs'; +import { pluginRoot, _path } from '../model/path.js'; class Config { - getConfig() { + constructor() { + this.cache = { + config: null, + config_default: null, + user: null, + user_default: null, + }; + + this.fileMaps = { + config: `${pluginRoot}/config/config/config.yaml`, + config_default: `${pluginRoot}/config/config_default.yaml`, + user: `${pluginRoot}/config/config/user.yaml`, + user_default: `${pluginRoot}/config/user_default.yaml`, + }; + + this.watchFiles(); + } + + loadYAML(filePath) { try { - return YAML.parse( - fs.readFileSync(`${pluginRoot}/config/config/config.yaml`, 'utf-8') - ) - } catch (err) { - logger.warn('读取 config.yaml 失败', err) - return false + return YAML.parse(fs.readFileSync(filePath, 'utf-8')); + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`读取 ${filePath} 失败:\n${error}`)); + return null; } } - getDefConfig() { + saveConfig(filePath, data) { try { - return YAML.parse( - fs.readFileSync(`${pluginRoot}/config/config_default.yaml`, 'utf-8') - ) - } catch (err) { - logger.warn('读取 config_default.yaml 失败', err) - return false + fs.writeFileSync(filePath, YAML.stringify(data)); + return true; + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`写入 ${filePath} 失败:\n${error}`)); + return false; + } + } + + watchFiles() { + Object.entries(this.fileMaps).forEach(([key, filePath]) => { + fs.watchFile(filePath, () => { + this.cache[key] = this.loadYAML(filePath); + }); + }); + } + + getConfig() { + if (!this.cache.config) { + this.cache.config = this.loadYAML(this.fileMaps.config); + } + return this.cache.config; + } + + getDefConfig() { + if (!this.cache.config_default) { + this.cache.config_default = this.loadYAML(this.fileMaps.config_default); } + return this.cache.config_default; } setConfig(config_data) { - try { - fs.writeFileSync( - `${pluginRoot}/config/config/config.yaml`, - YAML.stringify(config_data), - ) - return true - } catch (err) { - logger.warn('写入 config.yaml 失败', err) - return false + if (this.saveConfig(this.fileMaps.config, config_data)) { + this.cache.config = config_data; + return true; } + return false; } - getUserConfig(userId) { - const userConfigPath = `${_path}/data/waves/${userId}.yaml`; + getUserConfig() { + if (!this.cache.user) { + this.cache.user = this.loadYAML(this.fileMaps.user); + } + return this.cache.user; + } - try { - if (fs.existsSync(userConfigPath)) { - const configFileContent = fs.readFileSync(userConfigPath, 'utf-8'); - return YAML.parse(configFileContent); - } + getDefUserConfig() { + if (!this.cache.user_default) { + this.cache.user_default = this.loadYAML(this.fileMaps.user_default); + } + return this.cache.user_default; + } - return []; + setUserConfig(user_data) { + return this.saveConfig(this.fileMaps.user, user_data); + } + + getUserData(userId) { + const userConfigData = `${_path}/data/waves/${userId}.yaml`; + try { + return fs.existsSync(userConfigData) ? this.loadYAML(userConfigData) : []; } catch (error) { - logger.warn(`读取用户配置 ${userId}.yaml 失败`, error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`读取用户配置 ${userId}.yaml 失败:\n${error}`)); return []; } } - setUserConfig(userId, userData) { - const userConfigPath = `${_path}/data/waves/${userId}.yaml`; - + setUserData(userId, userData) { + const userConfigData = `${_path}/data/waves/${userId}.yaml`; try { - if (userData.length === 0) { - fs.existsSync(userConfigPath) && fs.unlinkSync(userConfigPath); + if (!userData.length) { + if (fs.existsSync(userConfigData)) fs.unlinkSync(userConfigData); redis.del(`Yunzai:waves:users:${userId}`); return true; } - const yamlData = YAML.stringify(userData); - fs.writeFileSync(userConfigPath, yamlData); + this.saveConfig(userConfigData, userData); redis.set(`Yunzai:waves:users:${userId}`, JSON.stringify(userData)); - return true; } catch (error) { - logger.warn(`写入用户配置 ${userId}.yaml 失败`, error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`写入用户配置 ${userId}.yaml 失败:\n${error}`)); return false; } } } -export default new Config() +export default new Config(); \ No newline at end of file diff --git a/components/Kuro.js b/components/Kuro.js index 2dded87..a4cb181 100644 --- a/components/Kuro.js +++ b/components/Kuro.js @@ -32,16 +32,16 @@ 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.info('获取可用性成功:账号已过期'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.yellow(`获取可用性成功:账号已过期`)); return false; } else { if (Config.getConfig().enable_log) { - logger.info('获取可用性成功:账号可用'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取可用性成功:账号可用`)); } return true; } } catch (error) { - logger.error('获取可用性失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取可用性失败,疑似网络问题:\n${error}`)); return strict ? false : true; } } @@ -58,15 +58,15 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区用户签到成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区用户签到成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('库街区用户签到失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区用户签到失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('库街区用户签到失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区用户签到失败,疑似网络问题:\n${error}`)); return { status: false, msg: '库街区用户签到失败,疑似网络问题,请检查控制台日志' }; } } @@ -86,15 +86,15 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区点赞成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区点赞成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('库街区点赞失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区点赞失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('库街区点赞失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区点赞失败,疑似网络问题:\n${error}`)); return { status: false, msg: '库街区点赞失败,疑似网络问题,请检查控制台日志' }; } } @@ -110,15 +110,15 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区分享成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区分享成功`)); } return { status: true, data: response.data.msg }; } else { - logger.error('库街区分享失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区分享失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('库街区分享失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区分享失败,疑似网络问题:\n${error}`)); return { status: false, msg: '库街区分享失败,疑似网络问题,请检查控制台日志' }; } } @@ -134,15 +134,15 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区浏览帖子成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区浏览帖子成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('库街区浏览帖子失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区浏览帖子失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('库街区浏览帖子失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区浏览帖子失败,疑似网络问题:\n${error}`)); return { status: false, msg: '库街区浏览帖子失败,疑似网络问题,请检查控制台日志' }; } } @@ -159,14 +159,14 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区获取帖子成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区获取帖子成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('库街区获取帖子失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取帖子失败:${response.data.msg}`)); } } catch (error) { - logger.error('库街区获取帖子失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取帖子失败,疑似网络问题:\n${error}`)); } } @@ -181,15 +181,15 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区获取任务进度成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区获取任务进度成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('库街区获取任务进度失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取任务进度失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('库街区获取任务进度失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取任务进度失败,疑似网络问题:\n${error}`)); return { status: false, msg: '库街区获取任务进度失败,疑似网络问题,请检查控制台日志' }; } } @@ -202,15 +202,15 @@ class Kuro { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info('库街区获取库洛币总数成功'); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`库街区获取库洛币总数成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('库街区获取库洛币总数失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取库洛币总数失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('库街区获取库洛币总数失败,疑似网络问题:\n', error); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`库街区获取库洛币总数失败,疑似网络问题:\n${error}`)); return { status: false, msg: '库街区获取库洛币总数失败,疑似网络问题,请检查控制台日志' }; } } diff --git a/components/Render.js b/components/Render.js index 75e7888..bc8f619 100644 --- a/components/Render.js +++ b/components/Render.js @@ -28,7 +28,7 @@ const Render = { async render(path, params, cfg) { let { e } = cfg if (!e.runtime) { - logger.error('未找到e.runtime,请升级至最新版Yunzai') + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`未找到e.runtime,请升级至最新版Yunzai`)); } let BotName = Version.isMiao ? 'Miao-Yunzai' : Version.isTrss ? 'TRSS-Yunzai' : 'Yunzai-Bot' @@ -39,8 +39,8 @@ const Render = { if (package_json.version) { currentVersion = package_json.version } - } catch (err) { - logger.error('读取package.json失败', err) + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`读取 package.json 失败:\n${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 b9d076b..9a218ec 100644 --- a/components/Server.js +++ b/components/Server.js @@ -6,25 +6,21 @@ import fs from 'fs/promises'; class Server { constructor() { + this.app = express(); this.data = {}; + this.server = null; this.init(); } async init() { - const app = express(); - app.use(express.json()); - const port = await Config.getConfig().server_port; + this.app.use(express.json()); + await this.checkServer(); - if (!Config.getConfig().allow_login) return; - app.listen(port, () => { - logger.mark( - logger.blue('[Waves PLUGIN]') + - ' 登录服务端点:' + - logger.green(`http://localhost:${port}`) - ); - }); + setInterval(() => { + this.checkServer(); + }, 5000); - app.get('/login/:id', async (req, res) => { + this.app.get('/login/:id', async (req, res) => { const id = req.params.id; const filePath = this.data[id] ? '/server/login.html' : '/server/error.html'; @@ -36,13 +32,13 @@ class Server { } data = data.replace(/background_image/g, await Config.getConfig().background_api); res.send(data); - } catch (err) { - logger.error(err); + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`发送登录页失败:\n${error}}`)); res.status(500).send('Internal Server Error'); } }); - app.post('/code/:id', async (req, res) => { + this.app.post('/code/:id', async (req, res) => { const id = req.params.id; const { mobile, code } = req.body; @@ -55,12 +51,34 @@ class Server { if (!data.status) return res.status(200).json({ code: 400, msg: data.msg }); this.data[id].token = data.data.token; return res.status(200).json({ code: 200, msg: 'Login successful' }); - }) + }); - app.use((req, res) => { + this.app.use((req, res) => { res.redirect('https://github.com/erzaozi/waves-plugin'); }); } + + async checkServer() { + const allowLogin = Config.getConfig().allow_login; + + 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}`)); + }); + } + + if (!allowLogin && this.server) { + this.server.close((error) => { + if (error) { + logger.mark(logger.blue('[Waves PLUGIN]'), logger.white(`无法关闭登录服务器`), logger.red(error)); + } else { + logger.mark(logger.blue('[Waves PLUGIN]'), logger.white(`已关闭登录服务器`)); + } + }); + this.server = null; + } + } } export default new Server(); \ No newline at end of file diff --git a/components/Wiki.js b/components/Wiki.js index d643626..07d00a2 100644 --- a/components/Wiki.js +++ b/components/Wiki.js @@ -50,12 +50,12 @@ class Wiki { if (response.data.code === 200) { return { status: true, data: response.data.data }; } else { - logger.error('获取Wiki列表失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 列表失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取Wiki列表失败,疑似网络问题:\n', error); - return { status: false, msg: '获取Wiki列表失败,疑似网络问题,请检查控制台日志' }; + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取Wiki列表失败,疑似网络问题:\n${error}`)); + return { status: false, msg: '获取 Wiki 列表失败,疑似网络问题,请检查控制台日志' }; } } @@ -77,7 +77,7 @@ class Wiki { for (const [i, response] of responses.entries()) { const catalogueId = Object.keys(CONSTANTS.CATALOGUEID_MAP)[i]; - + if (response.status) { const record = response.data.results.records.find(record => record.name === name); if (record) { @@ -85,7 +85,7 @@ class Wiki { } } } - + return { status: false, msg: '未找到该词条的Wiki信息' }; } } @@ -118,16 +118,16 @@ class Wiki { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info(`获取Wiki详情成功`); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取 Wiki 详情成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取Wiki详情失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 详情失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取Wiki详情失败,疑似网络问题:\n', error); - return { status: false, msg: '获取Wiki详情失败,疑似网络问题,请检查控制台日志' }; + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 详情失败,疑似网络问题:\n${error}`)); + return { status: false, msg: '获取 Wiki 详情失败,疑似网络问题,请检查控制台日志' }; } } @@ -169,16 +169,16 @@ class Wiki { return { status: false, msg: '未找到该词条的Wiki信息' }; } if (Config.getConfig().enable_log) { - logger.info(`搜索Wiki成功`); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`搜索 Wiki 成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('搜索Wiki失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`搜索 Wiki 失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('搜索Wiki失败,疑似网络问题:\n', error); - return { status: false, msg: '搜索Wiki失败,疑似网络问题,请检查控制台日志' }; + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`搜索 Wiki 失败,疑似网络问题:\n${error}`)); + return { status: false, msg: '搜索 Wiki 失败,疑似网络问题,请检查控制台日志' }; } } @@ -204,16 +204,16 @@ class Wiki { if (response.data.code === 200) { if (Config.getConfig().enable_log) { - logger.info(`获取Wiki首页成功`); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.green(`获取 Wiki 首页成功`)); } return { status: true, data: response.data.data }; } else { - logger.error('获取Wiki首页失败:', response.data.msg); + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 首页失败:${response.data.msg}`)); return { status: false, msg: response.data.msg }; } } catch (error) { - logger.error('获取Wiki首页失败,疑似网络问题:\n', error); - return { status: false, msg: '获取Wiki首页失败,疑似网络问题,请检查控制台日志' }; + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`获取 Wiki 首页失败,疑似网络问题:\n${error}`)); + return { status: false, msg: '获取 Wiki 首页失败,疑似网络问题,请检查控制台日志' }; } } } diff --git a/config/config_default.yaml b/config/config_default.yaml index 7bf8ac3..3ce508e 100644 --- a/config/config_default.yaml +++ b/config/config_default.yaml @@ -19,6 +19,8 @@ allow_import: false enable_log: false # 图片渲染精度 render_scale: 100 +# 接口并发量 +limit: 10 # ---------- 登录服务器配置 ---------- # 允许在线登录 @@ -42,14 +44,4 @@ allow_img_delete: false # ---------- 别名相关 ---------- # 是否允许普通用户设置别名 -allow_set_alias: false - -# ---------- 定时任务列表 ---------- -# 自动签到列表 -waves_auto_signin_list: [] -# 自动任务列表 -waves_auto_task_list: [] -# 体力推送列表 -waves_auto_push_list: [] -# 公告推送列表 -waves_auto_news_list: [] \ No newline at end of file +allow_set_alias: false \ No newline at end of file diff --git a/config/user_default.yaml b/config/user_default.yaml new file mode 100644 index 0000000..6d202ab --- /dev/null +++ b/config/user_default.yaml @@ -0,0 +1,9 @@ +# ---------- 定时任务列表 ---------- +# 自动签到列表 +waves_auto_signin_list: [] +# 自动任务列表 +waves_auto_task_list: [] +# 体力推送列表 +waves_auto_push_list: [] +# 公告推送列表 +waves_auto_news_list: [] \ No newline at end of file diff --git a/guoba.support.js b/guoba.support.js index 7106550..8d374e9 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -34,7 +34,7 @@ export function supportGuoba() { }, }, { - field: "waves_auto_signin_list", + field: "user_config.waves_auto_signin_list", label: "自动签到配置", bottomHelpMessage: "自动签到列表", component: "GSubForm", @@ -72,7 +72,7 @@ export function supportGuoba() { }, }, { - field: 'signin_time', + field: 'config.signin_time', label: '定时表达式配置', bottomHelpMessage: '定时签到', component: 'EasyCron', @@ -81,7 +81,7 @@ export function supportGuoba() { }, }, { - field: "waves_auto_task_list", + field: "user_config.waves_auto_task_list", label: "自动任务配置", bottomHelpMessage: "自动任务列表", component: "GSubForm", @@ -119,7 +119,7 @@ export function supportGuoba() { }, }, { - field: 'task_time', + field: 'config.task_time', label: '定时表达式配置', bottomHelpMessage: '定时任务', component: 'EasyCron', @@ -128,7 +128,7 @@ export function supportGuoba() { }, }, { - field: "waves_auto_push_list", + field: "user_config.waves_auto_push_list", label: "体力推送配置", bottomHelpMessage: "体力推送列表", component: "GSubForm", @@ -166,7 +166,7 @@ export function supportGuoba() { }, }, { - field: 'sanity_push_time', + field: 'config.sanity_push_time', label: '定时表达式配置', bottomHelpMessage: '体力检查频率', component: 'EasyCron', @@ -175,7 +175,7 @@ export function supportGuoba() { }, }, { - field: "waves_auto_news_lists", + field: "user_config.waves_auto_news_lists", label: "公告推送配置", bottomHelpMessage: "公告推送列表", component: "GSubForm", @@ -210,7 +210,7 @@ export function supportGuoba() { }, }, { - field: 'news_push_time', + field: 'config.news_push_time', label: '定时表达式配置', bottomHelpMessage: '公告检查频率', component: 'EasyCron', @@ -227,13 +227,13 @@ export function supportGuoba() { }, }, { - field: "allow_login", + field: "config.allow_login", label: "允许网页登录", bottomHelpMessage: "是否允许网页登录", component: "Switch", }, { - field: "server_port", + field: "config.server_port", label: "开放端口", bottomHelpMessage: "登录HTTP服务器开放端口", component: "InputNumber", @@ -246,7 +246,7 @@ export function supportGuoba() { }, }, { - field: "public_link", + field: "config.public_link", label: "登录服务公开地址", bottomHelpMessage: "展示给用户的自定义登录地址", component: "Input", @@ -256,7 +256,7 @@ export function supportGuoba() { }, }, { - field: "background_api", + field: "config.background_api", label: "登录页背景图", bottomHelpMessage: "背景图API地址", component: "Input", @@ -274,25 +274,25 @@ export function supportGuoba() { }, }, { - field: "allow_img_upload", + field: "config.allow_img_upload", label: "上传面板图", bottomHelpMessage: "是否允许普通用户上传面板图", component: "Switch", }, { - field: "allow_get_origin", + field: "config.allow_get_origin", label: "获取原图", bottomHelpMessage: "是否允许普通用户获取原图", component: "Switch", }, { - field: "allow_get_list", + field: "config.allow_get_list", label: "获取面板图列表", bottomHelpMessage: "是否允许普通用户获取面板图列表", component: "Switch", }, { - field: "allow_img_delete", + field: "config.allow_img_delete", label: "删除面板图", bottomHelpMessage: "是否允许普通用户删除面板图", component: "Switch", @@ -306,7 +306,7 @@ export function supportGuoba() { }, }, { - field: "allow_set_alias", + field: "config.allow_set_alias", label: "设置别名", bottomHelpMessage: "是否允许普通用户设置别名", component: "Switch", @@ -320,13 +320,13 @@ export function supportGuoba() { }, }, { - field: "use_public_cookie", + field: "config.use_public_cookie", label: "使用公共Token", bottomHelpMessage: "允许未登录用户使用登录用户的Token进行查询", component: "Switch", }, { - field: "strategy_provide", + field: "config.strategy_provide", label: "攻略图提供方", bottomHelpMessage: "选择角色攻略图提供方", component: "Select", @@ -340,13 +340,13 @@ export function supportGuoba() { }, }, { - field: "allow_import", + field: "config.allow_import", label: "允许导入抽卡记录", bottomHelpMessage: "无法验证导入数据真实性,可能存在虚假数据覆盖真实数据情况,请谨慎开启", component: "Switch", }, { - field: "signin_interval", + field: "config.signin_interval", label: "签到间隔时间", bottomHelpMessage: "单位:秒,请勿设置过短,风险自负", component: "InputNumber", @@ -357,7 +357,7 @@ export function supportGuoba() { }, }, { - field: "task_interval", + field: "config.task_interval", label: "任务间隔时间", bottomHelpMessage: "单位:秒,请勿设置过短,风险自负", component: "InputNumber", @@ -368,13 +368,13 @@ export function supportGuoba() { }, }, { - field: "enable_log", + field: "config.enable_log", label: "输出成功日志", bottomHelpMessage: "输出成功日志,用于调试和向开发者反馈问题", component: "Switch", }, { - field: "render_scale", + field: "config.render_scale", label: "图片渲染精度", bottomHelpMessage: "图片渲染精度,建议 50-200 ,默认 100", component: "InputNumber", @@ -386,38 +386,53 @@ export function supportGuoba() { step: 1 }, }, + { + field: "config.limit", + label: "接口并发量", + bottomHelpMessage: "过大的并发将会请求阻塞", + component: "InputNumber", + required: true, + componentProps: { + placeholder: '请输入并发量', + step: 1, + }, + }, ], getConfigData() { let config = Config.getConfig() - config["waves_auto_news_lists"] = []; - config["waves_auto_news_list"].forEach(user => { + let user_config = Config.getUserConfig() + user_config["waves_auto_news_lists"] = []; + user_config["waves_auto_news_list"].forEach(user => { const { botId, groupId, userId } = user; let isGroup = !!groupId; if (isGroup) { - config["waves_auto_news_lists"].push({ botId, isGroup, pushId: groupId }); + user_config["waves_auto_news_lists"].push({ botId, isGroup, pushId: groupId }); } else { - config["waves_auto_news_lists"].push({ botId, isGroup, pushId: userId }); + user_config["waves_auto_news_lists"].push({ botId, isGroup, pushId: userId }); } }) - return config + return { config, user_config } }, setConfigData(data, { Result }) { - let config = {}; + let last = {}; for (let [keyPath, value] of Object.entries(data)) { - lodash.set(config, keyPath, value); + lodash.set(last, keyPath, value); } - config = lodash.merge({}, Config.getConfig(), config); + + let config = lodash.merge({}, Config.getConfig(), last.config); + let user_config = lodash.merge({}, Config.getUserConfig(), last.user_config); config.public_link = config.public_link.replace(/\/$/, ''); - config["waves_auto_news_list"] = []; - config["waves_auto_news_lists"].forEach(({ botId, isGroup, pushId }) => { - config["waves_auto_news_list"].push({ botId, groupId: isGroup ? pushId : "", userId: !isGroup ? pushId : "" }); + user_config["waves_auto_news_list"] = []; + user_config["waves_auto_news_lists"].forEach(({ botId, isGroup, pushId }) => { + user_config["waves_auto_news_list"].push({ botId, groupId: isGroup ? pushId : "", userId: !isGroup ? pushId : "" }); }); - delete config["waves_auto_news_lists"]; + delete user_config["waves_auto_news_lists"]; Config.setConfig(config) + Config.setUserConfig(user_config) return Result.ok({}, '保存成功~') }, }, diff --git a/model/init.js b/model/init.js index 13113a4..10275ff 100644 --- a/model/init.js +++ b/model/init.js @@ -5,12 +5,10 @@ import YAML from "yaml"; class Init { constructor() { - this.initConfig() this.compatible() + this.initConfig() this.syncConfig().then(syncCount => { - logger.mark( - logger.blue('[Waves PLUGIN]') + ' 同步了 ' + logger.green(syncCount) + ' 个用户信息' - ) + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.white(`同步了`), logger.green(syncCount), logger.white(`个用户信息`)); }); } @@ -30,13 +28,13 @@ class Init { // 检查默认配置文件 const config_default_path = `${pluginRoot}/config/config_default.yaml` if (!fs.existsSync(config_default_path)) { - logger.error('默认设置文件不存在,请检查或重新安装插件') + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`默认设置文件不存在,请检查或重新安装插件`)); return true } // 检查配置文件 const config_path = `${pluginRoot}/config/config/config.yaml` if (!fs.existsSync(config_path)) { - logger.error('设置文件不存在,将使用默认设置文件') + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`设置文件不存在,将使用默认设置文件`)); fs.copyFileSync(config_default_path, config_path) } // 同步配置文件 @@ -53,52 +51,46 @@ class Init { } } Config.setConfig(config_yaml) + // 检查默认用户配置文件 + const user_default_path = `${pluginRoot}/config/user_default.yaml` + if (!fs.existsSync(config_default_path)) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`默认用户配置文件不存在,请检查或重新安装插件`)); + return true + } + // 检查用户配置文件 + const user_path = `${pluginRoot}/config/config/user.yaml` + if (!fs.existsSync(user_path)) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`用户配置文件不存在,将使用默认用户配置文件`)); + fs.copyFileSync(user_default_path, user_path) + } + // 同步用户配置文件 + const user_default_yaml = Config.getDefUserConfig() + const user_yaml = Config.getUserConfig() + for (const key in user_default_yaml) { + if (!(key in user_yaml)) { + user_yaml[key] = user_default_yaml[key] + } + } + for (const key in user_yaml) { + if (!(key in user_default_yaml)) { + delete user_yaml[key] + } + } + Config.setUserConfig(user_yaml) } async compatible() { - // 1.4.6 -> 1.4.7 更改签到/体力/推送配置文件存储格式 - let config = await Config.getConfig(); - - config.waves_auto_signin_list = config.waves_auto_signin_list.map(user => - typeof user === 'string' - ? (() => { - const [botId, groupId, userId] = user.split(':'); - return { - botId: botId === 'undefined' ? '' : botId, - groupId: groupId === 'undefined' ? '' : groupId, - userId: userId === 'undefined' ? '' : userId - }; - })() - : user - ); + // 1.5.13 -> 1.5.14 分离配置文件与用户配置文件 + const config = Config.getConfig() || {}; + const keys = ['waves_auto_signin_list', 'waves_auto_task_list', 'waves_auto_push_list', 'waves_auto_news_list']; - config.waves_auto_push_list = config.waves_auto_push_list.map(user => - typeof user === 'string' - ? (() => { - const [botId, groupId, userId] = user.split(':'); - return { - botId: botId === 'undefined' ? '' : botId, - groupId: groupId === 'undefined' ? '' : groupId, - userId: userId === 'undefined' ? '' : userId - }; - })() - : user - ); + const lists = Object.fromEntries(keys.map(k => [k, config[k]]).filter(([, v]) => v)); - config.waves_auto_news_list = config.waves_auto_news_list.map(user => - typeof user === 'string' - ? (() => { - const [botId, groupId, userId] = user.split(':'); - return { - botId: botId === 'undefined' ? '' : botId, - groupId: groupId === 'undefined' ? '' : groupId, - userId: userId === 'undefined' ? '' : userId - }; - })() - : user - ); + if (Object.keys(lists).length < keys.length) return true; + keys.forEach(k => delete config[k]); Config.setConfig(config); + Config.setUserConfig(lists); } async syncConfig() { @@ -112,8 +104,8 @@ class Init { let userInfo = YAML.parse(await fs.promises.readFile(`${_path}/data/waves/${fileName}`, 'utf-8')); await redis.set(`Yunzai:waves:users:${fileName.split('.')[0]}`, JSON.stringify(userInfo)); successCount++; - } catch (err) { - logger.error(`[Waves-Plugin] 同步用户信息失败:${err}`) + } catch (error) { + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`同步用户信息失败:\n${error}`)); } } diff --git a/package.json b/package.json index 1e01d30..efae83d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "waves-plugin", - "version": "1.5.13", + "version": "1.5.14", "description": "基于 Yunzai 的鸣潮游戏数据查询插件", "main": "index.js", "scripts": { @@ -9,8 +9,9 @@ "type": "module", "module": "index.js", "dependencies": { - "axios": "^1.7.2", - "qs": "^6.12.1", + "axios": "^1.7.8", + "p-limit": "^6.1.0", + "qs": "^6.13.1", "sharp": "^0.33.5" }, "keywords": [ diff --git a/utils/Calculate.js b/utils/Calculate.js index a421545..10a6dc9 100644 --- a/utils/Calculate.js +++ b/utils/Calculate.js @@ -150,7 +150,7 @@ class WeightCalculator { baseWeight.mainProps[COST].find(item => item.name === name).max * roleWeight.mainProps[COST].find(item => item.name === name).theoreticalValue; } catch (error) { - logger.error(`[Waves-Plugin] 疑似该声骸属性异常:${JSON.stringify(phantom)}`) + logger.mark(logger.blue('[WAVES PLUGIN]'), logger.red(`疑似该声骸属性异常:${JSON.stringify(phantom)}`)); } }); }; diff --git a/utils/logs.js b/utils/logs.js deleted file mode 100644 index adf0f30..0000000 --- a/utils/logs.js +++ /dev/null @@ -1,46 +0,0 @@ -import fs from 'fs' -import { pluginRoot } from '../model/path.js' -let currentVersion -const package_path = `${pluginRoot}/package.json` -try { - const package_json = JSON.parse(fs.readFileSync(package_path, 'utf-8')) - if (package_json.version) { - currentVersion = package_json.version - } -} catch (err) { - logger.error('读取package.json失败', err) -} - -/** 快捷logger:i-info m-mark w-warn e-error - */ -class Log { - constructor () { - this.header = `【Waves-Plugin v${currentVersion}】` - } - - /** 快捷执行logger.info( ) */ - i (...msg) { - logger.info(this.header, ...msg) - } - - /** 快捷执行logger.mark( ) */ - m (...msg) { - logger.mark(this.header, ...msg) - } - - /** 快捷执行logger.warn( ) */ - w (...msg) { - logger.warn(this.header, ...msg) - } - - /** 快捷执行logger.error( ) */ - e (...msg) { - logger.error(this.header, ...msg) - } - - /** 快捷执行console.log( ) */ - c (...msg) { - console.log(this.header, ...msg) - } -} -export default new Log()