Fix TimeStamps unmarshalling (#474) (#475)

This commit is contained in:
Nicholas Hanley 2017-11-08 21:39:26 -05:00 committed by Chris Rhodes
parent a948670657
commit 43bf6cf0d0

View file

@ -12,6 +12,7 @@
package discordgo
import (
"encoding/json"
"net/http"
"sync"
"time"
@ -338,8 +339,23 @@ type Game struct {
// A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
type TimeStamps struct {
EndTimestamp uint `json:"end,omitempty"`
StartTimestamp uint `json:"start,omitempty"`
EndTimestamp int64 `json:"end,omitempty"`
StartTimestamp int64 `json:"start,omitempty"`
}
// UnmarshalJSON unmarshals JSON into TimeStamps struct
func (t *TimeStamps) UnmarshalJSON(b []byte) error {
temp := struct {
End float64 `json:"end,omitempty"`
Start float64 `json:"start,omitempty"`
}{}
err := json.Unmarshal(b, &temp)
if err != nil {
return err
}
t.EndTimestamp = int64(temp.End)
t.StartTimestamp = int64(temp.Start)
return nil
}
// An Assets struct contains assets and labels used in the rich presence "playing .." Game