forked from pothtonswer/discordmuffin
Updated to support new Discord method of sending game playing data, closes #34
This commit is contained in:
parent
850901a5dc
commit
bb4f63775e
2 changed files with 19 additions and 8 deletions
|
@ -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.
|
||||
|
|
19
wsapi.go
19
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue