From 167cab0f1d3a841131717f4910ae1445d467ad39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=8F=B6?= <1936472877@qq.com> Date: Sat, 28 Dec 2024 10:01:33 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/index.js | 8 ++++---- apps/info.js | 4 ++++ components/App.js | 2 +- lib/logger.js | 4 ++-- models/api/ISteamUser.js | 1 + models/task/index.js | 16 ++++++++-------- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/apps/index.js b/apps/index.js index 171fe3d..8e03201 100644 --- a/apps/index.js +++ b/apps/index.js @@ -25,12 +25,12 @@ for (const i of files) { // } apps[id] = exp.app } catch (error) { - logger.error(`[${Version.pluginName}]加载js: apps/${i}错误\n`, error) + logger.error('error', `[${Version.pluginName}]加载js: apps/${i}错误\n`, error) } } export { apps } -logger.log('-----------------') -logger.log(`${Version.pluginName} v${Version.pluginVersion} 加载成功~ 耗时: ${Date.now() - startTime}ms`) -logger.log('-------^_^-------') +logger.log('info', '-----------------') +logger.log('info', `${Version.pluginName} v${Version.pluginVersion} 加载成功~ 耗时: ${Date.now() - startTime}ms`) +logger.log('info', '-------^_^-------') diff --git a/apps/info.js b/apps/info.js index c9f47a9..fa615ce 100644 --- a/apps/info.js +++ b/apps/info.js @@ -30,6 +30,10 @@ const rule = { return true } const info = data.pop() + if (info.communityvisibilitystate !== 3) { + await e.reply([segment.at(uid), `\n${info.personaname}个人资料未公开`]) + return true + } if (Config.other.infoMode == 2) { const color = info.gameid ? 1 : info.personastate === 0 ? 3 : 2 const bg = await api.IPlayerService.GetProfileItemsEquipped(steamId) diff --git a/components/App.js b/components/App.js index 73244fc..93684cd 100644 --- a/components/App.js +++ b/components/App.js @@ -94,7 +94,7 @@ export default class App { App.reply(e, Config.tips.loadingTips, { recallMsg: 5, at: true }) } const res = await fnc(e).catch(error => { - logger.error(error) + logger.error(error.message) let message = error.message const keyMap = [ { key: 'apiProxy', title: 'api反代' }, diff --git a/lib/logger.js b/lib/logger.js index 146ff22..c795db6 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -17,7 +17,7 @@ const getRandomHexColor = () => { export default { ...logger, - log: (...logs) => logger.info(chalk.hex(getRandomHexColor())(`[${Version.pluginName}]`, ...logs)), + log: (level, ...logs) => logger[level](chalk.hex(getRandomHexColor())(`[${Version.pluginName}]`, ...logs)), info: (...logs) => logger[Config.other.log ? 'info' : 'debug'](chalk.hex(getRandomHexColor())(`[${Version.pluginName}]`, ...logs)), - error: (...logs) => logger.error(`[${Version.pluginName}]`, ...logs) + error: (...logs) => Config.other.log && logger.error(`[${Version.pluginName}]`, ...logs) } diff --git a/models/api/ISteamUser.js b/models/api/ISteamUser.js index 84697d1..aa8cc15 100644 --- a/models/api/ISteamUser.js +++ b/models/api/ISteamUser.js @@ -6,6 +6,7 @@ import { utils } from '#models' * @param {string|string[]} steamIds * @returns {Promise<{ * steamid: string, + * communityvisibilitystate: number, * profilestate: number, * personaname: string, * profileurl: string, diff --git a/models/task/index.js b/models/task/index.js index 72e164b..ca5dacb 100644 --- a/models/task/index.js +++ b/models/task/index.js @@ -78,8 +78,8 @@ export function startTimer () { desc: lastPlay.playTime ? `距离上次 ${utils.formatDuration(time)}` : '', image: iconUrl }) - db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, player.gameid, player.gameextrainfo, 'playTotal', 1).catch(e => logger.error('更新统计数据失败', e)) - db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, now, null, player.gameid, player.gameextrainfo).catch(e => logger.error('添加历史记录失败', e)) + db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, player.gameid, player.gameextrainfo, 'playTotal', 1).catch(e => logger.error('更新统计数据失败', e.message)) + db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, now, null, player.gameid, player.gameextrainfo).catch(e => logger.error('添加历史记录失败', e.message)) } if (Config.push.enable && lastPlay.name && lastPlay.name != player.gameextrainfo) { const time = now - lastPlay.playTime @@ -90,8 +90,8 @@ export function startTimer () { desc: `时长: ${utils.formatDuration(time)}`, image: utils.steam.getHeaderImgUrlByAppid(lastPlay.appid) }) - db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, lastPlay.appid, lastPlay.name, 'playTime', time).catch(e => logger.error('更新统计数据失败', e)) - db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, lastPlay.playTime, now, lastPlay.appid, lastPlay.name).catch(e => logger.error('添加历史记录失败', e)) + db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, lastPlay.appid, lastPlay.name, 'playTime', time).catch(e => logger.error('更新统计数据失败', e.message)) + db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, lastPlay.playTime, now, lastPlay.appid, lastPlay.name).catch(e => logger.error('添加历史记录失败', e.message)) } // 在线状态改变 if (Config.push.stateChange && player.personastate != lastPlay.state) { @@ -107,11 +107,11 @@ export function startTimer () { descStyle: `style="background-color: #${getColor(player.personastate)};color: white;width: fit-content;border-radius: 5px; padding: 0 5px;"` }) if (player.personastate === 0) { - db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, player.gameid, player.gameextrainfo, 'onlineTime', time).catch(e => logger.error('更新统计数据失败', e)) - db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, lastPlay.onlineTime, now).catch(e => logger.error('添加历史记录失败', e)) + db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, player.gameid, player.gameextrainfo, 'onlineTime', time).catch(e => logger.error('更新统计数据失败', e.message)) + db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, lastPlay.onlineTime, now).catch(e => logger.error('添加历史记录失败', e.message)) } else { db.StatsTableUpdate(i.userId, i.groupId, i.botId, i.steamId, player.gameid, player.gameextrainfo, 'onlineTotal', 1).catch(e => logger.error('更新统计数据失败', e)) - db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, now).catch(e => logger.error('添加历史记录失败', e)) + db.HistoryAdd(i.userId, i.groupId, i.botId, i.steamId, now).catch(e => logger.error('添加历史记录失败', e.message)) } } else { state.state = player.personastate === 0 ? 0 : 1 @@ -172,7 +172,7 @@ export function startTimer () { } } } catch (error) { - logger.error('检查Steam游戏信息出现错误', error) + logger.error('检查Steam游戏信息出现错误', error.message) } }, 1000 * 60 * Config.push.time) }