refactor(config): 移除.env依赖并引入服务器配置模型

将项目配置系统从依赖.env文件和环境变量迁移到使用Pydantic模型进行集中管理。此举通过移除`python-dotenv`库简化了环境设置,并提高了配置的类型安全性和可维护性。

主要变更包括:
- 移除`bot.py`中的.env加载逻辑。
- 新增`ServerConfig`模型来管理服务器的主机和端口。
- 更新`src/common/server.py`和`src/common/message/api.py`以从全局配置对象获取服务器设置,取代了`os.environ`。
- 从配置中移除了已废弃的`MaizoneIntercomConfig`。
- 在`bot_config_template.toml`中添加了新的`[server]`配置部分。
This commit is contained in:
minecraft1024a
2025-09-12 19:04:27 +08:00
committed by Windpicker-owo
parent 212fb0a449
commit 26e20b2cd7
6 changed files with 17 additions and 27 deletions

View File

@@ -2,7 +2,7 @@ from fastapi import FastAPI, APIRouter
from fastapi.middleware.cors import CORSMiddleware # 新增导入
from typing import Optional
from uvicorn import Config, Server as UvicornServer
import os
from src.config.config import global_config
from rich.traceback import install
install(extra_lines=3)
@@ -98,5 +98,5 @@ def get_global_server() -> Server:
"""获取全局服务器实例"""
global global_server
if global_server is None:
global_server = Server(host=os.environ["HOST"], port=int(os.environ["PORT"]))
global_server = Server(host=global_config.server.host,port=int(global_config.server.port),)
return global_server