✨ 资源下载分离 (#1814)

* 🚀 资源文件单独下载,分离被动任务初始化

* 🔥 移除resources文件夹

* 🚀 优化版本更新逻辑,增加资源下载异常处理

* 🚀 增加资源下载失败异常处理及提示信息

* 🚀 增加资源下载选项及异常处理优化

* 🚀 移除空ID检查及资源更新条件处理

* ✨ 简易配置中未加载的配置将被移除

* 🐛 测试更新

* ✨ 修复更新完成消息格式

---------

Co-authored-by: Flern <cb56ec362bbbfb5272eb941281299d8d-qq_connect@git.osc>
This commit is contained in:
HibiKier
2025-01-06 11:32:56 +08:00
committed by GitHub
co-authored by Flern
parent 91dce56bf8
commit ec70144d7e
308 changed files with 397 additions and 38881 deletions
+57 -23
View File
@@ -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.configs.utils import PluginExtraData
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
@@ -18,26 +30,32 @@ __plugin_meta__ = PluginMetadata(
usage="""
usage:
检查更新真寻最新版本,包括了自动更新
资源文件大小一般在130mb左右,除非必须更新一般仅更新代码文件
指令:
检查更新真寻
检查更新 [main|release|resource] ?[-r]
main: main分支
release: 最新release
resource: 资源文件
-r: 下载资源文件,一般在更新main或release时使用
示例:
检查更新 main
检查更新 main -r
检查更新 release -r
检查更新 resource
""".strip(),
extra=PluginExtraData(
author="HibiKier",
version="0.1",
plugin_type=PluginType.SUPERUSER,
configs=[
RegisterConfig(
key="UPDATE_REMIND",
value=True,
help="是否检测更新版本",
default_value=True,
),
],
).dict(),
)
_matcher = on_alconna(
Alconna("检查更新", Args["ver_type?", ["main", "dev", "release"]]),
Alconna(
"检查更新",
Args["ver_type?", ["main", "release", "resource"]],
Option("-r|--resource", action=store_true, help_text="下载资源文件"),
),
priority=1,
block=True,
permission=SUPERUSER,
@@ -46,18 +64,34 @@ _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),
):
if not session.id1:
await MessageUtils.build_message("用户id为空...").finish()
if not ver_type.available:
result = await UpdateManage.check_version()
logger.info("查看当前版本...", "检查更新", session=session)
await MessageUtils.build_message(result).finish()
try:
result = await UpdateManage.update(bot, session.id1, ver_type.result)
except Exception as e:
logger.error("版本更新失败...", "检查更新", session=session, e=e)
await MessageUtils.build_message(f"更新版本失败...e: {e}").finish()
result = ""
if ver_type.result in {"main", "release"}:
if not ver_type.available:
result = await UpdateManage.check_version()
logger.info("查看当前版本...", "检查更新", session=session)
await MessageUtils.build_message(result).finish()
try:
result = await UpdateManage.update(bot, session.id1, ver_type.result)
except Exception as e:
logger.error("版本更新失败...", "检查更新", session=session, e=e)
await MessageUtils.build_message(f"更新版本失败...e: {e}").finish()
if resource.result or ver_type.result == "resource":
try:
await ResourceManager.init_resources(True)
result += "\n资源文件更新成功!"
except DownloadResourceException:
result += "\n资源更新下载失败..."
except Exception as e:
logger.error("资源更新下载失败...", "检查更新", session=session, e=e)
result += "\n资源更新未知错误..."
if result:
await MessageUtils.build_message(result).finish()
await MessageUtils.build_message(result.strip()).finish()
await MessageUtils.build_message("更新版本失败...").finish()