From 36324398c39638a24e1f006416e96f9ebc4916ed Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Mon, 10 Nov 2025 09:55:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dat=E5=AF=BC=E8=87=B4=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=97=A0=E6=B3=95=E8=AF=86=E5=88=AB=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreRouters/callback.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CoreRouters/callback.py b/CoreRouters/callback.py index 6d7617f..8c0c95d 100644 --- a/CoreRouters/callback.py +++ b/CoreRouters/callback.py @@ -4,6 +4,7 @@ from ..Convention.Runtime.Architecture import Architecture from fastapi import APIRouter, Request from fastapi.responses import JSONResponse +import re from ..CoreModules.models import CallbackRequest from ..CoreModules.plugin_interface import PluginInterface @@ -21,13 +22,25 @@ async def callback_verify(): logger.Log("Info", "收到Callback验证请求") return JSONResponse({"result": "ok"}) +# 机器人名称模式(用于从@消息中提取,兼容半角/全角空格) +AT_PATTERN = re.compile(r'@[^\s]+[\s\u3000]+(.+)', re.DOTALL) + +def parse_message_after_at(message: str) -> str: + # 去除首尾空格 + message = message.strip() + + # 尝试提取@后的内容 + at_match = AT_PATTERN.search(message) + if at_match: + return at_match.group(1).strip() + return message @router.post("/callback/construct") async def callback_receive_construct(callback_data: CallbackRequest): """以构造好的Callback消息进行处理, 已知方式""" try: # 解析指令 - content = callback_data.content + content = parse_message_after_at(callback_data.content) command = content.split(" ")[0] message = content[len(command):].strip() logger.Log("Info", f"识别指令: command={command}")