Fix presence unmarshalling as the values are inconsistent from Discord. (#287)
This commit is contained in:
parent
c352d7016c
commit
b7c7e60fd5
1 changed files with 32 additions and 0 deletions
32
structs.go
32
structs.go
|
@ -14,6 +14,7 @@ package discordgo
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -290,6 +291,37 @@ type Game struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Game) UnmarshalJSON(bytes []byte) error {
|
||||||
|
temp := &struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type json.RawMessage `json:"type"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}{}
|
||||||
|
err := json.Unmarshal(bytes, temp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
g.Name = temp.Name
|
||||||
|
g.URL = temp.URL
|
||||||
|
|
||||||
|
if temp.Type != nil {
|
||||||
|
err = json.Unmarshal(temp.Type, &g.Type)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
s := ""
|
||||||
|
err = json.Unmarshal(temp.Type, &s)
|
||||||
|
if err == nil {
|
||||||
|
g.Type, err = strconv.Atoi(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// A Member stores user information for Guild members.
|
// A Member stores user information for Guild members.
|
||||||
type Member struct {
|
type Member struct {
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
|
|
Loading…
Reference in a new issue