Coverage for merco/gateway/base.py: 0%
21 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 14:04 +0800
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-07 14:04 +0800
1"""网关基类"""
3from abc import ABC, abstractmethod
4from typing import Callable
7class BaseGateway(ABC):
8 """消息平台网关基类"""
10 name: str = ""
12 def __init__(self, config: dict):
13 self.config = config
14 self._message_handler: Callable = None
16 def set_handler(self, handler: Callable):
17 """设置消息处理器"""
18 self._message_handler = handler
20 @abstractmethod
21 async def start(self):
22 """启动网关"""
23 pass
25 @abstractmethod
26 async def stop(self):
27 """停止网关"""
28 pass
30 @abstractmethod
31 async def send_message(self, chat_id: str, message: str):
32 """发送消息"""
33 pass
35 async def handle_message(self, chat_id: str, message: str):
36 """处理收到的消息"""
37 if self._message_handler:
38 await self._message_handler(chat_id, message)