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:
@@ -4,9 +4,9 @@
|
||||
定义了消息相关的事件类,包括 MessageEvent, PrivateMessageEvent, GroupMessageEvent。
|
||||
"""
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from core.managers.permission_manager import ADMIN, OP, USER
|
||||
from core.permission import Permission
|
||||
from models.message import MessageSegment
|
||||
from models.sender import Sender
|
||||
from .base import OneBotEvent, EventType
|
||||
@@ -34,9 +34,9 @@ class MessageEvent(OneBotEvent):
|
||||
"""
|
||||
|
||||
# 权限级别常量,用于装饰器参数
|
||||
ADMIN = ADMIN
|
||||
OP = OP
|
||||
USER = USER
|
||||
ADMIN = Permission.ADMIN
|
||||
OP = Permission.OP
|
||||
USER = Permission.USER
|
||||
|
||||
message_type: str
|
||||
"""消息类型: private (私聊), group (群聊)"""
|
||||
@@ -70,7 +70,7 @@ class MessageEvent(OneBotEvent):
|
||||
def post_type(self) -> str:
|
||||
return EventType.MESSAGE
|
||||
|
||||
async def reply(self, message: str, auto_escape: bool = False):
|
||||
async def reply(self, message: Union[str, "MessageSegment", List["MessageSegment"]], auto_escape: bool = False):
|
||||
"""
|
||||
回复消息(抽象方法,由子类实现)
|
||||
|
||||
@@ -86,7 +86,7 @@ class PrivateMessageEvent(MessageEvent):
|
||||
私聊消息事件
|
||||
"""
|
||||
|
||||
async def reply(self, message: str, auto_escape: bool = False):
|
||||
async def reply(self, message: Union[str, "MessageSegment", List["MessageSegment"]], auto_escape: bool = False):
|
||||
"""
|
||||
回复私聊消息
|
||||
|
||||
@@ -110,7 +110,7 @@ class GroupMessageEvent(MessageEvent):
|
||||
anonymous: Optional[Anonymous] = None
|
||||
"""匿名信息"""
|
||||
|
||||
async def reply(self, message: str, auto_escape: bool = False):
|
||||
async def reply(self, message: Union[str, "MessageSegment", List["MessageSegment"]], auto_escape: bool = False):
|
||||
"""
|
||||
回复群聊消息
|
||||
|
||||
|
||||
Reference in New Issue
Block a user