From a6c9134aa01359f34c4785f80c72d883f88b1b4a Mon Sep 17 00:00:00 2001 From: Flern Date: Fri, 3 Jan 2025 11:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=E5=A2=9E=E5=8A=A0=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E4=B8=8B=E8=BD=BD=E9=80=89=E9=A1=B9=E5=8F=8A=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builtin_plugins/auto_update/__init__.py | 38 +++++++++++++++++-- .../auto_update/_data_source.py | 12 +----- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/zhenxun/builtin_plugins/auto_update/__init__.py b/zhenxun/builtin_plugins/auto_update/__init__.py index fb9eb161..fc2656a7 100644 --- a/zhenxun/builtin_plugins/auto_update/__init__.py +++ b/zhenxun/builtin_plugins/auto_update/__init__.py @@ -2,12 +2,24 @@ from nonebot.adapters import Bot from nonebot.permission import SUPERUSER from nonebot.plugin import PluginMetadata from nonebot.rule import to_me -from nonebot_plugin_alconna import Alconna, Args, Match, on_alconna +from nonebot_plugin_alconna import ( + Alconna, + Args, + Match, + Option, + Query, + on_alconna, + store_true, +) from nonebot_plugin_session import EventSession from zhenxun.configs.utils import PluginExtraData, RegisterConfig from zhenxun.services.log import logger from zhenxun.utils.enum import PluginType +from zhenxun.utils.manager.resource_manager import ( + DownloadResourceException, + ResourceManager, +) from zhenxun.utils.message import MessageUtils from ._data_source import UpdateManage @@ -19,7 +31,11 @@ __plugin_meta__ = PluginMetadata( usage: 检查更新真寻最新版本,包括了自动更新 指令: - 检查更新真寻 + 检查更新 [main|release] ?[-r] + -r: 下载资源文件 + 示例: + 检查更新 main + 检查更新 main -r """.strip(), extra=PluginExtraData( author="HibiKier", @@ -37,7 +53,11 @@ __plugin_meta__ = PluginMetadata( ) _matcher = on_alconna( - Alconna("检查更新", Args["ver_type?", ["main", "dev", "release"]]), + Alconna( + "检查更新", + Args["ver_type?", ["main", "release"]], + Option("-r|--resource", action=store_true, help_text="下载资源文件"), + ), priority=1, block=True, permission=SUPERUSER, @@ -46,7 +66,13 @@ _matcher = on_alconna( @_matcher.handle() -async def _(bot: Bot, session: EventSession, ver_type: Match[str]): +async def _( + bot: Bot, + session: EventSession, + ver_type: Match[str], + resource: Query[bool] = Query("resource", False), +): + result = "" if not session.id1: await MessageUtils.build_message("用户id为空...").finish() if not ver_type.available: @@ -58,6 +84,10 @@ async def _(bot: Bot, session: EventSession, ver_type: Match[str]): except Exception as e: logger.error("版本更新失败...", "检查更新", session=session, e=e) await MessageUtils.build_message(f"更新版本失败...e: {e}").finish() + try: + await ResourceManager.init_resources(True) + except DownloadResourceException: + result += "\n资源更新下载失败..." if result: await MessageUtils.build_message(result).finish() await MessageUtils.build_message("更新版本失败...").finish() diff --git a/zhenxun/builtin_plugins/auto_update/_data_source.py b/zhenxun/builtin_plugins/auto_update/_data_source.py index dae1926e..eee4bc7c 100644 --- a/zhenxun/builtin_plugins/auto_update/_data_source.py +++ b/zhenxun/builtin_plugins/auto_update/_data_source.py @@ -11,10 +11,6 @@ from zhenxun.services.log import logger from zhenxun.utils.github_utils import GithubUtils from zhenxun.utils.github_utils.models import RepoInfo from zhenxun.utils.http_utils import AsyncHttpx -from zhenxun.utils.manager.resource_manager import ( - DownloadResourceException, - ResourceManager, -) from zhenxun.utils.platform import PlatformUtils from .config import ( @@ -159,7 +155,7 @@ class UpdateManage: ) @classmethod - async def update(cls, bot: Bot, user_id: str, version_type: str) -> str | None: + async def update(cls, bot: Bot, user_id: str, version_type: str) -> str: """更新操作 参数: @@ -208,10 +204,6 @@ class UpdateManage: logger.debug("下载真寻最新版文件完成...", "检查更新") await _file_handle(new_version) result = "版本更新完成\n" - try: - await ResourceManager.init_resources(True) - except DownloadResourceException: - result += "资源下载失败..." return ( f"{result}\n" f"版本: {cur_version} -> {new_version}\n" @@ -219,7 +211,7 @@ class UpdateManage: ) else: logger.debug("下载真寻最新版文件失败...", "检查更新") - return None + return "" @classmethod def __get_version(cls) -> str: