diff --git a/structs.go b/structs.go index cbe4a09..80928a8 100644 --- a/structs.go +++ b/structs.go @@ -12,9 +12,7 @@ package discordgo import ( - "encoding/json" "net/http" - "strconv" "sync" "time" @@ -315,43 +313,19 @@ type Presence struct { Since *int `json:"since"` } +// A game type +type GameType int + +const ( + GameTypeGame GameType = iota + GameTypeStreaming +) + // A Game struct holds the name of the "playing .." game for a user type Game struct { - Name string `json:"name"` - Type int `json:"type"` - URL string `json:"url,omitempty"` -} - -// UnmarshalJSON unmarshals json to Game struct -func (g *Game) UnmarshalJSON(bytes []byte) error { - temp := &struct { - Name json.Number `json:"name"` - Type json.RawMessage `json:"type"` - URL string `json:"url"` - }{} - err := json.Unmarshal(bytes, temp) - if err != nil { - return err - } - g.URL = temp.URL - g.Name = temp.Name.String() - - 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 + Name string `json:"name"` + Type GameType `json:"type"` + URL string `json:"url,omitempty"` } // A Member stores user information for Guild members. diff --git a/wsapi.go b/wsapi.go index df87092..59dc532 100644 --- a/wsapi.go +++ b/wsapi.go @@ -285,9 +285,9 @@ func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err } if game != "" { - gameType := 0 + gameType := GameTypeGame if url != "" { - gameType = 1 + gameType = GameTypeStreaming } usd.Game = &Game{ Name: game,