This commit is contained in:
cc
2026-05-02 19:08:12 +08:00
2 changed files with 68 additions and 10 deletions

View File

@@ -6657,17 +6657,35 @@ class ChatService {
}
private cleanSystemMessage(content: string): string {
if (!content) return '[系统消息]'
const normalized = this.cleanUtf16(this.decodeHtmlEntities(String(content)))
const readableSysmsg = this.extractReadableSystemMessageText(normalized)
if (readableSysmsg) {
return readableSysmsg
}
// 移除 XML 声明
let cleaned = content.replace(/<\?xml[^?]*\?>/gi, '')
let cleaned = normalized.replace(/<\?xml[^?]*\?>/gi, '')
// 移除所有 XML/HTML 标签
cleaned = cleaned.replace(/<[^>]+>/g, '')
// 移除尾部的数字(如撤回消息后的时间戳)
cleaned = cleaned.replace(/\d+\s*$/, '')
// 清理多余空白
cleaned = cleaned.replace(/\s+/g, ' ').trim()
cleaned = this.stripSenderPrefix(cleaned).replace(/\s+/g, ' ').trim()
return cleaned || '[系统消息]'
}
private extractReadableSystemMessageText(content: string): string {
const sysmsgMatch = /<sysmsg\b[^>]*>([\s\S]*?)<\/sysmsg>/i.exec(content)
const source = sysmsgMatch?.[1] || content
const text =
this.extractXmlValue(source, 'plain') ||
this.extractXmlValue(source, 'text') ||
''
return this.stripSenderPrefix(text).replace(/\s+/g, ' ').trim()
}
private stripSenderPrefix(content: string): string {
return content.replace(/^[\s]*([a-zA-Z0-9_@-]+):(?!\/\/)(?:\s*(?:\r?\n|<br\s*\/?>)\s*|\s*)/i, '')
}