From 0393e7aff76d0ec47c87a7a4031428e6156ff230 Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Fri, 6 Feb 2026 23:19:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=8D=E4=B8=80=E6=8B=8D?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/chatService.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/electron/services/chatService.ts b/electron/services/chatService.ts index 2a20a06..0d88680 100644 --- a/electron/services/chatService.ts +++ b/electron/services/chatService.ts @@ -2190,19 +2190,32 @@ class ChatService { /** * 清理拍一拍消息 - * 格式示例: 我拍了拍 "梨绒" ງ໐໐໓ ຖiງht620000wxid_... + * 格式示例: + * 纯文本: 我拍了拍 "梨绒" ງ໐໐໓ ຖiງht620000wxid_... + * XML: "有幸"拍了拍"浩天空"相信未来!... */ private cleanPatMessage(content: string): string { if (!content) return '[拍一拍]' - // 1. 尝试匹配标准的 "A拍了拍B" 格式 - // 这里的正则比较宽泛,为了兼容不同的语言环境 + // 1. 优先从 XML 标签提取内容 + const titleMatch = /<title>([\s\S]*?)<\/title>/i.exec(content) + if (titleMatch) { + const title = titleMatch[1] + .replace(/<!\[CDATA\[/g, '') + .replace(/\]\]>/g, '') + .trim() + if (title) { + return `[拍一拍] ${title}` + } + } + + // 2. 尝试匹配标准的 "A拍了拍B" 格式 const match = /^(.+?拍了拍.+?)(?:[\r\n]|$|ງ|wxid_)/.exec(content) if (match) { return `[拍一拍] ${match[1].trim()}` } - // 2. 如果匹配失败,尝试清理掉疑似的 garbage (wxid, 乱码) + // 3. 如果匹配失败,尝试清理掉疑似的 garbage (wxid, 乱码) let cleaned = content.replace(/wxid_[a-zA-Z0-9_-]+/g, '') // 移除 wxid cleaned = cleaned.replace(/[ງ໐໓ຖiht]+/g, ' ') // 移除已知的乱码字符 cleaned = cleaned.replace(/\d{6,}/g, '') // 移除长数字