From 50628b386a60e239f0fcf16399ba95e4f625ae53 Mon Sep 17 00:00:00 2001 From: Hoshina Date: Sat, 14 Feb 2026 20:40:06 +0800 Subject: [PATCH] fix: change BotStatus type to json.RawMessage and add isAPIResponse function --- pkg/channels/onebot.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pkg/channels/onebot.go b/pkg/channels/onebot.go index 5d97fab9c..f301646d8 100644 --- a/pkg/channels/onebot.go +++ b/pkg/channels/onebot.go @@ -45,7 +45,7 @@ type oneBotRawEvent struct { MetaEventType string `json:"meta_event_type"` Echo string `json:"echo"` RetCode json.RawMessage `json:"retcode"` - Status BotStatus `json:"status"` + Status json.RawMessage `json:"status"` } type BotStatus struct { @@ -53,6 +53,21 @@ type BotStatus struct { Good bool `json:"good"` } +func isAPIResponse(raw json.RawMessage) bool { + if len(raw) == 0 { + return false + } + var s string + if json.Unmarshal(raw, &s) == nil { + return s == "ok" || s == "failed" + } + var bs BotStatus + if json.Unmarshal(raw, &bs) == nil { + return bs.Online || bs.Good + } + return false +} + type oneBotSender struct { UserID json.RawMessage `json:"user_id"` Nickname string `json:"nickname"` @@ -334,10 +349,10 @@ func (c *OneBotChannel) listen() { continue } - if raw.Echo != "" || raw.Status.Online || raw.Status.Good { + if raw.Echo != "" || isAPIResponse(raw.Status) { logger.DebugCF("onebot", "Received API response, skipping", map[string]interface{}{ "echo": raw.Echo, - "status": raw.Status, + "status": string(raw.Status), }) continue }