mirror of
https://github.com/TriM-Organization/LiteyukiBot-TriM.git
synced 2024-11-11 01:27:29 +08:00
🐛 在读取数据库前进行迁移 fix #35
This commit is contained in:
parent
53bc6df30f
commit
acfc70ea50
@ -5,6 +5,7 @@ import nonebot
|
||||
import psutil
|
||||
from cpuinfo import cpuinfo
|
||||
from liteyuki.utils import __NAME__, __VERSION__
|
||||
from liteyuki.utils.base.config import get_config
|
||||
from liteyuki.utils.base.data_manager import TempConfig, common_db
|
||||
from liteyuki.utils.base.language import Language
|
||||
from liteyuki.utils.base.resource import get_path
|
||||
@ -75,6 +76,7 @@ def get_local_data(lang_code) -> dict:
|
||||
"friends" : lang.get("status.friends"),
|
||||
"groups" : lang.get("status.groups"),
|
||||
"plugins" : lang.get("status.plugins"),
|
||||
"bots" : lang.get("status.bots"),
|
||||
"message_sent" : lang.get("status.message_sent"),
|
||||
"message_received": lang.get("status.message_received"),
|
||||
"cpu" : lang.get("status.cpu"),
|
||||
@ -86,6 +88,13 @@ def get_local_data(lang_code) -> dict:
|
||||
"total" : lang.get("status.total"),
|
||||
"used" : lang.get("status.used"),
|
||||
"free" : lang.get("status.free"),
|
||||
|
||||
"days" : lang.get("status.days"),
|
||||
"hours" : lang.get("status.hours"),
|
||||
"minutes" : lang.get("status.minutes"),
|
||||
"seconds" : lang.get("status.seconds"),
|
||||
"runtime" : lang.get("status.runtime"),
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -126,8 +135,8 @@ async def get_bots_data(self_id: str = "0") -> dict:
|
||||
"protocol_name" : protocol_names.get(version_info.get("protocol_name"), "Online"),
|
||||
"groups" : groups,
|
||||
"friends" : friends,
|
||||
"message_sent" : statistics.get("message_sent"),
|
||||
"message_received": statistics.get("message_received"),
|
||||
"message_sent" : statistics.get("message_sent", 0),
|
||||
"message_received": statistics.get("message_received", 0),
|
||||
"app_name" : app_name
|
||||
}
|
||||
result["bots"].append(bot_data)
|
||||
@ -184,12 +193,13 @@ async def get_hardware_data() -> dict:
|
||||
async def get_liteyuki_data() -> dict:
|
||||
temp_data: TempConfig = common_db.first(TempConfig(), default=TempConfig())
|
||||
result = {
|
||||
"name" : __NAME__,
|
||||
"name" : list(get_config("nickname", [__NAME__]))[0],
|
||||
"version": __VERSION__,
|
||||
"plugins": len(nonebot.get_loaded_plugins()),
|
||||
"nonebot": f"{nonebot.__version__}",
|
||||
"python" : f"{platform.python_implementation()} {platform.python_version()}",
|
||||
"system" : f"{platform.system()} {platform.release()}",
|
||||
"runtime": time.time() - temp_data.data.get("start_time", time.time()), # 运行时间秒数
|
||||
"bots" : len(nonebot.get_bots())
|
||||
}
|
||||
return result
|
||||
|
@ -137,6 +137,7 @@ weather.no_key=未设置天气api key,请在配置文件添加weather_key
|
||||
status.friends=好友
|
||||
status.groups=群
|
||||
status.plugins=插件
|
||||
status.bots=机器人
|
||||
status.message_sent=发送消息
|
||||
status.message_received=接收消息
|
||||
status.cpu=处理器
|
||||
@ -146,4 +147,9 @@ status.disk=磁盘
|
||||
status.usage=使用率
|
||||
status.total=总计
|
||||
status.used=已用
|
||||
status.free=空闲
|
||||
status.free=空闲
|
||||
status.runtime=运行时间
|
||||
status.days=天
|
||||
status.hours=时
|
||||
status.minutes=分
|
||||
status.seconds=秒
|
@ -0,0 +1,60 @@
|
||||
:root {
|
||||
--main-text-color: #fff;
|
||||
--sub-text-color: #bbb;
|
||||
--tip-text-color: #888;
|
||||
}
|
||||
|
||||
.bot-info {
|
||||
display: flex;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.bot-icon {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
aspect-ratio: 1;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.bot-icon-img {
|
||||
border-radius: 50%;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.bot-name {
|
||||
color: var(--main-text-color);
|
||||
display: flex;
|
||||
font-size: 40px;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.bot-tag {
|
||||
white-space: nowrap;
|
||||
color: var(--sub-text-color);
|
||||
font-size: 27px;
|
||||
font-weight: 700;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.bot-tag[suffix="1"]::after {
|
||||
content: " | ";
|
||||
display: inline-block;
|
||||
margin: 0 5px;
|
||||
height: 30%;
|
||||
line-height: 50%;
|
||||
color: var(--tip-text-color);
|
||||
}
|
||||
|
||||
/*修改bot-info 下hr样式*/
|
||||
.bot-info hr {
|
||||
border: 0;
|
||||
height: 4px;
|
||||
background: var(--tip-text-color);
|
||||
margin: 10px 0;
|
||||
width: 100%;
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
const data = JSON.parse(document.getElementById('data').innerText);
|
||||
const bot_data = data['bot']; // 机器人数据
|
||||
const hardware_data = data['hardware']; // 硬件数据
|
||||
const liteyuki_data = data['liteyuki']; // LiteYuki数据
|
||||
const local_data = data['localization']; // 本地化语言数据
|
||||
|
||||
console.log(data)
|
||||
const hardwareData = data['hardware']; // 硬件数据
|
||||
const liteyukiData = data['liteyuki']; // LiteYuki数据
|
||||
const localData = data['localization']; // 本地化语言数据
|
||||
|
||||
/**
|
||||
* 创建饼图
|
||||
* 创建CPU/内存/交换饼图
|
||||
* @param title
|
||||
* @param {Array<{name: string, value: number}>} data 数据
|
||||
*/
|
||||
@ -62,7 +60,7 @@ function createPieChartOption(title, data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建柱状图
|
||||
* 创建磁盘用量柱状图
|
||||
* @param title
|
||||
* @param percent 数据
|
||||
*/
|
||||
@ -70,15 +68,79 @@ function createBarChartOption(title, percent) {
|
||||
// percent为百分比,最大值为100
|
||||
}
|
||||
|
||||
function secondsToTextTime(seconds) {
|
||||
let days = Math.floor(seconds / 86400)
|
||||
let hours = Math.floor((seconds % 86400) / 3600)
|
||||
let minutes = Math.floor((seconds % 3600) / 60)
|
||||
let seconds_ = Math.floor(seconds % 60)
|
||||
return `${days}${localData['days']} ${hours}${localData['hours']} ${minutes}${localData['minutes']} ${seconds_}${localData['seconds']}`
|
||||
}
|
||||
|
||||
// 主函数
|
||||
function main() {
|
||||
// 添加机器人信息
|
||||
bot_data['bots'].forEach(
|
||||
(bot, index) => {
|
||||
let botInfoDiv = document.importNode(document.getElementById('bot-template').content, true)
|
||||
document.body.insertBefore(botInfoDiv, document.getElementById('hardware-info'))
|
||||
(bot) => {
|
||||
let botInfoDiv = document.importNode(document.getElementById('bot-template').content, true) // 复制模板
|
||||
|
||||
|
||||
// 设置机器人信息
|
||||
botInfoDiv.className = 'info-box bot-info'
|
||||
console.log(botInfoDiv.querySelector('.bot-icon-img'))
|
||||
botInfoDiv.querySelector('.bot-icon-img').setAttribute('src', bot['icon'])
|
||||
botInfoDiv.querySelector('.bot-name').innerText = bot['name']
|
||||
let tagArray = [
|
||||
bot['protocol_name'],
|
||||
bot['app_name'],
|
||||
`${localData['groups']} ${bot['groups']}`,
|
||||
`${localData['friends']} ${bot['friends']}`,
|
||||
`${localData['message_sent']} ${bot['message_sent']}`,
|
||||
`${localData['message_received']} ${bot['message_received']}`,
|
||||
]
|
||||
// 添加一些标签
|
||||
tagArray.forEach(
|
||||
(tag, index) => {
|
||||
let tagSpan = document.createElement('span')
|
||||
tagSpan.className = 'bot-tag'
|
||||
tagSpan.innerText = tag
|
||||
// 给最后一个标签不添加后缀
|
||||
tagSpan.setAttribute('suffix', index === tagArray.length - 1 ? '0' : '1')
|
||||
botInfoDiv.querySelector('.bot-tags').appendChild(tagSpan)
|
||||
}
|
||||
)
|
||||
document.body.insertBefore(botInfoDiv, document.getElementById('hardware-info')) // 插入对象
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
// 添加轻雪信息
|
||||
let liteyukiInfoDiv = document.importNode(document.getElementById('bot-template').content, true) // 复制模板
|
||||
liteyukiInfoDiv.className = 'info-box bot-info'
|
||||
liteyukiInfoDiv.querySelector('.bot-icon-img').setAttribute('src', './img/liteyuki.png')
|
||||
liteyukiInfoDiv.querySelector('.bot-name').innerText = liteyukiData['name']
|
||||
console.log(liteyukiData)
|
||||
let tagArray = [
|
||||
`Liteyuki ${liteyukiData['version']}`,
|
||||
`Nonebot ${liteyukiData['nonebot']}`,
|
||||
liteyukiData['python'],
|
||||
liteyukiData['system'],
|
||||
`${localData['plugins']} ${liteyukiData['plugins']}`,
|
||||
`${localData['bots']} ${liteyukiData['bots']}`,
|
||||
`${localData['runtime']} ${secondsToTextTime(liteyukiData['runtime'])}`,
|
||||
]
|
||||
tagArray.forEach(
|
||||
(tag, index) => {
|
||||
let tagSpan = document.createElement('span')
|
||||
tagSpan.className = 'bot-tag'
|
||||
tagSpan.innerText = tag
|
||||
// 给最后一个标签不添加后缀
|
||||
tagSpan.setAttribute('suffix', index === tagArray.length - 1 ? '0' : '1')
|
||||
liteyukiInfoDiv.querySelector('.bot-tags').appendChild(tagSpan)
|
||||
}
|
||||
)
|
||||
document.body.insertBefore(liteyukiInfoDiv, document.getElementById('hardware-info')) // 插入对象
|
||||
|
||||
// 添加硬件信息
|
||||
}
|
||||
|
||||
main()
|
@ -5,18 +5,20 @@
|
||||
<title>Liteyuki Status</title>
|
||||
<link rel="stylesheet" href="./css/card.css">
|
||||
<link rel="stylesheet" href="./css/status.css">
|
||||
<link rel="stylesheet" href="./css/fonts.css">
|
||||
</head>
|
||||
<body>
|
||||
<template id="bot-template">
|
||||
<div class="info-box bot-info">
|
||||
<div id="bot-icon">
|
||||
<img id="bot-icon-img" src="" alt="">
|
||||
<div class="bot-icon">
|
||||
<img class="bot-icon-img" src="" alt="bot-icon">
|
||||
</div>
|
||||
<div id="bot-detail">
|
||||
<div id="bot-name">
|
||||
<div class="bot-detail">
|
||||
<div class="bot-name">
|
||||
Liteyuki
|
||||
</div>
|
||||
<div id="bot-tags">
|
||||
<hr>
|
||||
<div class="bot-tags">
|
||||
<!-- tag span-->
|
||||
</div>
|
||||
</div>
|
||||
|
@ -51,6 +51,7 @@ def init():
|
||||
|
||||
"""
|
||||
# 检测python版本是否高于3.10
|
||||
auto_migrate()
|
||||
init_log()
|
||||
if sys.version_info < (3, 10):
|
||||
nonebot.logger.error("This project requires Python3.10+ to run, please upgrade your Python Environment.")
|
||||
@ -59,7 +60,6 @@ def init():
|
||||
temp_data.data["start_time"] = time.time()
|
||||
common_db.upsert(temp_data)
|
||||
|
||||
auto_migrate()
|
||||
# 在加载完成语言后再初始化日志
|
||||
nonebot.logger.info("Liteyuki is initializing...")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user