Files
NeoBot/core/config_models.py
K2cr2O1 0bca97424b feat(图片管理): 添加图片尺寸配置支持
在 config.toml 中新增 image_manager 配置块,包含图片高度和宽度设置
修改 ImageManager 类以使用配置中的尺寸,替代硬编码值
添加 ImageManagerModel 配置模型并集成到全局配置中
2026-02-28 16:17:20 +08:00

71 lines
1.7 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 RedisModel(BaseModel):
"""
对应 `config.toml` 中的 `[redis]` 配置块。
"""
host: str
port: int
db: int
password: str
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 ConfigModel(BaseModel):
"""
顶层配置模型,整合了所有子配置块。
"""
napcat_ws: NapCatWSModel
bot: BotModel
redis: RedisModel
docker: DockerModel
image_manager: ImageManagerModel