From a76bc3de9237d5089582cd343774782c96296b17 Mon Sep 17 00:00:00 2001 From: snowy Date: Sat, 6 Apr 2024 08:48:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E7=9A=84=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=8C=85=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=20feat:=20?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=95=86=E5=BA=97=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + docs/.vuepress/navbar.ts | 5 ++ docs/README.md | 4 ++ docs/store/README.md | 27 +++++++++ docs/usage/basic_command.md | 3 +- liteyuki/liteyuki_main/__init__.py | 1 - liteyuki/liteyuki_main/core.py | 20 +++++++ liteyuki/liteyuki_main/loader.py | 11 +--- liteyuki/liteyuki_main/runtime.py | 19 +++++-- liteyuki/plugins/liteyuki_npm/__init__.py | 1 + liteyuki/plugins/liteyuki_npm/rpm.py | 18 ++++++ liteyuki/resources/lang/zh-CN.lang | 4 +- liteyuki/resources/templates/stats.html | 1 - liteyuki/utils/resource.py | 69 ++++++++++++++++++----- 14 files changed, 153 insertions(+), 31 deletions(-) create mode 100644 docs/store/README.md create mode 100644 liteyuki/plugins/liteyuki_npm/rpm.py diff --git a/.gitignore b/.gitignore index afb5c74..a86f1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/ data/ db/ +/resources/ __pycache__/ *.pyc *.pyo diff --git a/docs/.vuepress/navbar.ts b/docs/.vuepress/navbar.ts index b1ed99b..4fc30c5 100644 --- a/docs/.vuepress/navbar.ts +++ b/docs/.vuepress/navbar.ts @@ -11,5 +11,10 @@ export default navbar([ text: "使用手册", link: "/usage/", prefix: "usage/", + }, + { + text: "主题商店", + link: "/store/", + prefix: "store/", } ]); diff --git a/docs/README.md b/docs/README.md index 7a62571..a75d684 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,6 +19,10 @@ actions: - text: 使用手册 icon: book link: ./usage/basic_command.html + + - text: 主题商店 + icon: paint-brush + link: ./theme/theme_store.html #1. 安装 `Git` 和 `Python3.10+` 环境 #2. 克隆项目 `git clone https://github.com/snowykami/LiteyukiBot` (无法连接可以用`https://gitee.com/snowykami/LiteyukiBot`) diff --git a/docs/store/README.md b/docs/store/README.md new file mode 100644 index 0000000..fec98b1 --- /dev/null +++ b/docs/store/README.md @@ -0,0 +1,27 @@ +--- +home: true +icon: paint-brush +heroText: Liteyuki Theme Store +tagline: 轻雪主题/资源商店 + +highlights: + - header: 所有资源包 + bgImage: https://theme-hope-assets.vuejs.press/bg/2-light.svg + bgImageDark: https://theme-hope-assets.vuejs.press/bg/2-dark.svg + bgImageStyle: + background-repeat: repeat + background-size: initial + features: + - title: Kawaii-Status + icon: paint-brush + details: 可爱的状态卡片,模仿的Koishi + link: https://cdn.liteyuki.icu/static/lrp/KawaiiStatus.zip + - title: MiSans字体包 + icon: paint-brush + details: 标准字体包,适用于大多数主题,简约大方 + link: https://cdn.liteyuki.icu/static/lrp/MiSansFonts.zip + - title: MapleMono字体包 + icon: paint-brush + details: 适用于标准主题的MapleMono字体包 + link: https://cdn.liteyuki.icu/static/lrp/MapleMonoFonts.zip +--- \ No newline at end of file diff --git a/docs/usage/basic_command.md b/docs/usage/basic_command.md index 46ad743..c4e30ee 100644 --- a/docs/usage/basic_command.md +++ b/docs/usage/basic_command.md @@ -17,10 +17,11 @@ category: 使用手册 [S]liteecho # 查看当前bot [S]config set value # 添加配置项,若存在则会覆盖,输入值会被执行,以便于转换为正确的值,"10"和10是不一样的 [S]config get [key] # 查询配置项,不带key返回配置项列表,推荐私聊使用 +[S]reload-resources # 重载资源 [S]switch-image-mode # 切换图片模式,该功能需要commit:505468b及以后的Lagrange.OneBot,在普通图片和Markdown图片之间切换,后者更大但有失败的可能 # 上述两个命令修改的配置项在数据库中保存,但是优先级低于配置文件,如果配置文件中存在相同的配置项,将会使用配置文件中的配置 ------ -别名: reload-liteyuki 重启轻雪, update-liteyuki 更新轻雪, config 配置, set 设置, get 查询 +别名: reload-liteyuki 重启轻雪, update-liteyuki 更新轻雪, reload-resources 重载资源, config 配置, set 设置, get 查询 ``` ### 轻雪Nonebot插件管理 `liteyuki_npm` diff --git a/liteyuki/liteyuki_main/__init__.py b/liteyuki/liteyuki_main/__init__.py index 470b129..27fba35 100644 --- a/liteyuki/liteyuki_main/__init__.py +++ b/liteyuki/liteyuki_main/__init__.py @@ -1,6 +1,5 @@ from nonebot.plugin import PluginMetadata -from liteyuki.utils.language import get_default_lang from .core import * from .loader import * from .runtime import * diff --git a/liteyuki/liteyuki_main/core.py b/liteyuki/liteyuki_main/core.py index c60df79..d72477a 100644 --- a/liteyuki/liteyuki_main/core.py +++ b/liteyuki/liteyuki_main/core.py @@ -14,6 +14,7 @@ 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 from liteyuki.utils.reloader import Reloader +from liteyuki.utils.resource import get_loaded_resource_packs, load_resources require("nonebot_plugin_alconna"), require("nonebot_plugin_htmlrender") from nonebot_plugin_alconna import on_alconna, Alconna, Args, Subcommand, Arparma @@ -45,6 +46,14 @@ reload_liteyuki = on_alconna( permission=SUPERUSER ) +reload_resources = on_alconna( + aliases={"重载资源"}, + command=Alconna( + "reload-resources" + ), + permission=SUPERUSER +) + cmd_config = on_alconna( aliases={"配置"}, command=Alconna( @@ -153,6 +162,17 @@ async def _(result: Arparma, event: T_MessageEvent, bot: T_Bot): await md.send_md(reply, bot, event=event) +@reload_resources.handle() +async def _(event: T_MessageEvent): + ulang = get_user_lang(str(event.user_id)) + load_resources() + await reload_resources.finish( + ulang.get("liteyuki.reload_resources_success", + NUM=len(get_loaded_resource_packs()) + ) + ) + + @switch_image_mode.handle() async def _(bot: T_Bot, event: T_MessageEvent): global markdown_image diff --git a/liteyuki/liteyuki_main/loader.py b/liteyuki/liteyuki_main/loader.py index 138b0b5..b31940d 100644 --- a/liteyuki/liteyuki_main/loader.py +++ b/liteyuki/liteyuki_main/loader.py @@ -1,20 +1,15 @@ import os.path +import shutil import nonebot.plugin from liteyuki.utils import init_log from liteyuki.utils.data_manager import InstalledPlugin, plugin_db -from liteyuki.utils.resource import load_resource_from_dir +from liteyuki.utils.resource import load_resource_from_dir, load_resources from liteyuki.utils.tools import check_for_package -# 加载默认资源和语言 -RESOURCE_PATH = "liteyuki/resources" -load_resource_from_dir(RESOURCE_PATH) +load_resources() init_log() -# 加载其他资源包 -if os.path.exists("resources"): - for resource in os.listdir("resources"): - load_resource_from_dir(os.path.join("resources", resource)) nonebot.plugin.load_plugins("liteyuki/plugins") nonebot.plugin.load_plugins("plugins") diff --git a/liteyuki/liteyuki_main/runtime.py b/liteyuki/liteyuki_main/runtime.py index 52580c5..33c4dac 100644 --- a/liteyuki/liteyuki_main/runtime.py +++ b/liteyuki/liteyuki_main/runtime.py @@ -144,10 +144,13 @@ async def get_stats_data(self_id: str = None, lang: str = None) -> dict: if disk_usage.total > 0: disk_data.append( { - "name" : disk.device, - "total" : disk_total_show, - "free" : disk_free_show, - "percent": disk_usage.percent, + "name" : disk.device, + "total" : disk_total_show, + "free" : disk_free_show, + "percent" : disk_usage.percent, + "usedValue" : disk_usage.used, + "freeValue" : disk_usage.free, + "totalValue": disk_usage.total, } ) @@ -164,14 +167,17 @@ async def get_stats_data(self_id: str = None, lang: str = None) -> dict: cpu_info = get_cpu_info() templ = { + "plugin" : len(nonebot.get_loaded_plugins()), + "version" : __VERSION__, + "system" : platform.platform(), "cpu" : [ { "name" : "USED", - "value": psutil.cpu_percent(interval=1) + "value": psutil.cpu_percent() }, { "name" : "FREE", - "value": 100 - psutil.cpu_percent(interval=1) + "value": 100 - psutil.cpu_percent() } ], "mem" : [ @@ -221,6 +227,7 @@ async def get_stats_data(self_id: str = None, lang: str = None) -> dict: "cpu_trans" : ulang.get("main.monitor.cpu"), "mem_trans" : ulang.get("main.monitor.memory"), "swap_trans" : ulang.get("main.monitor.swap"), + "disk_trans" : ulang.get("main.monitor.disk"), "used_trans" : ulang.get("main.monitor.used"), "free_trans" : ulang.get("main.monitor.free"), "total_trans": ulang.get("main.monitor.total"), diff --git a/liteyuki/plugins/liteyuki_npm/__init__.py b/liteyuki/plugins/liteyuki_npm/__init__.py index 03e4482..c6f3f76 100644 --- a/liteyuki/plugins/liteyuki_npm/__init__.py +++ b/liteyuki/plugins/liteyuki_npm/__init__.py @@ -2,6 +2,7 @@ from nonebot.plugin import PluginMetadata from .manager import * from .installer import * from .helper import * +from .rpm import * __author__ = "snowykami" __plugin_meta__ = PluginMetadata( diff --git a/liteyuki/plugins/liteyuki_npm/rpm.py b/liteyuki/plugins/liteyuki_npm/rpm.py new file mode 100644 index 0000000..2270d12 --- /dev/null +++ b/liteyuki/plugins/liteyuki_npm/rpm.py @@ -0,0 +1,18 @@ +# 轻雪资源包管理器 +from nonebot.permission import SUPERUSER +from nonebot_plugin_alconna import on_alconna, Alconna, Args, Subcommand, Arparma + +from liteyuki.utils.ly_typing import T_Bot + +list_rp = on_alconna( + aliases={"列出资源包", "资源包列表"}, + command=Alconna( + "list", + Args["page", int, 1]["num", int, 10], + ), + permission=SUPERUSER +) + +@list_rp.handle() +async def _(bot: T_Bot): + pass \ No newline at end of file diff --git a/liteyuki/resources/lang/zh-CN.lang b/liteyuki/resources/lang/zh-CN.lang index c9bd351..2d48244 100644 --- a/liteyuki/resources/lang/zh-CN.lang +++ b/liteyuki/resources/lang/zh-CN.lang @@ -98,4 +98,6 @@ liteyuki.image_mode_on=开启Markdown图片模式 liteyuki.image_mode_off=关闭Markdown图片模式 npm.page=第{PAGE}/{TOTAL}页 -main.monitor.free=空闲 \ No newline at end of file +main.monitor.free=空闲 + +liteyuki.reload_resources_success=资源重载成功,共计{NUM}个资源包 \ No newline at end of file diff --git a/liteyuki/resources/templates/stats.html b/liteyuki/resources/templates/stats.html index 7413525..18715e4 100644 --- a/liteyuki/resources/templates/stats.html +++ b/liteyuki/resources/templates/stats.html @@ -7,7 +7,6 @@ Liteyuki Stats -