Skip to content

Commit

Permalink
perf: 优化错误日志
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Dec 28, 2024
1 parent 921cd3f commit 167cab0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
8 changes: 4 additions & 4 deletions apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '-------^_^-------')
4 changes: 4 additions & 0 deletions apps/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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反代' },
Expand Down
4 changes: 2 additions & 2 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions models/api/ISteamUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { utils } from '#models'
* @param {string|string[]} steamIds
* @returns {Promise<{
* steamid: string,
* communityvisibilitystate: number,
* profilestate: number,
* personaname: string,
* profileurl: string,
Expand Down
16 changes: 8 additions & 8 deletions models/task/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -172,7 +172,7 @@ export function startTimer () {
}
}
} catch (error) {
logger.error('检查Steam游戏信息出现错误', error)
logger.error('检查Steam游戏信息出现错误', error.message)
}
}, 1000 * 60 * Config.push.time)
}
Expand Down

0 comments on commit 167cab0

Please sign in to comment.