From a4015b6b132c6cc1d204bcab745c57f8998e0460 Mon Sep 17 00:00:00 2001 From: ChangingSelf Date: Wed, 9 Apr 2025 22:25:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?docs(README):=20README=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=B5=81=E8=BD=AC=E6=97=B6=E5=BA=8F=E5=9B=BE?= =?UTF-8?q?=EF=BC=88mermaid=EF=BC=89=EF=BC=8C=E4=BB=A5=E4=BE=BF=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=80=85=E7=90=86=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index a9b1937..134bdad 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,50 @@ enable_temp = false 至于requirements,需要maim_message,安装略 +# 消息流转过程 + +```mermaid +sequenceDiagram + participant Napcat as Napcat客户端 + participant Adapter as MaiBot-Napcat适配器 + participant Queue as 消息队列 + participant Handler as 消息处理器 + participant MaiBot as MaiBot服务 + + Note over Napcat,MaiBot: 初始化阶段 + Napcat->>Adapter: WebSocket连接(ws://localhost:8095) + Adapter->>MaiBot: WebSocket连接(ws://localhost:8000) + + Note over Napcat,MaiBot: 心跳检测 + loop 每30秒 + Napcat->>Adapter: 发送心跳包 + Adapter->>Napcat: 心跳响应 + end + + Note over Napcat,MaiBot: 消息处理流程 + Napcat->>Adapter: 发送消息 + Adapter->>Queue: 消息入队(message_queue) + Queue->>Handler: 消息出队处理 + Handler->>Handler: 解析消息类型 + alt 文本消息 + Handler->>MaiBot: 发送文本消息 + else 图片消息 + Handler->>MaiBot: 发送图片消息 + else 混合消息 + Handler->>MaiBot: 发送混合消息 + else 转发消息 + Handler->>MaiBot: 发送转发消息 + end + MaiBot-->>Adapter: 消息响应 + Adapter-->>Napcat: 消息响应 + + Note over Napcat,MaiBot: 优雅关闭 + Adapter->>MaiBot: 关闭连接 + Adapter->>Queue: 清空消息队列 + Adapter->>Napcat: 关闭连接 +``` + + # TO DO List - [x] 读取自动心跳测试连接 - [x] 接受消息解析 From d1a1763dc00568374b16a9f98115d1ee56c22143 Mon Sep 17 00:00:00 2001 From: Dreamwxz Date: Fri, 11 Apr 2025 21:07:19 +0800 Subject: [PATCH 2/4] Update recv_handler.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复@任何人都@bot --- src/recv_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/recv_handler.py b/src/recv_handler.py index 9a793f2..173b9f4 100644 --- a/src/recv_handler.py +++ b/src/recv_handler.py @@ -353,7 +353,7 @@ class RecvHandler: else: return None else: - member_info: dict = await get_member_info(self.server_connection, group_id=group_id, user_id=self_id) + member_info: dict = await get_member_info(self.server_connection, group_id=group_id, user_id=qq_id) if member_info: return Seg( type=RealMessageType.text, From 744def22692bed774e0192ae510d59b4cd72d76c Mon Sep 17 00:00:00 2001 From: UnCLAS-Prommer Date: Fri, 11 Apr 2025 23:16:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E5=A4=8D=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mmc_com_layer.py | 2 +- src/recv_handler.py | 26 +++++++++++++++++++++++--- src/utils.py | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/mmc_com_layer.py b/src/mmc_com_layer.py index b04b0f9..76a549f 100644 --- a/src/mmc_com_layer.py +++ b/src/mmc_com_layer.py @@ -5,7 +5,7 @@ from .send_handler import send_handler route_config = RouteConfig( route_config={ - "qq": TargetConfig( + global_config.platform: TargetConfig( url=f"ws://{global_config.mai_host}:{global_config.mai_port}/ws", token=None, ) diff --git a/src/recv_handler.py b/src/recv_handler.py index 9a793f2..2a7425a 100644 --- a/src/recv_handler.py +++ b/src/recv_handler.py @@ -24,6 +24,7 @@ from .utils import ( get_image_base64, get_self_info, get_stranger_info, + get_message_detail, ) from .message_queue import get_response @@ -256,11 +257,14 @@ class RecvHandler: logger.warning("暂时不支持窗口抖动解析") pass case RealMessageType.share: - logger.warning("链接分享?啊?你搞我啊?") + logger.warning("暂时不支持链接解析") pass case RealMessageType.reply: - logger.warning("暂时不支持回复解析") - pass + ret_seg = await self.handle_reply_message(sub_message) + if ret_seg: + seg_message.append(ret_seg) + else: + logger.warning("reply处理失败") case RealMessageType.forward: forward_message_id = sub_message.get("data").get("id") payload = json.dumps( @@ -362,6 +366,22 @@ class RecvHandler: else: return None + async def handle_reply_message(self, raw_message: dict) -> None: + """ + 处理回复消息 + + """ + message_id = raw_message.get("data").get("id") + message_detail: dict = await get_message_detail(self.server_connection, message_id) + sender_info: dict = message_detail.get("sender") + sender_nickname: str = sender_info.get("nickname") + if not sender_nickname: + logger.warning("无法获取被引用的人的昵称,返回默认值") + return Seg(type="text", data="回复QQ用户的消息,说:") + else: + return Seg(type="text", data=f"回复{sender_nickname}的消息,说:") + + async def handle_notice(self, raw_message: dict) -> None: notice_type = raw_message.get("notice_type") # message_time: int = raw_message.get("time") diff --git a/src/utils.py b/src/utils.py index d6fb406..2246755 100644 --- a/src/utils.py +++ b/src/utils.py @@ -126,3 +126,18 @@ async def get_stranger_info(websocket: Server.ServerConnection, user_id: int) -> response: dict = await get_response() logger.debug(response) return response.get("data") + +async def get_message_detail(websocket: Server.ServerConnection, message_id: str) -> dict: + """ + 获取消息详情 + Parameters: + websocket: WebSocket连接对象 + message_id: 消息ID + Returns: + dict: 返回的消息详情 + """ + payload = json.dumps({"action": "get_msg", "params": {"message_id": message_id}}) + await websocket.send(payload) + response: dict = await get_response() + logger.debug(response) + return response.get("data") \ No newline at end of file From 0aef4281c820f9eafc7751033c300384c848c675 Mon Sep 17 00:00:00 2001 From: UnCLAS-Prommer Date: Fri, 11 Apr 2025 23:19:16 +0800 Subject: [PATCH 4/4] readme --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b4e8626..c60a429 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ [Nickname] # 现在没用 nickname = "" -[Napcat_Server] # Napvat连接的ws服务设置 +[Napcat_Server] # Napcat连接的ws服务设置 host = "localhost" # Napcat设定的url地址 port = 8095 # Napcat设定的ws端口 [MaiBot_Server] # 连接麦麦的ws服务设置 -host = "localhost" # 麦麦在.env文件中设置的url地址 -port = 8000 # 麦麦在.env文件中设置的ws端口 +platform_name = "qq" # 标识adapter的名称(必填) +host = "localhost" # 麦麦在.env文件中设置的url地址 +port = 8000 # 麦麦在.env文件中设置的ws端口 [Napcat] heartbeat = 30 # 与Napcat设置的心跳相同(按秒计) @@ -25,6 +26,9 @@ heartbeat = 30 # 与Napcat设置的心跳相同(按秒计) group_list = [] private_list = [] enable_temp = false + +[Debug] +level = "INFO" # 日志等级(DEBUG, INFO, WARNING, ERROR) ``` 你需要的就是把template_config.toml复制到根目录,然后改 @@ -83,11 +87,11 @@ sequenceDiagram - [x] 文本与消息混合解析 - [x] 转发解析(含图片动态解析) - [ ] 群公告解析 - - [ ] 回复解析(?) + - [x] 回复解析 - [ ] 群临时消息(可能不做) - [ ] 链接解析 - [x] 戳一戳解析 - - [ ] 读取戳一戳的自定义内容(?) + - [x] 读取戳一戳的自定义内容 - [ ] 语音解析(?) - [ ] 所有的notice类 - [ ] 撤回