feat(跨平台): 优化消息处理并添加纯文本提取功能
添加 extract_text_only 函数过滤非文本标记 修改翻译逻辑仅处理纯文本内容 完善附件处理和消息内容拼接 修复仅包含表情时的消息处理问题
This commit is contained in:
@@ -4,10 +4,26 @@
|
||||
"""
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
from typing import Dict, List, Any
|
||||
from models.message import MessageSegment
|
||||
from core.utils.logger import logger
|
||||
from .config import config
|
||||
|
||||
|
||||
def extract_text_only(content: str) -> str:
|
||||
"""从消息内容中提取纯文本,过滤掉非文本标记"""
|
||||
if not content:
|
||||
return ""
|
||||
|
||||
# 移除所有 [图片: xxx]、[视频: xxx]、[语音: xxx]、[文件: xxx] 等标记
|
||||
text_only = re.sub(r'\s*\[(图片|视频|语音|文件):[^\]]+\]\s*', ' ', content)
|
||||
|
||||
# 移除连续空格
|
||||
text_only = re.sub(r'\s+', ' ', text_only).strip()
|
||||
|
||||
return text_only
|
||||
|
||||
async def parse_forward_nodes(nodes: List[Dict[str, Any]]) -> tuple[str, List[dict]]:
|
||||
"""解析 OneBot 合并转发消息节点"""
|
||||
content_parts = []
|
||||
|
||||
Reference in New Issue
Block a user