✨ 细节优化
This commit is contained in:
@@ -46,12 +46,6 @@ export default async function getBotState(e) {
|
||||
|
||||
return Promise.all(dataPromises)
|
||||
}
|
||||
// function extractVersion(versionString) {
|
||||
// const regex = /\d+\.\d+\.\d+/
|
||||
// const match = versionString.match(regex)
|
||||
// const version = match ? match[0] : versionString
|
||||
// return version
|
||||
// }
|
||||
|
||||
async function getAvatarColor(url) {
|
||||
const defaultAvatar = `${Plugin_Path}/resources/state/img/default_avatar.jpg`
|
||||
@@ -71,13 +65,23 @@ async function getAvatarColor(url) {
|
||||
}
|
||||
async function getMessageCount(bot) {
|
||||
const nowDate = moment().format("MMDD")
|
||||
const sent = await redis.get(`Yz:count:send:msg:bot:${bot.uin}:total`) || bot.stat?.sent_msg_cnt
|
||||
const recv = await redis.get(`Yz:count:receive:msg:bot:${bot.uin}:total`) || bot.stat?.recv_msg_cnt
|
||||
const screenshot = await redis.get(`Yz:count:send:image:bot:${bot.uin}:total`) || await redis.get(`Yz:count:screenshot:day:${nowDate}`)
|
||||
const keys = [
|
||||
`Yz:count:send:msg:bot:${bot.uin}:total`,
|
||||
`Yz:count:receive:msg:bot:${bot.uin}:total`,
|
||||
`Yz:count:send:image:bot:${bot.uin}:total`,
|
||||
`Yz:count:screenshot:day:${nowDate}`
|
||||
]
|
||||
|
||||
const values = await redis.mGet(keys) || []
|
||||
|
||||
const sent = values[0] || bot.stat?.sent_msg_cnt || 0
|
||||
const recv = values[1] || bot.stat?.recv_msg_cnt || 0
|
||||
const screenshot = values[2] || values[3] || 0
|
||||
|
||||
return {
|
||||
sent: sent || 0,
|
||||
recv: recv || 0,
|
||||
screenshot: screenshot || 0
|
||||
sent,
|
||||
recv,
|
||||
screenshot
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,23 +44,30 @@ export function getNetworkTestList(e) {
|
||||
}))
|
||||
}
|
||||
|
||||
// 封装处理每个测试站点逻辑到一个单独的函数
|
||||
const handleSite = (site) => {
|
||||
return getNetworkLatency(site.url, site.timeout, site.useProxy)
|
||||
.then(res => ({ first: site.name, tail: res }))
|
||||
.catch(error => {
|
||||
let errorMsg = "error"
|
||||
if (error.name === "AbortError") {
|
||||
errorMsg = "timeout"
|
||||
}
|
||||
if (error.message.includes("ECONNRESET")) {
|
||||
logger.error(`[Yenai-Plugin][状态]请求 ${site.name} 发生了 ECONNRESET 错误:`, error.message)
|
||||
errorMsg = "econnreset"
|
||||
}
|
||||
logger.error(`[Yenai-Plugin][状态]请求 ${site.name} 过程中发生错误:`, error.message)
|
||||
return { first: site.name, tail: `<span style='color:#F44336'>${errorMsg}</span>` }
|
||||
const errorMsg = handleError(error, site.name)
|
||||
const errorSpan = `<span style='color:#F44336'>${errorMsg}</span>`
|
||||
return { first: site.name, tail: errorSpan }
|
||||
})
|
||||
}
|
||||
|
||||
const handleError = (error, siteName) => {
|
||||
let errorMsg = "error"
|
||||
const prefix = "[Yenai-Plugin][状态]"
|
||||
if (error.name === "AbortError") {
|
||||
logger.warn(`${prefix}请求 ${siteName} 超时`)
|
||||
errorMsg = "timeout"
|
||||
} else if (error.message.includes("ECONNRESET")) {
|
||||
logger.warn(`${prefix}请求 ${siteName} 发生了 ECONNRESET 错误:`, error.message)
|
||||
errorMsg = "econnreset"
|
||||
} else {
|
||||
logger.error(`${prefix}请求 ${siteName} 过程中发生错误:`, error.message)
|
||||
}
|
||||
return errorMsg
|
||||
}
|
||||
/**
|
||||
* 解析配置参数并返回配置对象。
|
||||
* @param {Array | string | boolean} psTestSites - 预期应该是对象包含show,list,timeout
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function getBackground() {
|
||||
const buffBase64 = arrayBufferToBase64(buffer)
|
||||
return `data:image/jpeg;base64,${buffBase64}`
|
||||
} catch (err) {
|
||||
logger.error(`[Yenai-Plugin][状态]背景图请求失败,使用默认背景图“${backdropDefault}”,错误原因: ${err.message}`)
|
||||
logger.warn(`[Yenai-Plugin][状态]背景图请求失败,使用默认背景图 “${backdropDefault}” ,错误原因: ${err.message}`)
|
||||
const Plugin_Path = "../../../../../plugins/yenai-plugin"
|
||||
return `${Plugin_Path}/resources/state/img/${backdropDefault}`
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user