Browse Source

Fix TimeStamps unmarshalling (#474) (#475)

Nicholas Hanley 7 years ago
parent
commit
43bf6cf0d0
1 changed files with 18 additions and 2 deletions
  1. 18 2
      structs.go

+ 18 - 2
structs.go

@@ -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