fix: change BotStatus type to json.RawMessage and add isAPIResponse function

This commit is contained in:
Hoshina 2026-02-14 20:40:06 +08:00
parent 9a3f3611c3
commit 50628b386a

View file

@ -45,7 +45,7 @@ type oneBotRawEvent struct {
MetaEventType string `json:"meta_event_type"` MetaEventType string `json:"meta_event_type"`
Echo string `json:"echo"` Echo string `json:"echo"`
RetCode json.RawMessage `json:"retcode"` RetCode json.RawMessage `json:"retcode"`
Status BotStatus `json:"status"` Status json.RawMessage `json:"status"`
} }
type BotStatus struct { type BotStatus struct {
@ -53,6 +53,21 @@ type BotStatus struct {
Good bool `json:"good"` 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 { type oneBotSender struct {
UserID json.RawMessage `json:"user_id"` UserID json.RawMessage `json:"user_id"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
@ -334,10 +349,10 @@ func (c *OneBotChannel) listen() {
continue 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{}{ logger.DebugCF("onebot", "Received API response, skipping", map[string]interface{}{
"echo": raw.Echo, "echo": raw.Echo,
"status": raw.Status, "status": string(raw.Status),
}) })
continue continue
} }