Files
NeoBot/core/config_models.py
K2cr2O1 014c6c9092 feat(reverse_ws): 添加反向WebSocket支持及负载均衡功能
- 新增反向WebSocket管理器模块,支持多客户端连接
- 实现负载均衡机制,自动选择健康且负载最低的客户端
- 添加防重复事件处理机制,防止消息重复处理
- 更新配置模型和加载器以支持反向WebSocket配置
- 添加示例文件和文档说明使用方法
- 修改主程序启动逻辑以支持反向WebSocket服务
2026-02-28 20:57:48 +08:00

105 lines
2.3 KiB
Python

"""
Pydantic 配置模型模块
该模块使用 Pydantic 定义了与 `config.toml` 文件结构完全对应的配置模型。
这使得配置的加载、校验和访问都变得类型安全和健壮。
"""
from typing import List, Optional
from pydantic import BaseModel, Field
class NapCatWSModel(BaseModel):
"""
对应 `config.toml` 中的 `[napcat_ws]` 配置块。
"""
uri: str
token: str
reconnect_interval: int = 5
class BotModel(BaseModel):
"""
对应 `config.toml` 中的 `[bot]` 配置块。
"""
command: List[str] = Field(default_factory=lambda: ["/"])
ignore_self_message: bool = True
permission_denied_message: str = "权限不足,需要 {permission_name} 权限"
class ReverseWSModel(BaseModel):
"""
对应 `config.toml` 中的 `[reverse_ws]` 配置块。
"""
enabled: bool = False
host: str = "0.0.0.0"
port: int = 3002
token: Optional[str] = None
class RedisModel(BaseModel):
"""
对应 `config.toml` 中的 `[redis]` 配置块。
"""
host: str
port: int
db: int
password: str
class MySQLModel(BaseModel):
"""
对应 `config.toml` 中的 `[mysql]` 配置块。
"""
host: str
port: int
user: str
password: str
db: str
charset: str = "utf8mb4"
class DockerModel(BaseModel):
"""
对应 `config.toml` 中的 `[docker]` 配置块。
"""
base_url: Optional[str] = None
sandbox_image: str = "python-sandbox:latest"
timeout: int = 10
concurrency_limit: int = 5
tls_verify: bool = False
ca_cert_path: Optional[str] = None
client_cert_path: Optional[str] = None
client_key_path: Optional[str] = None
class ImageManagerModel(BaseModel):
"""
对应 `config.toml` 中的 `[image_manager]` 配置块。
"""
image_height: int = 1920
image_width: int = 1080
class ReverseWSModel(BaseModel):
"""
对应 `config.toml` 中的 `[reverse_ws]` 配置块。
"""
enabled: bool = False
host: str = "0.0.0.0"
port: int = 3002
token: Optional[str] = None
class ConfigModel(BaseModel):
"""
顶层配置模型,整合了所有子配置块。
"""
napcat_ws: NapCatWSModel
bot: BotModel
redis: RedisModel
mysql: MySQLModel
docker: DockerModel
image_manager: ImageManagerModel
reverse_ws: ReverseWSModel