From b8bc0e3381563555e56517bd60f7fa3262319e08 Mon Sep 17 00:00:00 2001 From: K2Cr2O1 <2221577113@qq.com> Date: Mon, 23 Mar 2026 20:55:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E8=BF=9B=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当配置文件不存在时自动生成示例配置 添加pyproject.toml作为项目构建配置 更新.gitignore忽略更多文件类型 删除不再使用的反向WebSocket示例文件 --- core/config_loader.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/config_loader.py b/core/config_loader.py index f2b506f..ad332aa 100644 --- a/core/config_loader.py +++ b/core/config_loader.py @@ -38,10 +38,10 @@ class Config: :raises ConfigError: 如果加载配置时发生其他错误 """ if not self.path.exists(): - error = ConfigNotFoundError(message=f"配置文件 {self.path} 未找到!") - self.logger.error(f"配置加载失败: {error.message}") - self.logger.log_custom_exception(error) - raise error + self.logger.warning(f"配置文件 {self.path} 未找到,正在生成示例配置...") + self._generate_example_config() + self.logger.success(f"示例配置已生成: {self.path}") + self.logger.info("请编辑配置文件后重新启动程序") try: self.logger.info(f"正在从 {self.path} 加载配置...") @@ -86,6 +86,19 @@ class Config: self.logger.log_custom_exception(error) raise error + def _generate_example_config(self): + """ + 生成示例配置文件 + """ + example_path = Path("config.example.toml") + + if not example_path.exists(): + self.logger.error(f"示例配置文件 {example_path} 不存在,无法生成配置") + raise ConfigNotFoundError(message=f"示例配置文件 {example_path} 不存在") + + content = example_path.read_text() + self.path.write_text(content) + # 通过属性访问配置 @property def napcat_ws(self) -> NapCatWSModel: