From 2306ebf3f608db6f73c0e4fe3da961f589b5958c Mon Sep 17 00:00:00 2001 From: Rikki Date: Sun, 9 Mar 2025 03:15:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=A0=E4=B8=BA=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E4=B8=B4=E7=95=8C=E7=89=88=E6=9C=AC=E8=8C=83=E5=9B=B4=E6=AF=94?= =?UTF-8?q?=E8=BE=83=E9=BA=BB=E7=83=A6=EF=BC=8C=E5=A2=9E=E5=8A=A0=20notice?= =?UTF-8?q?=20=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=88=A0=E9=99=A4=E5=8E=9F?= =?UTF-8?q?=E6=9C=AC=E7=9A=84=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=EF=BC=88?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=95=85=E9=9A=9C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/config.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/chat/config.py b/src/plugins/chat/config.py index 8675ca9ee..492efa909 100644 --- a/src/plugins/chat/config.py +++ b/src/plugins/chat/config.py @@ -251,6 +251,10 @@ class BotConfig: config.enable_kuuki_read = others_config.get("enable_kuuki_read", config.enable_kuuki_read) # 版本表达式:>=1.0.0,<2.0.0 + # 允许字段:func: method, support: str, notice: str + # 如果使用 notice 字段,在该组配置加载时,会展示该字段对用户的警示 + # 例如:"notice": "personality 将在 1.3.2 后被移除",那么在有效版本中的用户就会虽然可以 + # 正常执行程序,但是会看到这条自定义提示 include_configs = { "personality": { "func": personality, @@ -313,22 +317,20 @@ class BotConfig: # 如果在配置中找到了需要的项,调用对应项的闭包函数处理 for key in include_configs: if key in toml_dict: - group_specifierset: SpecifierSet = toml_dict[key]["support"] + group_specifierset: SpecifierSet = include_configs[key]["support"] # 检查配置文件版本是否在支持范围内 if config.INNER_VERSION in group_specifierset: # 如果版本在支持范围内,检查是否在支持的末端 - if config.INNER_VERSION == group_specifierset.filter([config.INNER_VERSION])[-1]: - logger.warning( - f"配置文件中的 '{key}' 字段的版本 ({config.INNER_VERSION}) 已接近支持范围的末端。\n" - f"未来版本可能会移除对该字段的支持。" - ) + if 'notice' in include_configs[key]: + logger.warning(include_configs[key]["notice"]) + include_configs[key]["func"](toml_dict) else: # 如果版本不在支持范围内,崩溃并提示用户 logger.error( - f"配置文件中的 '{key}' 字段的版本 ({config_version}) 不在支持范围内。\n" + f"配置文件中的 '{key}' 字段的版本 ({config.INNER_VERSION}) 不在支持范围内。\n" f"当前程序仅支持以下版本范围: {group_specifierset}" ) exit(1)