From 99266ea57913663f9880c512726c42cb7e5e7f28 Mon Sep 17 00:00:00 2001
From: yj <2077506045@qq.com>
Date: 星期一, 28 七月 2025 11:14:28 +0800
Subject: [PATCH] 新增忽略好友消息;删除多余文件

---
 config.py |   85 +++++++++++++++++++++++++++++-------------
 1 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/config.py b/config.py
index ae16800..c9792f3 100644
--- a/config.py
+++ b/config.py
@@ -3,44 +3,75 @@
 """
 
 import os
-from typing import Optional
-from pydantic_settings import BaseSettings
+import json
 
 
-class Settings(BaseSettings):
+class Settings:
     """搴旂敤閰嶇疆"""
 
-    # 鏁版嵁搴撻厤缃�
-    database_url: str = "mysql+pymysql://root:TAI%402019%23Zjun@120.24.39.179:3306/ecloud_dify"
+    def __init__(self, config_file: str = "config.json"):
+        """鍒濆鍖栭厤缃紝浠嶫SON鏂囦欢鍔犺浇"""
+        self.config_file = config_file
+        self._load_config()
 
-    # Redis閰嶇疆
-    redis_url: str = "redis://localhost:6379/0"
+    def _load_config(self):
+        """浠嶫SON鏂囦欢鍔犺浇閰嶇疆"""
+        if not os.path.exists(self.config_file):
+            raise FileNotFoundError(f"閰嶇疆鏂囦欢 {self.config_file} 涓嶅瓨鍦�")
 
-    # E浜戠瀹堕厤缃�
-    ecloud_base_url: str = "http://your-ecloud-domain.com"
-    ecloud_authorization: str = "your-authorization-token"
+        try:
+            with open(self.config_file, 'r', encoding='utf-8') as f:
+                config_data = json.load(f)
+            self._set_config_from_dict(config_data)
+        except Exception as e:
+            raise Exception(f"鍔犺浇閰嶇疆鏂囦欢澶辫触: {e}")
 
-    # DifyAI閰嶇疆
-    dify_base_url: str = "https://api.dify.ai/v1"
-    dify_api_key: str = "your-dify-api-key"
+    def _set_config_from_dict(self, config_data: dict):
+        """浠庡瓧鍏歌缃厤缃�"""
+        # 鏁版嵁搴撻厤缃�
+        self.database_url = config_data["database"]["url"]
 
-    # 鏈嶅姟閰嶇疆
-    server_host: str = "0.0.0.0"
-    server_port: int = 8000
-    debug: bool = True
+        # Redis閰嶇疆
+        self.redis_url = config_data["redis"]["url"]
 
-    # 鏃ュ織閰嶇疆
-    log_level: str = "INFO"
-    log_file: str = "logs/app.log"
+        # E浜戠瀹堕厤缃�
+        ecloud_config = config_data["ecloud"]
+        self.ecloud_base_url = ecloud_config["base_url"]
+        self.ecloud_authorization = ecloud_config["authorization"]
+        self.ecloud_w_id = ecloud_config["w_id"]
 
-    # 娑堟伅澶勭悊閰嶇疆
-    max_retry_count: int = 3
-    retry_delay: int = 5  # 绉�
-    queue_timeout: int = 300  # 绉�
+        # DifyAI閰嶇疆
+        dify_config = config_data["dify"]
+        self.dify_base_url = dify_config["base_url"]
+        self.dify_api_key = dify_config["api_key"]
+        self.dify_streaming_enabled = dify_config["streaming_enabled"]
+        self.dify_streaming_timeout = dify_config["streaming_timeout"]
 
-    class Config:
-        env_file = ".env"
-        env_file_encoding = "utf-8"
+        # 鏈嶅姟閰嶇疆
+        server_config = config_data["server"]
+        self.server_host = server_config["host"]
+        self.server_port = server_config["port"]
+        self.debug = server_config["debug"]
+
+        # 鏃ュ織閰嶇疆
+        logging_config = config_data["logging"]
+        self.log_level = logging_config["level"]
+        self.log_file = logging_config["file"]
+
+        # 娑堟伅澶勭悊閰嶇疆
+        msg_config = config_data["message_processing"]
+        self.max_retry_count = msg_config["max_retry_count"]
+        self.retry_delay = msg_config["retry_delay"]
+        self.queue_timeout = msg_config["queue_timeout"]
+
+        # 瀹㈡湇閰嶇疆
+        customer_service_config = config_data["customer_service"]
+        self.customer_service_names = customer_service_config["names"]
+
+        # 濂藉弸蹇界暐閰嶇疆
+        friend_ignore_config = config_data["friend_ignore"]
+        self.friend_ignore_enabled = friend_ignore_config["enabled"]
+        self.friend_ignore_whitelist = friend_ignore_config["whitelist"]
 
 
 # 鍏ㄥ眬閰嶇疆瀹炰緥

--
Gitblit v1.9.1