From 30356f5fdb9c5374ee96a6d585178a60f2c82488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com> Date: Thu, 19 Jun 2025 00:20:37 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=AD=A3=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=B7=AF=E5=BE=84=E7=9A=84=E5=AE=9A=E4=B9=89=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E4=BD=BF=E7=94=A8os.path.join=E4=BB=A5?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E8=B7=A8=E5=B9=B3=E5=8F=B0=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/config.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/config/config.py b/src/config/config.py index 67a8b6a25..3dab769d1 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -43,8 +43,10 @@ install(extra_lines=3) # 配置主程序日志格式 logger = get_logger("config") -CONFIG_DIR = "config" -TEMPLATE_DIR = "template" +# 获取当前文件所在目录的父目录的父目录(即MaiBot项目根目录) +PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) +CONFIG_DIR = os.path.join(PROJECT_ROOT, "config") +TEMPLATE_DIR = os.path.join(PROJECT_ROOT, "template") # 考虑到,实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码 # 对该字段的更新,请严格参照语义化版本规范:https://semver.org/lang/zh-CN/ @@ -53,12 +55,12 @@ MMC_VERSION = "0.8.0-snapshot.1" def update_config(): # 获取根目录路径 - old_config_dir = f"{CONFIG_DIR}/old" + old_config_dir = os.path.join(CONFIG_DIR, "old") # 定义文件路径 - template_path = f"{TEMPLATE_DIR}/bot_config_template.toml" - old_config_path = f"{CONFIG_DIR}/bot_config.toml" - new_config_path = f"{CONFIG_DIR}/bot_config.toml" + template_path = os.path.join(TEMPLATE_DIR, "bot_config_template.toml") + old_config_path = os.path.join(CONFIG_DIR, "bot_config.toml") + new_config_path = os.path.join(CONFIG_DIR, "bot_config.toml") # 检查配置文件是否存在 if not os.path.exists(old_config_path): @@ -88,11 +90,9 @@ def update_config(): logger.info("已有配置文件未检测到版本号,可能是旧版本。将进行更新") # 创建old目录(如果不存在) - os.makedirs(old_config_dir, exist_ok=True) - - # 生成带时间戳的新文件名 + os.makedirs(old_config_dir, exist_ok=True) # 生成带时间戳的新文件名 timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") - old_backup_path = f"{old_config_dir}/bot_config_{timestamp}.toml" + old_backup_path = os.path.join(old_config_dir, f"bot_config_{timestamp}.toml") # 移动旧配置文件到old目录 shutil.move(old_config_path, old_backup_path) @@ -198,5 +198,5 @@ logger.info(f"MaiCore当前版本: {MMC_VERSION}") update_config() logger.info("正在品鉴配置文件...") -global_config = load_config(config_path=f"{CONFIG_DIR}/bot_config.toml") +global_config = load_config(config_path=os.path.join(CONFIG_DIR, "bot_config.toml")) logger.info("非常的新鲜,非常的美味!")