From 80c21586058d58f58ffe00e7ecf7ac2943239f8e Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Fri, 6 May 2016 15:22:16 -0700 Subject: [PATCH 1/3] Support streaming status updates. --- structs.go | 2 ++ wsapi.go | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/structs.go b/structs.go index 296d28a..796f5a4 100644 --- a/structs.go +++ b/structs.go @@ -253,6 +253,8 @@ type Presence struct { // 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"` } // A Member stores user information for Guild members. diff --git a/wsapi.go b/wsapi.go index c51a445..d0717a6 100644 --- a/wsapi.go +++ b/wsapi.go @@ -306,13 +306,9 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{} } } -type updateStatusGame struct { - Name string `json:"name"` -} - type updateStatusData struct { - IdleSince *int `json:"idle_since"` - Game *updateStatusGame `json:"game"` + IdleSince *int `json:"idle_since"` + Game *Game `json:"game"` } type updateStatusOp struct { @@ -320,10 +316,12 @@ type updateStatusOp struct { Data updateStatusData `json:"d"` } -// UpdateStatus is used to update the authenticated user's status. -// If idle>0 then set status to idle. If game>0 then set game. +// UpdateStatus is used to update the user's status. +// If idle>0 then set status to idle. +// If game!="" then set game. +// If game!="" and url!="" then set the status type to streaming with the URL set. // if otherwise, set status to active, and no game. -func (s *Session) UpdateStatus(idle int, game string) (err error) { +func (s *Session) UpdateStatus(idle int, game string, url string) (err error) { s.log(LogInformational, "called") @@ -339,7 +337,15 @@ func (s *Session) UpdateStatus(idle int, game string) (err error) { } if game != "" { - usd.Game = &updateStatusGame{game} + gameType := 0 + if url != "" { + gameType = 1 + } + usd.Game = &Game{ + Name: game, + Type: gameType, + URL: url, + } } s.wsMutex.Lock() From 544d1dfcb5c7d7be74fa932acfd8a3b4625d442f Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sat, 14 May 2016 09:43:47 -0700 Subject: [PATCH 2/3] Fix test. --- discord_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord_test.go b/discord_test.go index d2b497f..79a3e60 100644 --- a/discord_test.go +++ b/discord_test.go @@ -216,7 +216,7 @@ func TestOpenClose(t *testing.T) { // UpdateStatus - maybe we move this into wsapi_test.go but the websocket // created here is needed. This helps tests that the websocket was setup // and it is working. - if err = d.UpdateStatus(0, time.Now().String()); err != nil { + if err = d.UpdateStatus(0, time.Now().String(), ""); err != nil { t.Errorf("UpdateStatus error: %+v", err) } From a8ecc78c3403616a6b1eccb201aaf2a8ebb91b15 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Sat, 14 May 2016 09:50:37 -0700 Subject: [PATCH 3/3] Don't break the API. --- discord_test.go | 2 +- wsapi.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/discord_test.go b/discord_test.go index 79a3e60..d2b497f 100644 --- a/discord_test.go +++ b/discord_test.go @@ -216,7 +216,7 @@ func TestOpenClose(t *testing.T) { // UpdateStatus - maybe we move this into wsapi_test.go but the websocket // created here is needed. This helps tests that the websocket was setup // and it is working. - if err = d.UpdateStatus(0, time.Now().String(), ""); err != nil { + if err = d.UpdateStatus(0, time.Now().String()); err != nil { t.Errorf("UpdateStatus error: %+v", err) } diff --git a/wsapi.go b/wsapi.go index d0717a6..4014274 100644 --- a/wsapi.go +++ b/wsapi.go @@ -316,12 +316,12 @@ type updateStatusOp struct { Data updateStatusData `json:"d"` } -// UpdateStatus is used to update the user's status. +// UpdateStreamingStatus is used to update the user's streaming status. // If idle>0 then set status to idle. // If game!="" then set game. // If game!="" and url!="" then set the status type to streaming with the URL set. // if otherwise, set status to active, and no game. -func (s *Session) UpdateStatus(idle int, game string, url string) (err error) { +func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) { s.log(LogInformational, "called") @@ -355,6 +355,14 @@ func (s *Session) UpdateStatus(idle int, game string, url string) (err error) { return } +// UpdateStatus is used to update the user's status. +// If idle>0 then set status to idle. +// If game!="" then set game. +// if otherwise, set status to active, and no game. +func (s *Session) UpdateStatus(idle int, game string) (err error) { + return s.UpdateStreamingStatus(idle, game, "") +} + // onEvent is the "event handler" for all messages received on the // Discord Gateway API websocket connection. //