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
ea613ce176
commit
062001cd51
23
.gitignore
vendored
23
.gitignore
vendored
@ -153,29 +153,8 @@ extensive_plugin/
|
|||||||
test/
|
test/
|
||||||
bot.py
|
bot.py
|
||||||
.idea/
|
.idea/
|
||||||
/resources/text/
|
resources/
|
||||||
# /resources/image/
|
|
||||||
/resources/temp/
|
|
||||||
/resources/image/genshin/
|
|
||||||
/resources/image/draw_card/
|
|
||||||
/resources/image/card/
|
|
||||||
/resources/image/temp/
|
|
||||||
/resources/image/sign/today_card/
|
|
||||||
/resources/image/image_management/
|
|
||||||
/resources/image/bilibili_sub/
|
|
||||||
/resources/image/other/
|
|
||||||
/resources/image/_setu/
|
|
||||||
/resources/image/_r18/
|
|
||||||
/resources/image/csgo_cases/
|
|
||||||
!/resources/image/csgo_cases/_background/
|
|
||||||
/resources/image/superuser_help.png
|
|
||||||
/resources/image/update_img_help.png
|
|
||||||
/resources/image/prts/
|
|
||||||
/configs/config.py
|
/configs/config.py
|
||||||
configs/config.yaml
|
configs/config.yaml
|
||||||
plugins/csgo_server/
|
|
||||||
plugins/activity/
|
|
||||||
!/resources/image/genshin/alc/back.png
|
|
||||||
!/data/genshin_alc/
|
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
plugins_/
|
plugins_/
|
||||||
@ -13,7 +13,7 @@ from nonebot_plugin_alconna import (
|
|||||||
)
|
)
|
||||||
from nonebot_plugin_uninfo import Uninfo
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
|
|
||||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
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 (
|
from zhenxun.utils.manager.resource_manager import (
|
||||||
@ -30,25 +30,19 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
usage="""
|
usage="""
|
||||||
usage:
|
usage:
|
||||||
检查更新真寻最新版本,包括了自动更新
|
检查更新真寻最新版本,包括了自动更新
|
||||||
|
资源文件大小一般在130mb左右,除非必须更新一般仅更新代码文件
|
||||||
指令:
|
指令:
|
||||||
检查更新 [main|release] ?[-r]
|
检查更新 [main|release] ?[-r]
|
||||||
-r: 下载资源文件
|
-r: 下载资源文件
|
||||||
示例:
|
示例:
|
||||||
检查更新 main
|
检查更新 main
|
||||||
检查更新 main -r
|
检查更新 main -r
|
||||||
|
检查更新 release -r
|
||||||
""".strip(),
|
""".strip(),
|
||||||
extra=PluginExtraData(
|
extra=PluginExtraData(
|
||||||
author="HibiKier",
|
author="HibiKier",
|
||||||
version="0.1",
|
version="0.1",
|
||||||
plugin_type=PluginType.SUPERUSER,
|
plugin_type=PluginType.SUPERUSER,
|
||||||
configs=[
|
|
||||||
RegisterConfig(
|
|
||||||
key="UPDATE_REMIND",
|
|
||||||
value=True,
|
|
||||||
help="是否检测更新版本",
|
|
||||||
default_value=True,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).dict(),
|
).dict(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -87,6 +81,9 @@ async def _(
|
|||||||
await ResourceManager.init_resources(True)
|
await ResourceManager.init_resources(True)
|
||||||
except DownloadResourceException:
|
except DownloadResourceException:
|
||||||
result += "\n资源更新下载失败..."
|
result += "\n资源更新下载失败..."
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("资源更新下载失败...", "检查更新", session=session, e=e)
|
||||||
|
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()
|
||||||
|
|||||||
@ -25,7 +25,7 @@ if old_config_file.exists():
|
|||||||
old_config_file.rename(SIMPLE_CONFIG_FILE)
|
old_config_file.rename(SIMPLE_CONFIG_FILE)
|
||||||
|
|
||||||
|
|
||||||
def _handle_config(plugin: Plugin):
|
def _handle_config(plugin: Plugin, exists_module: list[str]):
|
||||||
"""处理配置项
|
"""处理配置项
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
@ -49,9 +49,10 @@ def _handle_config(plugin: Plugin):
|
|||||||
arg_parser=reg_config.arg_parser,
|
arg_parser=reg_config.arg_parser,
|
||||||
_override=False,
|
_override=False,
|
||||||
)
|
)
|
||||||
|
exists_module.append(f"{module}:{reg_config.key}")
|
||||||
|
|
||||||
|
|
||||||
def _generate_simple_config():
|
def _generate_simple_config(exists_module: list[str]):
|
||||||
"""
|
"""
|
||||||
生成简易配置
|
生成简易配置
|
||||||
|
|
||||||
@ -70,9 +71,12 @@ def _generate_simple_config():
|
|||||||
try:
|
try:
|
||||||
if _data.get(module) and k in _data[module].keys():
|
if _data.get(module) and k in _data[module].keys():
|
||||||
Config.set_config(module, k, _data[module][k])
|
Config.set_config(module, k, _data[module][k])
|
||||||
_tmp_data[module][k] = Config.get_config(module, k)
|
if f"{module}:{k}" in exists_module:
|
||||||
|
_tmp_data[module][k] = Config.get_config(module, k)
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
raise AttributeError(f"{e}\n可能为config.yaml配置文件填写不规范") from e
|
raise AttributeError(f"{e}\n可能为config.yaml配置文件填写不规范") from e
|
||||||
|
if not _tmp_data[module]:
|
||||||
|
_tmp_data.pop(module)
|
||||||
Config.save()
|
Config.save()
|
||||||
temp_file = DATA_PATH / "temp_config.yaml"
|
temp_file = DATA_PATH / "temp_config.yaml"
|
||||||
# 重新生成简易配置文件
|
# 重新生成简易配置文件
|
||||||
@ -103,9 +107,10 @@ def _():
|
|||||||
初始化插件数据配置
|
初始化插件数据配置
|
||||||
"""
|
"""
|
||||||
plugins2config_file = DATA_PATH / "configs" / "plugins2config.yaml"
|
plugins2config_file = DATA_PATH / "configs" / "plugins2config.yaml"
|
||||||
|
exists_module = []
|
||||||
for plugin in get_loaded_plugins():
|
for plugin in get_loaded_plugins():
|
||||||
if plugin.metadata:
|
if plugin.metadata:
|
||||||
_handle_config(plugin)
|
_handle_config(plugin, exists_module)
|
||||||
if not Config.is_empty():
|
if not Config.is_empty():
|
||||||
Config.save()
|
Config.save()
|
||||||
_data: CommentedMap = _yaml.load(plugins2config_file.open(encoding="utf8"))
|
_data: CommentedMap = _yaml.load(plugins2config_file.open(encoding="utf8"))
|
||||||
@ -118,4 +123,4 @@ def _():
|
|||||||
# 存完插件基本设置
|
# 存完插件基本设置
|
||||||
with plugins2config_file.open("w", encoding="utf8") as wf:
|
with plugins2config_file.open("w", encoding="utf8") as wf:
|
||||||
_yaml.dump(_data, wf)
|
_yaml.dump(_data, wf)
|
||||||
_generate_simple_config()
|
_generate_simple_config(exists_module)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user