修复at导致命令无法识别的问题
This commit is contained in:
@@ -4,6 +4,7 @@ from ..Convention.Runtime.Architecture import Architecture
|
|||||||
|
|
||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
import re
|
||||||
|
|
||||||
from ..CoreModules.models import CallbackRequest
|
from ..CoreModules.models import CallbackRequest
|
||||||
from ..CoreModules.plugin_interface import PluginInterface
|
from ..CoreModules.plugin_interface import PluginInterface
|
||||||
@@ -21,13 +22,25 @@ async def callback_verify():
|
|||||||
logger.Log("Info", "收到Callback验证请求")
|
logger.Log("Info", "收到Callback验证请求")
|
||||||
return JSONResponse({"result": "ok"})
|
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")
|
@router.post("/callback/construct")
|
||||||
async def callback_receive_construct(callback_data: CallbackRequest):
|
async def callback_receive_construct(callback_data: CallbackRequest):
|
||||||
"""以构造好的Callback消息进行处理, 已知方式"""
|
"""以构造好的Callback消息进行处理, 已知方式"""
|
||||||
try:
|
try:
|
||||||
# 解析指令
|
# 解析指令
|
||||||
content = callback_data.content
|
content = parse_message_after_at(callback_data.content)
|
||||||
command = content.split(" ")[0]
|
command = content.split(" ")[0]
|
||||||
message = content[len(command):].strip()
|
message = content[len(command):].strip()
|
||||||
logger.Log("Info", f"识别指令: command={command}")
|
logger.Log("Info", f"识别指令: command={command}")
|
||||||
|
|||||||
Reference in New Issue
Block a user