From bb4f63775e185fedafbde536b5a11b2a4b425aba Mon Sep 17 00:00:00 2001 From: Bruce Marriner Date: Wed, 23 Dec 2015 23:51:20 -0600 Subject: [PATCH] Updated to support new Discord method of sending game playing data, closes #34 --- structs.go | 8 ++++++-- wsapi.go | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/structs.go b/structs.go index 4e5b6d4..a9896f1 100644 --- a/structs.go +++ b/structs.go @@ -210,7 +210,11 @@ type VoiceState struct { type Presence struct { User User `json:"user"` Status string `json:"status"` - GameID int `json:"game_id"` + Game Game `json:"game"` +} + +type Game struct { + Name string `json:"name"` } // A Member stores user information for Guild members. @@ -303,7 +307,7 @@ type PresenceUpdate struct { Status string `json:"status"` Roles []string `json:"roles"` GuildID string `json:"guild_id"` - GameID int `json:"game_id"` + Game Game `json:"game"` } // A MessageAck stores data for the message ack websocket event. diff --git a/wsapi.go b/wsapi.go index 7efa3f5..7fb5f9b 100644 --- a/wsapi.go +++ b/wsapi.go @@ -59,9 +59,13 @@ func (s *Session) Handshake() (err error) { return } +type updateStatusGame struct { + Name string `json:"name"` +} + type updateStatusData struct { - IdleSince json.Token `json:"idle_since"` - GameID json.Token `json:"game_id"` + IdleSince json.Token `json:"idle_since"` + Game interface{} `json:"game"` } type updateStatusOp struct { @@ -72,7 +76,7 @@ type updateStatusOp struct { // UpdateStatus is used to update the authenticated user's status. // If idle>0 then set status to idle. If game>0 then set game. // if otherwise, set status to active, and no game. -func (s *Session) UpdateStatus(idle int, gameID int) (err error) { +func (s *Session) UpdateStatus(idle int, game string) (err error) { var usd updateStatusData if idle > 0 { @@ -81,14 +85,17 @@ func (s *Session) UpdateStatus(idle int, gameID int) (err error) { usd.IdleSince = nil } - if gameID >= 0 { - usd.GameID = gameID + var usg updateStatusGame + if game == "" { + usd.Game = nil } else { - usd.GameID = nil + usg.Name = game + usd.Game = usg } data := updateStatusOp{3, usd} err = s.wsConn.WriteJSON(data) + return }