⚡️ 优化
This commit is contained in:
122
apps/state.js
122
apps/state.js
@@ -79,77 +79,21 @@ export class NewState extends plugin {
|
||||
// Node板块
|
||||
State.getNodeInfo()
|
||||
]))
|
||||
const defaultAvatar = `../../../../../plugins/${Plugin_Name}/resources/state/img/default_avatar.jpg`
|
||||
// 机器人名称
|
||||
const BotName = Version.name
|
||||
// 系统运行时间
|
||||
const systime = common.formatTime(os.uptime(), 'dd天hh小时mm分', false)
|
||||
// 日历
|
||||
const calendar = moment().format('YYYY-MM-DD HH:mm:ss')
|
||||
// nodejs版本
|
||||
let BotStatus = ""
|
||||
|
||||
/** bot列表 */
|
||||
let BotList = [e.self_id]
|
||||
/** TRSS */
|
||||
if (e.msg.includes("pro") && Array.isArray(Bot?.uin)) {
|
||||
BotList = Bot.uin
|
||||
}
|
||||
/** ws-plugin、Lain-plugin多bot */
|
||||
else if (e.msg.includes("pro") && !Array.isArray(Bot?.uin) && Bot?.adapter && Bot?.adapter.includes(e.self_id)) {
|
||||
BotList = Bot.adapter
|
||||
|
||||
if (e.msg.includes('pro')) {
|
||||
if (Array.isArray(Bot?.uin)) {
|
||||
BotList = Bot.uin
|
||||
} else if (Bot?.adapter && Bot.adapter.includes(e.self_id)) {
|
||||
BotList = Bot.adapter
|
||||
}
|
||||
}
|
||||
|
||||
for (const i of BotList) {
|
||||
const bot = Bot[i]
|
||||
if (!bot?.uin) continue
|
||||
// 头像
|
||||
const avatar = bot.avatar || (Number(bot.uin) ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${bot.uin}` : defaultAvatar)
|
||||
// 昵称
|
||||
const nickname = bot.nickname || "未知"
|
||||
// 在线状态
|
||||
const onlineStatus = status[bot.status] || "在线"
|
||||
// 登录平台版本
|
||||
const platform = bot.apk ? `${bot.apk.display} v${bot.apk.version}` : bot.version.version || "未知"
|
||||
// 发
|
||||
const sent = await redis.get(`Yz:count:send:msg:bot:${bot.uin}:total`) || await redis.get('Yz:count:sendMsg:total') || 0
|
||||
// 收
|
||||
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:total') || 0
|
||||
// 好友数
|
||||
const friendQuantity = Array.from(bot.fl?.keys()).length
|
||||
// 群数
|
||||
const groupQuantity = Array.from(bot.gl?.keys()).length
|
||||
// 群员数
|
||||
let groupMemberQuantity = 0
|
||||
for (const i of bot.gml?.values() || [])
|
||||
groupMemberQuantity += Array.from(i.keys()).length
|
||||
// 运行时间
|
||||
const runTime = common.formatTime(Date.now() / 1000 - bot.stat?.start_time, 'dd天hh小时mm分', false)
|
||||
// Bot版本
|
||||
const botVersion = bot.version ? `${bot.version.name}(${bot.version.id})${bot.apk ? ` ${bot.version.version}` : ""}` : `ICQQ(QQ) v${require('icqq/package.json').version}`
|
||||
BotStatus += `<div class="box">
|
||||
<div class="tb">
|
||||
<div class="avatar">
|
||||
<img src="${avatar}"
|
||||
onerror="this.src= '${defaultAvatar}'; this.onerror = null;">
|
||||
</div>
|
||||
<div class="header">
|
||||
<h1>${nickname}</h1>
|
||||
<hr noshade>
|
||||
<p>${onlineStatus}(${platform}) | ${botVersion}</p>
|
||||
<p>收${recv} | 发${sent} | 图片${screenshot} | 好友${friendQuantity} | 群${groupQuantity} | 群员${groupMemberQuantity}</p>
|
||||
<p>${BotName} 已运行 ${runTime} | 系统运行 ${systime}</p>
|
||||
<p>${calendar} | Node.js ${process.version} | ${process.platform} ${process.arch}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
// 渲染数据
|
||||
let data = {
|
||||
BotStatus,
|
||||
BotStatus: await getBotState(BotList),
|
||||
chartData: JSON.stringify(common.checkIfEmpty(State.chartData, ['echarts_theme', 'cpu', 'ram']) ? undefined : State.chartData),
|
||||
// 硬盘内存
|
||||
HardDisk,
|
||||
@@ -174,4 +118,52 @@ export class NewState extends plugin {
|
||||
|
||||
interval = false
|
||||
}
|
||||
}
|
||||
}
|
||||
const getBotState = async (botList) => {
|
||||
const defaultAvatar = `../../../../../plugins/${Plugin_Name}/resources/state/img/default_avatar.jpg`
|
||||
const BotName = Version.name
|
||||
const systime = common.formatTime(os.uptime(), 'dd天hh小时mm分', false)
|
||||
const calendar = moment().format('YYYY-MM-DD HH:mm:ss')
|
||||
|
||||
const dataPromises = botList.map(async (i) => {
|
||||
const bot = Bot[i]
|
||||
if (!bot?.uin) return ''
|
||||
|
||||
const avatar = bot.avatar || (Number(bot.uin) ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${bot.uin}` : defaultAvatar)
|
||||
const nickname = bot.nickname || '未知'
|
||||
const onlineStatus = status[bot.status] || '在线'
|
||||
const platform = bot.apk ? `${bot.apk.display} v${bot.apk.version}` : bot.version.version || '未知'
|
||||
|
||||
const [sent, recv, screenshot] = await Promise.all([
|
||||
redis.get(`Yz:count:send:msg:bot:${bot.uin}:total`),
|
||||
redis.get(`Yz:count:receive:msg:bot:${bot.uin}:total`) || bot.stat?.recv_msg_cnt || '未知',
|
||||
redis.get(`Yz:count:send:image:bot:${bot.uin}:total`)
|
||||
])
|
||||
|
||||
const friendQuantity = bot.fl?.size || 0
|
||||
const groupQuantity = bot.gl?.size || 0
|
||||
const groupMemberQuantity = Array.from(bot.gml?.values() || []).reduce((acc, curr) => acc + curr.size, 0)
|
||||
const runTime = common.formatTime(Date.now() / 1000 - bot.stat?.start_time, 'dd天hh小时mm分', false)
|
||||
const botVersion = bot.version ? `${bot.version.name}(${bot.version.id})${bot.apk ? ` ${bot.version.version}` : ''}` : `ICQQ(QQ) v${require('icqq/package.json').version}`
|
||||
|
||||
return `<div class="box">
|
||||
<div class="tb">
|
||||
<div class="avatar">
|
||||
<img src="${avatar}"
|
||||
onerror="this.src= '${defaultAvatar}'; this.onerror = null;">
|
||||
</div>
|
||||
<div class="header">
|
||||
<h1>${nickname}</h1>
|
||||
<hr noshade>
|
||||
<p>${onlineStatus}(${platform}) | ${botVersion}</p>
|
||||
<p>收${recv} | 发${sent || 0} | 图片${screenshot || 0} | 好友${friendQuantity} | 群${groupQuantity} | 群员${groupMemberQuantity}</p>
|
||||
<p>${BotName} 已运行 ${runTime} | 系统运行 ${systime}</p>
|
||||
<p>${calendar} | Node.js ${process.version} | ${process.platform} ${process.arch}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
|
||||
const dataArray = await Promise.all(dataPromises)
|
||||
return dataArray.join('')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user