fix: change BotStatus type to json.RawMessage and add isAPIResponse function
This commit is contained in:
parent
9a3f3611c3
commit
50628b386a
1 changed files with 18 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue