mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🚀 增加资源下载选项及异常处理优化
This commit is contained in:
parent
ec6ad1408e
commit
a6c9134aa0
@ -2,12 +2,24 @@ from nonebot.adapters import Bot
|
|||||||
from nonebot.permission import SUPERUSER
|
from nonebot.permission import SUPERUSER
|
||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
from nonebot.rule import to_me
|
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 nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
from zhenxun.utils.enum import PluginType
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.utils.manager.resource_manager import (
|
||||||
|
DownloadResourceException,
|
||||||
|
ResourceManager,
|
||||||
|
)
|
||||||
from zhenxun.utils.message import MessageUtils
|
from zhenxun.utils.message import MessageUtils
|
||||||
|
|
||||||
from ._data_source import UpdateManage
|
from ._data_source import UpdateManage
|
||||||
@ -19,7 +31,11 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
usage:
|
usage:
|
||||||
检查更新真寻最新版本,包括了自动更新
|
检查更新真寻最新版本,包括了自动更新
|
||||||
指令:
|
指令:
|
||||||
检查更新真寻
|
检查更新 [main|release] ?[-r]
|
||||||
|
-r: 下载资源文件
|
||||||
|
示例:
|
||||||
|
检查更新 main
|
||||||
|
检查更新 main -r
|
||||||
""".strip(),
|
""".strip(),
|
||||||
extra=PluginExtraData(
|
extra=PluginExtraData(
|
||||||
author="HibiKier",
|
author="HibiKier",
|
||||||
@ -37,7 +53,11 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
)
|
)
|
||||||
|
|
||||||
_matcher = on_alconna(
|
_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,
|
priority=1,
|
||||||
block=True,
|
block=True,
|
||||||
permission=SUPERUSER,
|
permission=SUPERUSER,
|
||||||
@ -46,7 +66,13 @@ _matcher = on_alconna(
|
|||||||
|
|
||||||
|
|
||||||
@_matcher.handle()
|
@_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:
|
if not session.id1:
|
||||||
await MessageUtils.build_message("用户id为空...").finish()
|
await MessageUtils.build_message("用户id为空...").finish()
|
||||||
if not ver_type.available:
|
if not ver_type.available:
|
||||||
@ -58,6 +84,10 @@ async def _(bot: Bot, session: EventSession, ver_type: Match[str]):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("版本更新失败...", "检查更新", session=session, e=e)
|
logger.error("版本更新失败...", "检查更新", session=session, e=e)
|
||||||
await MessageUtils.build_message(f"更新版本失败...e: {e}").finish()
|
await MessageUtils.build_message(f"更新版本失败...e: {e}").finish()
|
||||||
|
try:
|
||||||
|
await ResourceManager.init_resources(True)
|
||||||
|
except DownloadResourceException:
|
||||||
|
result += "\n资源更新下载失败..."
|
||||||
if result:
|
if result:
|
||||||
await MessageUtils.build_message(result).finish()
|
await MessageUtils.build_message(result).finish()
|
||||||
await MessageUtils.build_message("更新版本失败...").finish()
|
await MessageUtils.build_message("更新版本失败...").finish()
|
||||||
|
|||||||
@ -11,10 +11,6 @@ from zhenxun.services.log import logger
|
|||||||
from zhenxun.utils.github_utils import GithubUtils
|
from zhenxun.utils.github_utils import GithubUtils
|
||||||
from zhenxun.utils.github_utils.models import RepoInfo
|
from zhenxun.utils.github_utils.models import RepoInfo
|
||||||
from zhenxun.utils.http_utils import AsyncHttpx
|
from zhenxun.utils.http_utils import AsyncHttpx
|
||||||
from zhenxun.utils.manager.resource_manager import (
|
|
||||||
DownloadResourceException,
|
|
||||||
ResourceManager,
|
|
||||||
)
|
|
||||||
from zhenxun.utils.platform import PlatformUtils
|
from zhenxun.utils.platform import PlatformUtils
|
||||||
|
|
||||||
from .config import (
|
from .config import (
|
||||||
@ -159,7 +155,7 @@ class UpdateManage:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@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("下载真寻最新版文件完成...", "检查更新")
|
logger.debug("下载真寻最新版文件完成...", "检查更新")
|
||||||
await _file_handle(new_version)
|
await _file_handle(new_version)
|
||||||
result = "版本更新完成\n"
|
result = "版本更新完成\n"
|
||||||
try:
|
|
||||||
await ResourceManager.init_resources(True)
|
|
||||||
except DownloadResourceException:
|
|
||||||
result += "资源下载失败..."
|
|
||||||
return (
|
return (
|
||||||
f"{result}\n"
|
f"{result}\n"
|
||||||
f"版本: {cur_version} -> {new_version}\n"
|
f"版本: {cur_version} -> {new_version}\n"
|
||||||
@ -219,7 +211,7 @@ class UpdateManage:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.debug("下载真寻最新版文件失败...", "检查更新")
|
logger.debug("下载真寻最新版文件失败...", "检查更新")
|
||||||
return None
|
return ""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __get_version(cls) -> str:
|
def __get_version(cls) -> str:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user