fix: 【不发送】标签在sendProactive路径失效 + 群聊长消息截断防封控

- sendProactive端点新增【不发送】过滤(之前只有主回复路径有)
- sendProactive和主回复路径均增加群聊500字截断+最多2条限制
- 防止第三方平台适配器因过长消息触发封控

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-07-05 14:18:39 +08:00
parent f723194a17
commit 4ebdac42a1
2 changed files with 35 additions and 1 deletions
+8 -1
View File
@@ -484,7 +484,7 @@ func startOBv11Readers(router *bridge.PlatformRouter) {
if interval <= 0 { if interval <= 0 {
interval = 2 * time.Second interval = 2 * time.Second
} }
// 群聊用更长间隔避免刷屏,限制最多2条消息 // 群聊用更长间隔避免刷屏,限制最多2条消息,单条不超过500字防封控
if messageType == "group" { if messageType == "group" {
minGroupInterval := 3 * time.Second minGroupInterval := 3 * time.Second
if interval < minGroupInterval { if interval < minGroupInterval {
@@ -493,6 +493,13 @@ func startOBv11Readers(router *bridge.PlatformRouter) {
if len(toSend) > 2 { if len(toSend) > 2 {
toSend = toSend[:2] toSend = toSend[:2]
} }
const maxRunes = 500
for i := range toSend {
runes := []rune(toSend[i].Content)
if len(runes) > maxRunes {
toSend[i].Content = string(runes[:maxRunes]) + "\n…(内容过长已截断)"
}
}
} }
for i, rm := range toSend { for i, rm := range toSend {
if i > 0 && interval > 0 { if i > 0 && interval > 0 {
@@ -214,9 +214,36 @@ func (h *BridgeHandler) sendProactive(w http.ResponseWriter, r *http.Request) {
content := filterActions(req.Content) content := filterActions(req.Content)
content = convertMarkdownPlain(content) content = convertMarkdownPlain(content)
// 过滤 【不发送】 自我审查标签
if strings.Contains(content, "【不发送】") {
trimmed := content
if len([]rune(trimmed)) > 80 {
trimmed = string([]rune(trimmed)[:80]) + "..."
}
log.Printf("[send-proactive] 昔涟自我审查,跳过发送: %s", trimmed)
writeJSON(w, http.StatusOK, map[string]string{"status": "self_censored"})
return
}
// 按 \n\n 和 ♪ 拆分为多条消息 // 按 \n\n 和 ♪ 拆分为多条消息
messages := splitProactiveContent(content) messages := splitProactiveContent(content)
// 群聊长消息截断:超过 500 字的单条消息截断,防止封控
if msgType == "group" {
const maxLen = 500
for i, msg := range messages {
runes := []rune(msg)
if len(runes) > maxLen {
messages[i] = string(runes[:maxLen]) + "\n…(内容过长已截断)"
log.Printf("[send-proactive] 群聊消息过长截断: %d→%d 字", len(runes), maxLen)
}
}
// 群聊最多2条
if len(messages) > 2 {
messages = messages[:2]
}
}
// Prepend CQ @mention tag if at_user_id is specified // Prepend CQ @mention tag if at_user_id is specified
atPrefix := "" atPrefix := ""
if req.AtUserID != "" { if req.AtUserID != "" {