Dev (#74)
* fix(discord): 修复 WebSocket 连接检测并增强跨平台文件处理 修复 Discord WebSocket 连接检测逻辑,使用正确的属性检查连接状态 为跨平台消息处理添加文件类型支持,并增加详细的调试日志 优化附件处理逻辑,确保所有文件类型都能正确识别和转发 * 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