From d37442bc9d03b3ac4791709b44f1218ff9bd0b2a Mon Sep 17 00:00:00 2001 From: snowy Date: Thu, 11 Apr 2024 13:15:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8A=B6=E6=80=81=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E6=A8=A1=E7=B3=8A=E5=8D=8A=E5=BE=84=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- liteyuki/liteyuki_main/runtime.py | 2 +- liteyuki/plugins/liteyuki_pacman/rpm.py | 2 + liteyuki/plugins/liteyuki_weather/__init__.py | 2 + liteyuki/plugins/liteyuki_weather/qweather.py | 20 ++++- liteyuki/resources/templates/css/style.css | 87 ++++++++++++++++++- liteyuki/resources/templates/js/style.js | 16 +++- liteyuki/resources/templates/stats.html | 87 ------------------- liteyuki/utils/config.py | 24 +++++ liteyuki/utils/resource.py | 6 +- 9 files changed, 151 insertions(+), 95 deletions(-) diff --git a/liteyuki/liteyuki_main/runtime.py b/liteyuki/liteyuki_main/runtime.py index 9e69aef2..d9b6d9c3 100644 --- a/liteyuki/liteyuki_main/runtime.py +++ b/liteyuki/liteyuki_main/runtime.py @@ -33,7 +33,7 @@ protocol_names = { async def _(bot: T_Bot, event: T_MessageEvent): ulang = get_user_lang(str(event.user_id)) image = await template2image( - get_path("templates/stats.html", abs_path=True), + get_path("templates/stats.html", abs_path=True, debug=True), { "data": await get_stats_data(bot.self_id, ulang.lang_code) }, diff --git a/liteyuki/plugins/liteyuki_pacman/rpm.py b/liteyuki/plugins/liteyuki_pacman/rpm.py index 39ca69ce..b2fb8e90 100644 --- a/liteyuki/plugins/liteyuki_pacman/rpm.py +++ b/liteyuki/plugins/liteyuki_pacman/rpm.py @@ -1,10 +1,12 @@ # 轻雪资源包管理器 import os +import nonebot import yaml from nonebot import require from nonebot.permission import SUPERUSER +from liteyuki.utils.config import get_config from liteyuki.utils.language import get_user_lang from liteyuki.utils.ly_typing import T_Bot, T_MessageEvent from liteyuki.utils.message import Markdown as md diff --git a/liteyuki/plugins/liteyuki_weather/__init__.py b/liteyuki/plugins/liteyuki_weather/__init__.py index 09fe0076..54cd1480 100644 --- a/liteyuki/plugins/liteyuki_weather/__init__.py +++ b/liteyuki/plugins/liteyuki_weather/__init__.py @@ -1,4 +1,6 @@ from nonebot.plugin import PluginMetadata +from .qweather import * + __plugin_meta__ = PluginMetadata( name="轻雪天气", diff --git a/liteyuki/plugins/liteyuki_weather/qweather.py b/liteyuki/plugins/liteyuki_weather/qweather.py index 3fd56bd6..715d1299 100644 --- a/liteyuki/plugins/liteyuki_weather/qweather.py +++ b/liteyuki/plugins/liteyuki_weather/qweather.py @@ -1,15 +1,27 @@ +import nonebot from nonebot import require +from liteyuki.utils.config import get_config +from liteyuki.utils.ly_typing import T_Bot + require("nonebot_plugin_alconna") -from nonebot_plugin_alconna import on_alconna, Alconna, Subcommand, Args, MultiVar, Arparma +from nonebot_plugin_alconna import on_alconna, Alconna, Args, Arparma, MultiVar @on_alconna( aliases={"天气"}, command=Alconna( "weather", - Args["keywords", MultiVar(str)], + Args["keywords", MultiVar(str), []], ), ).handle() -async def _(result: Arparma): - """await alconna.send("weather", city)""" \ No newline at end of file +async def _(bot: T_Bot, result: Arparma): + """ + 天气查询 + Args: + bot: + + Returns: + + """ + print("AAA", result, result.main_args) diff --git a/liteyuki/resources/templates/css/style.css b/liteyuki/resources/templates/css/style.css index de123389..fb01c20b 100644 --- a/liteyuki/resources/templates/css/style.css +++ b/liteyuki/resources/templates/css/style.css @@ -11,7 +11,92 @@ body { .info-box { border-radius: 30px; padding: 30px; - backdrop-filter: blur(60px); + backdrop-filter: blur(10px); background-color: rgba(0, 0, 0, 0.3); margin-bottom: 20px; +} + +.pie-chart { + height: 240px; + width: 240px; + margin-bottom: 20px; +} + +.pie-info { + margin: 0 40px; + align-items: center; +} + +.bot-info { + align-items: center; + display: flex; +} + +#hardware-info { + justify-content: center; + text-align: center; + display: flex; +} + +#disks-info { + flex-wrap: wrap; + justify-content: center; + +} + +#motto-info { + margin-bottom: 0; + text-align: center; + white-space: pre-wrap; +} + +.bot-icon { + border-radius: 50%; + height: 200px; + background-color: white; +} + +.bot-name, .bot-tag { + margin-left: 20px; +} + +.bot-name { + font-size: 42px; + font-weight: bold; +} + + +.bot-tag { + margin-top: 10px; +} + +.chart-label { + font-size: 24px; + max-width: 240px; +} + +.tag { + font-size: 32px; + font-weight: 700; + font-style: italic; +} + +.tag[suffix="1"]::after { + content: " | "; + display: inline-block; + margin: 0 5px; + height: 50%; + line-height: 50%; + color: #ccc; +} + +.motto-text { + font-size: 36px; + color: #fff; +} + +.motto-author { + font-size: 30px; + font-style: italic; + color: #ccc; } \ No newline at end of file diff --git a/liteyuki/resources/templates/js/style.js b/liteyuki/resources/templates/js/style.js index a236112f..97902af4 100644 --- a/liteyuki/resources/templates/js/style.js +++ b/liteyuki/resources/templates/js/style.js @@ -123,16 +123,30 @@ mottoAuthor.style.textAlign = 'right'; mottoDiv.appendChild(mottoAuthor); + function getPieUsage(data){ + let total = 0 + let used = 0 + data.forEach(item => { + total += item.value + if(item.name === 'FREE'){ + used += item.value + } + }) + console.log(used, total) + return used / total * 100 + } + function getPieOption(title, data) { return { animation: false, title: { - text: title, + text: title + '\n' + getPieUsage(data).toFixed(1) + '%', left: 'center', top: 'center', textStyle: { //文字颜色 + lineHeight: 36, color: '#fff', fontSize: 30 } diff --git a/liteyuki/resources/templates/stats.html b/liteyuki/resources/templates/stats.html index 93a7279d..4fcc26d8 100644 --- a/liteyuki/resources/templates/stats.html +++ b/liteyuki/resources/templates/stats.html @@ -7,93 +7,6 @@ Liteyuki Stats - diff --git a/liteyuki/utils/config.py b/liteyuki/utils/config.py index be31a457..7a591498 100644 --- a/liteyuki/utils/config.py +++ b/liteyuki/utils/config.py @@ -4,6 +4,8 @@ import nonebot import yaml from pydantic import BaseModel +from liteyuki.utils.data_manager import StoredConfig, common_db +from liteyuki.utils.ly_typing import T_Bot from liteyuki.utils.tools import random_hex_string config = {} # 全局配置,确保加载后读取 @@ -34,6 +36,28 @@ def load_from_yaml(file: str) -> dict: return conf +def get_config(key: str, bot: T_Bot = None, default=None): + """获取配置项,优先级:bot > config > db > yaml""" + if bot is None: + bot_config = {} + else: + bot_config = bot.config.dict() + if key in bot_config: + return bot_config[key] + + elif key in config: + return config[key] + + elif key in common_db.first(StoredConfig(), default=StoredConfig()).config: + return common_db.first(StoredConfig(), default=StoredConfig()).config[key] + + elif key in load_from_yaml("config.yml"): + return load_from_yaml("config.yml")[key] + + else: + return default + + def init_conf(conf: dict) -> dict: if "" not in conf.get("command_start", []): conf["alconna_use_command_start"] = True diff --git a/liteyuki/utils/resource.py b/liteyuki/utils/resource.py index b77d94bb..eca08ff9 100644 --- a/liteyuki/utils/resource.py +++ b/liteyuki/utils/resource.py @@ -47,15 +47,19 @@ def load_resource_from_dir(path: str): _loaded_resource_packs.insert(0, ResourceMetadata(**metadata)) -def get_path(path: str, abs_path: bool = False, default: Any = None) -> str | Any: +def get_path(path: str, abs_path: bool = False, default: Any = None, debug: bool=False) -> str | Any: """ 获取资源包中的文件 Args: + debug: 启用调试,每次都会先重载资源 abs_path: 是否返回绝对路径 default: 默认 path: 文件相对路径 Returns: 文件绝对路径 """ + if debug: + nonebot.logger.debug("Enable resource debug, Reloading resources") + load_resources() resource_relative_path = os.path.join(temp_resource_root, path) if os.path.exists(resource_relative_path): return os.path.abspath(resource_relative_path) if abs_path else resource_relative_path