from abc import ABC, abstractmethod from typing import Any, Dict, Optional class BaseHandler(ABC): """ 命令处理器抽象基类 定义所有命令处理器需要实现的基本方法 """ @abstractmethod def handle_command(self, command: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: """ 处理命令 Args: command: 命令类型 data: 命令数据 Returns: Dict[str, Any]: 处理结果 """ pass @abstractmethod def register_command(self, command: str, handler_func) -> bool: """ 注册命令处理函数 Args: command: 命令类型 handler_func: 处理函数 Returns: bool: 注册是否成功 """ pass @abstractmethod def unregister_command(self, command: str) -> bool: """ 注销命令处理函数 Args: command: 命令类型 Returns: bool: 注销是否成功 """ pass