Skip to content

Commit

Permalink
✨ 重构自检ui
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Sep 6, 2024
1 parent 51371ba commit 3b4c206
Show file tree
Hide file tree
Showing 12 changed files with 593 additions and 90 deletions.
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ python-multipart = "^0.0.9"
nonebot-plugin-alconna = "0.51.1"
arclet-alconna = "1.8.23"
aiocache = "^0.12.2"
py-cpuinfo = "^9.0.0"

[tool.poetry.dev-dependencies]
nonebug = "^0.3.2"
Expand Down
179 changes: 179 additions & 0 deletions resources/template/check/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@


@font-face {
font-family: fzrzFont;
/* 导入的字体文件 */
src: url("./res/font/fzrzExtraBold.ttf");
}




body {
position: absolute;
left: -8px;
top: -8px;
}

.wrapper{
height: 750px;
width: 395px;
background-color: antiquewhite;
position: relative;
}

.top-image {
height: 215px;
width: 395px;
}

.abs-image {
height: 426px;
width: 93px;
position: absolute;
right: 39px;
top: 240px;
}

.bot-text {
height: 55px;
width: 335px;
position: relative;
padding: 0 30px;
margin-top: 10px;
}

.main {
height: 448px;
width: 335px;
padding: 0 30px;
position: relative;
}

.title {
background-color: #EB869D;
height: 32px;
font-family: 'fzrzFont';
color: white;
width: max-content;
border-radius: 20px;
padding: 0 10px;
float: left;
margin-top: 10px;
}

.title-n {
height: 23px;
width: 23px;
border-radius: 50%;
background-color: white;
position: absolute;
left: 36px;
top: 15px;
display: flex;
justify-content: center;
align-items: center;
}

.title-a {
background-color: #ED859E;
height: 19px;
width: 19px;
border-radius: 50%;
}

.network {
display: flex;
margin-left: 10px;
}

.network-item {
font-family: 'fzrzFont';
color: #EC859F;
display: flex;
justify-items: center;
align-items: center;
margin-left: 20px;
}

.network-status {
height: 10px;
width: 10px;
border-radius: 50%;
margin-left: 5px;
}

.network-text {
margin-left: 5px;
}

.network-item {
margin-top: 10px;
}

.data-status-item {
margin-top: 10px;
}

.data-status {
width: 100%;
height: 240px;
/* background-color:blueviolet; */
margin-top: 22px;
}

.data-status-item {
display: flex;
font-family: 'fzrzFont';
font-size: 15px;
line-height: 18.5px;
height: 50px;
}

.process {
height: 28px;
width: 105px;
border: #ED859E 4px solid;
border-radius: 30px;
overflow: hidden;
}

.process-bar {
height: 28px;
width: 30px;
background-color: #EB869D;
border-top-right-radius: 30px;
border-bottom-right-radius: 30px;
}

.data-status-item-text {
margin-left: 10px;
color: #EC839D;
}

.line {
background-color: #EC859F;
height: 2px;
width: 100%;
border-radius: 20px;
}

.status-text {
font-family: 'fzrzFont';
color: #EC859F;
height: 90px;
display: flex;
}

.status-text-title {
height: 25%;
}

.tip {
font-family: 'fzrzFont';
color: #ecbac7;
font-size: 10px;
position: absolute;
right: 5px;
bottom: 1px;
}
90 changes: 90 additions & 0 deletions resources/template/check/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

</html>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
<!-- <link rel="stylesheet" href="./res/font-awesome/css/font-awesome.min.css"> -->
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="wrapper">
<img class="top-image" src="res/img/top.jpg"></img>
<img class="abs-image" src="res/img/bk.png"></img>
<div class="bot-text">
<div class="title">
<div class="title-n">
<div class="title-a"></div>
</div>
<span style="margin-left: 22px;">{{data.nickname}}自检</span>
</div>
<div class="network">
<div class="network-item">BaiDu<span class="network-status" style="background-color: {{data.baidu}}; border: 1px solid {{data.baidu}}"></span></div>
<div class="network-item">Google<span class="network-status" style="background-color: {{data.google}}; border: 1px solid {{data.google}}"></span></div>
</div>
</div>
<div class="main">
<div class="data-status">
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.cpu_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>CPU</div>
<!-- <div style="font-size: 13px;">0.8% - 3.5Ghz [14core]</div> -->
<div style="font-size: 13px;">{{data.cpu_info}}</div>
</div>
</div>
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.ram_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>RAM</div>
<div>{{data.ram_info}}</div>
</div>
</div>
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.swap_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>SWAP</div>
<div>{{data.swap_info}}</div>
</div>
</div>
<div class="data-status-item">
<div class="process">
<div class="process-bar" style="width: {{data.disk_process}}%;"></div>
</div>
<div class="data-status-item-text">
<div>DISK</div>
<div>{{data.disk_info}}</div>
</div>
</div>
</div>
<div class="line"></div>
<div class="status-text">
<div>
<p class="status-text-title">CPU</p>
<p class="status-text-title">SYSTEM</p>
<p class="status-text-title">VERSION</p>
<p class="status-text-title">PLUGINS</p>
</div>
<div style="margin-left: 37px;">
<p class="status-text-title" style="font-size: 14px;line-height: 18.5px;">{{data.brand_raw}}</p>
<p class="status-text-title">{{data.system}}</p>
<p class="status-text-title">{{data.version}}</p>
<p class="status-text-title">{{data.plugin_count}} loaded</p>
</div>
</div>
</div>
<div class="tip">Create By Zhenxun</div>
</div>
</body>
<script type="text/javascript" src="main.js">
</script>
</html>
Empty file.
Binary file not shown.
Binary file added resources/template/check/res/img/bk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/template/check/res/img/top.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions zhenxun/builtin_plugins/check/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from nonebot.rule import to_me
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot_plugin_session import EventSession
from nonebot_plugin_htmlrender import template_to_pic
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna

from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
from zhenxun.utils.message import MessageUtils
from zhenxun.configs.utils import PluginExtraData
from zhenxun.configs.path_config import TEMPLATE_PATH

from .data_source import get_status_info

__plugin_meta__ = PluginMetadata(
name="服务器自我检查",
description="查看服务器当前状态",
usage="""
查看服务器当前状态
指令:
自检
""".strip(),
extra=PluginExtraData(
author="HibiKier", version="0.1", plugin_type=PluginType.SUPERUSER
).dict(),
)


_matcher = on_alconna(
Alconna("自检"), rule=to_me(), permission=SUPERUSER, block=True, priority=1
)


@_matcher.handle()
async def _(session: EventSession, arparma: Arparma):
try:
data = await get_status_info()
image = await template_to_pic(
template_path=str((TEMPLATE_PATH / "check").absolute()),
template_name="main.html",
templates={"data": data},
pages={
"viewport": {"width": 195, "height": 750},
"base_url": f"file://{TEMPLATE_PATH}",
},
wait=2,
)
await MessageUtils.build_message(image).send()
logger.info("自检", arparma.header_result, session=session)
except Exception as e:
await MessageUtils.build_message(f"自检失败: {e}").send()
logger.error("自检失败", arparma.header_result, session=session, e=e)
Loading

0 comments on commit 3b4c206

Please sign in to comment.