From 438ba009b24a151dbc7724a2e20f36e187b498ce Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 15 Mar 2025 00:00:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=81=AB=E9=80=9F=E6=B7=BB=E5=8A=A0conf?= =?UTF-8?q?ig=E6=96=87=E4=BB=B6=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=97=B6=E5=A4=87=E4=BB=BD=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 2c99ba8fa..a9041749b 100644 --- a/webui.py +++ b/webui.py @@ -211,7 +211,18 @@ def save_trigger(server_address, server_port, final_result_list,t_mongodb_host,t #============================================== #主要配置文件保存函数 def save_config_to_file(t_config_data): - with open("config/bot_config.toml", "w", encoding="utf-8") as f: + filename = "config/bot_config.toml" + backup_filename = f"{filename}.bak" + if not os.path.exists(backup_filename): + if os.path.exists(filename): + logger.info(f"{filename} 已存在,正在备份到 {backup_filename}...") + shutil.copy(filename, backup_filename) # 备份文件 + logger.success(f"文件已备份到 {backup_filename}") + else: + logger.warning(f"{filename} 不存在,无法进行备份。") + + + with open(filename, "w", encoding="utf-8") as f: toml.dump(t_config_data, f) logger.success("配置已保存到 bot_config.toml 文件中") def save_bot_config(t_qqbot_qq, t_nickname,t_nickname_final_result):