diff --git a/astrbot/core/platform/sources/satori/satori_adapter.py b/astrbot/core/platform/sources/satori/satori_adapter.py index efb756680..a3f4f53ec 100644 --- a/astrbot/core/platform/sources/satori/satori_adapter.py +++ b/astrbot/core/platform/sources/satori/satori_adapter.py @@ -499,10 +499,36 @@ async def _extract_quote_element(self, content: str) -> Optional[dict]: } return None + except ET.ParseError as e: + logger.warning(f"XML解析失败,使用正则提取: {e}") + return await self._extract_quote_with_regex(content) except Exception as e: logger.error(f"提取标签时发生错误: {e}") return None + async def _extract_quote_with_regex(self, content: str) -> Optional[dict]: + """使用正则表达式提取quote标签信息""" + import re + + quote_pattern = r"]*)>(.*?)" + match = re.search(quote_pattern, content, re.DOTALL) + + if not match: + return None + + attrs_str = match.group(1) + inner_content = match.group(2) + + id_match = re.search(r'id\s*=\s*["\']([^"\']*)["\']', attrs_str) + quote_id = id_match.group(1) if id_match else "" + content_without_quote = content.replace(match.group(0), "") + content_without_quote = content_without_quote.strip() + + return { + "quote": {"id": quote_id, "content": inner_content}, + "content_without_quote": content_without_quote, + } + async def _convert_quote_message(self, quote: dict) -> Optional[AstrBotMessage]: """转换引用消息""" try: @@ -574,7 +600,7 @@ async def parse_satori_elements(self, content: str) -> list: root = ET.fromstring(processed_content) await self._parse_xml_node(root, elements) except ET.ParseError as e: - logger.error(f"解析 Satori 元素时发生解析错误: {e}, 错误内容: {content}") + logger.warning(f"解析 Satori 元素时发生解析错误: {e}, 错误内容: {content}") # 如果解析失败,将整个内容当作纯文本 if content.strip(): elements.append(Plain(text=content)) diff --git a/astrbot/core/platform/sources/satori/satori_event.py b/astrbot/core/platform/sources/satori/satori_event.py index f1a66da6b..78325c9a8 100644 --- a/astrbot/core/platform/sources/satori/satori_event.py +++ b/astrbot/core/platform/sources/satori/satori_event.py @@ -2,7 +2,18 @@ from astrbot.api import logger from astrbot.api.event import AstrMessageEvent, MessageChain from astrbot.api.platform import AstrBotMessage, PlatformMetadata -from astrbot.api.message_components import Plain, Image, At, File, Record, Video, Reply +from astrbot.api.message_components import ( + Plain, + Image, + At, + File, + Record, + Video, + Reply, + Forward, + Node, + Nodes, +) if TYPE_CHECKING: from .satori_adapter import SatoriPlatformAdapter @@ -48,55 +59,24 @@ async def send_with_adapter( content_parts = [] for component in message.chain: - if isinstance(component, Plain): - text = ( - component.text.replace("&", "&") - .replace("<", "<") - .replace(">", ">") - ) - content_parts.append(text) - - elif isinstance(component, At): - if component.qq: - content_parts.append(f'') - elif component.name: - content_parts.append(f'') - - elif isinstance(component, Image): - try: - image_base64 = await component.convert_to_base64() - if image_base64: - content_parts.append( - f'' - ) - except Exception as e: - logger.error(f"图片转换为base64失败: {e}") - - elif isinstance(component, File): - content_parts.append( - f'' - ) - - elif isinstance(component, Record): - try: - record_base64 = await component.convert_to_base64() - if record_base64: - content_parts.append( - f'