Updated to support new Discord method of sending game playing data, closes #34

This commit is contained in:
Bruce Marriner 2015-12-23 23:51:20 -06:00
parent 850901a5dc
commit bb4f63775e
2 changed files with 19 additions and 8 deletions

View file

@ -210,7 +210,11 @@ type VoiceState struct {
type Presence struct { type Presence struct {
User User `json:"user"` User User `json:"user"`
Status string `json:"status"` 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. // A Member stores user information for Guild members.
@ -303,7 +307,7 @@ type PresenceUpdate struct {
Status string `json:"status"` Status string `json:"status"`
Roles []string `json:"roles"` Roles []string `json:"roles"`
GuildID string `json:"guild_id"` GuildID string `json:"guild_id"`
GameID int `json:"game_id"` Game Game `json:"game"`
} }
// A MessageAck stores data for the message ack websocket event. // A MessageAck stores data for the message ack websocket event.

View file

@ -59,9 +59,13 @@ func (s *Session) Handshake() (err error) {
return return
} }
type updateStatusGame struct {
Name string `json:"name"`
}
type updateStatusData struct { type updateStatusData struct {
IdleSince json.Token `json:"idle_since"` IdleSince json.Token `json:"idle_since"`
GameID json.Token `json:"game_id"` Game interface{} `json:"game"`
} }
type updateStatusOp struct { type updateStatusOp struct {
@ -72,7 +76,7 @@ type updateStatusOp struct {
// UpdateStatus is used to update the authenticated user's status. // 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 idle>0 then set status to idle. If game>0 then set game.
// if otherwise, set status to active, and no 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 var usd updateStatusData
if idle > 0 { if idle > 0 {
@ -81,14 +85,17 @@ func (s *Session) UpdateStatus(idle int, gameID int) (err error) {
usd.IdleSince = nil usd.IdleSince = nil
} }
if gameID >= 0 { var usg updateStatusGame
usd.GameID = gameID if game == "" {
usd.Game = nil
} else { } else {
usd.GameID = nil usg.Name = game
usd.Game = usg
} }
data := updateStatusOp{3, usd} data := updateStatusOp{3, usd}
err = s.wsConn.WriteJSON(data) err = s.wsConn.WriteJSON(data)
return return
} }