feat: 重构核心架构,增强类型安全与插件管理
本次提交对核心模块进行了深度重构,引入 Pydantic 增强配置管理的类型安全性,并全面优化了插件管理系统。 主要变更详情: 1. 核心架构与配置 - 重构配置加载模块:引入 Pydantic 模型 (`core/config_models.py`),提供严格的配置项类型检查、验证及默认值管理。 - 统一模块结构:规范化模块导入路径,移除冗余的 `__init__.py` 文件,提升项目结构的清晰度。 - 性能优化:集成 Redis 缓存支持 (`RedisManager`),有效降低高频 API 调用开销,提升响应速度。 2. 插件系统升级 - 实现热重载机制:新增插件文件变更监听功能,支持开发过程中自动重载插件,提升开发效率。 - 优化生命周期管理:改进插件加载与卸载逻辑,支持精确卸载指定插件及其关联的命令、事件处理器和定时任务。 3. 功能特性增强 - 新增媒体 API:引入 `MediaAPI` 模块,封装图片、语音等富媒体资源的获取与处理接口。 - 完善权限体系:重构权限管理系统,实现管理员与操作员的分级控制,支持更细粒度的命令权限校验。 4. 代码质量与稳定性 - 全面类型修复:解决 `mypy` 静态类型检查发现的大量类型错误(包括 `CommandManager`、`EventFactory` 及 `Bot` API 签名不匹配问题)。 - 增强错误处理:优化消息处理管道的异常捕获机制,完善关键路径的日志记录,提升系统运行稳定性。
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -76,7 +76,7 @@ class MessageSegment:
|
||||
return self.data.get("file", "")
|
||||
return ""
|
||||
|
||||
def is_at(self, user_id: int = None) -> bool:
|
||||
def is_at(self, user_id: Optional[int] = None) -> bool:
|
||||
"""
|
||||
检查当前消息段是否是一个 'at' (提及) 消息段。
|
||||
|
||||
@@ -102,7 +102,7 @@ class MessageSegment:
|
||||
# --- 快捷构造方法 ---
|
||||
|
||||
@staticmethod
|
||||
def text(text: str) -> "MessageSegment": # noqa: F811
|
||||
def from_text(text: str) -> "MessageSegment":
|
||||
"""
|
||||
创建一个文本消息段。
|
||||
|
||||
@@ -115,7 +115,7 @@ class MessageSegment:
|
||||
return MessageSegment(type="text", data={"text": text})
|
||||
|
||||
@staticmethod
|
||||
def at(user_id: int | str, name: str = None) -> "MessageSegment":
|
||||
def at(user_id: int | str, name: Optional[str] = None) -> "MessageSegment":
|
||||
"""
|
||||
创建一个 @某人 的消息段。
|
||||
|
||||
@@ -132,7 +132,7 @@ class MessageSegment:
|
||||
return MessageSegment(type="at", data=data)
|
||||
|
||||
@staticmethod
|
||||
def image(file: str, image_type: str = None, cache: bool = True, proxy: bool = True, timeout: int = None, sub_type: int = None) -> "MessageSegment":
|
||||
def image(file: str, image_type: Optional[str] = None, cache: bool = True, proxy: bool = True, timeout: Optional[int] = None, sub_type: Optional[int] = None) -> "MessageSegment":
|
||||
"""
|
||||
创建一个图片消息段。
|
||||
|
||||
@@ -194,7 +194,7 @@ class MessageSegment:
|
||||
"""
|
||||
return MessageSegment(type="xml", data={"data": data})
|
||||
@staticmethod
|
||||
def share(url: str, title: str, content: str = None, image: str = None) -> "MessageSegment":
|
||||
def share(url: str, title: str, content: Optional[str] = None, image: Optional[str] = None) -> "MessageSegment":
|
||||
"""
|
||||
创建一个分享消息段。
|
||||
|
||||
@@ -227,7 +227,7 @@ class MessageSegment:
|
||||
"""
|
||||
return MessageSegment(type="music", data={"type": type, "id": id})
|
||||
@staticmethod
|
||||
def music_custom(url: str, audio: str, title: str, content: str = None, image: str = None) -> "MessageSegment":
|
||||
def music_custom(url: str, audio: str, title: str, content: Optional[str] = None, image: Optional[str] = None) -> "MessageSegment":
|
||||
"""
|
||||
创建一个自定义音乐消息段。
|
||||
|
||||
@@ -248,7 +248,7 @@ class MessageSegment:
|
||||
data["image"] = image
|
||||
return MessageSegment(type="music", data={"type": "custom", **data})
|
||||
@staticmethod
|
||||
def record(file: str, magic: bool = False, cache: bool = True, proxy: bool = True, timeout: int = None) -> "MessageSegment":
|
||||
def record(file: str, magic: bool = False, cache: bool = True, proxy: bool = True, timeout: Optional[int] = None) -> "MessageSegment":
|
||||
"""
|
||||
创建一个语音消息段。
|
||||
|
||||
@@ -267,7 +267,7 @@ class MessageSegment:
|
||||
data["timeout"] = str(timeout)
|
||||
return MessageSegment(type="record", data=data)
|
||||
@staticmethod
|
||||
def video(file: str, cover: str = None, c: int = 2) -> "MessageSegment":
|
||||
def video(file: str, cover: Optional[str] = None, c: int = 2) -> "MessageSegment":
|
||||
"""
|
||||
创建一个视频消息段。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user