diff --git a/discord_test.go b/discord_test.go index 318bed0..30d2c75 100644 --- a/discord_test.go +++ b/discord_test.go @@ -125,7 +125,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.UpdateGameStatus(0, time.Now().String()); err != nil { t.Errorf("UpdateStatus error: %+v", err) } diff --git a/events.go b/events.go index dd0e3d8..7488dcc 100644 --- a/events.go +++ b/events.go @@ -196,8 +196,7 @@ type PresencesReplace []*Presence // PresenceUpdate is the data for a PresenceUpdate event. type PresenceUpdate struct { Presence - GuildID string `json:"guild_id"` - Roles []string `json:"roles"` + GuildID string `json:"guild_id"` } // Resumed is the data for a Resumed event. diff --git a/state.go b/state.go index 4f6479b..2eeabd8 100644 --- a/state.go +++ b/state.go @@ -200,14 +200,10 @@ func (s *State) PresenceAdd(guildID string, presence *Presence) error { //guild.Presences[i] = presence //Update status - guild.Presences[i].Game = presence.Game - guild.Presences[i].Roles = presence.Roles + guild.Presences[i].Activities = presence.Activities if presence.Status != "" { guild.Presences[i].Status = presence.Status } - if presence.Nick != "" { - guild.Presences[i].Nick = presence.Nick - } //Update the optionally sent user information //ID Is a mandatory field so you should not need to check if it is empty @@ -966,24 +962,12 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) { // Member not found; this is a user coming online m = &Member{ GuildID: t.GuildID, - Nick: t.Nick, User: t.User, - Roles: t.Roles, } - } else { - - if t.Nick != "" { - m.Nick = t.Nick - } - if t.User.Username != "" { m.User.Username = t.User.Username } - - // PresenceUpdates always contain a list of roles, so there's no need to check for an empty list here - m.Roles = t.Roles - } err = s.MemberAdd(m) diff --git a/structs.go b/structs.go index 09bb163..3267072 100644 --- a/structs.go +++ b/structs.go @@ -14,6 +14,7 @@ package discordgo import ( "encoding/json" "fmt" + "math" "net/http" "strings" "sync" @@ -692,39 +693,10 @@ type VoiceState struct { // A Presence stores the online, offline, or idle and game status of Guild members. type Presence struct { - User *User `json:"user"` - Status Status `json:"status"` - Game *Game `json:"game"` - Activities []*Game `json:"activities"` - Nick string `json:"nick"` - Roles []string `json:"roles"` - Since *int `json:"since"` -} - -// GameType is the type of "game" (see GameType* consts) in the Game struct -type GameType int - -// Valid GameType values -const ( - GameTypeGame GameType = iota - GameTypeStreaming - GameTypeListening - GameTypeWatching - GameTypeCustom -) - -// A Game struct holds the name of the "playing .." game for a user -type Game struct { - Name string `json:"name"` - Type GameType `json:"type"` - URL string `json:"url,omitempty"` - Details string `json:"details,omitempty"` - State string `json:"state,omitempty"` - TimeStamps TimeStamps `json:"timestamps,omitempty"` - Assets Assets `json:"assets,omitempty"` - ApplicationID string `json:"application_id,omitempty"` - Instance int8 `json:"instance,omitempty"` - // TODO: Party and Secrets (unknown structure) + User *User `json:"user"` + Status Status `json:"status"` + Activities []*Activity `json:"activities"` + Since *int `json:"since"` } // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game @@ -1153,7 +1125,7 @@ type ActivityType int // Valid ActivityType values const ( - ActivityTypeGame GameType = iota + ActivityTypeGame ActivityType = iota ActivityTypeStreaming ActivityTypeListening // ActivityTypeWatching // not valid in this use case? diff --git a/wsapi.go b/wsapi.go index 1cf1598..55bc695 100644 --- a/wsapi.go +++ b/wsapi.go @@ -322,10 +322,10 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{} // UpdateStatusData ia provided to UpdateStatusComplex() type UpdateStatusData struct { - IdleSince *int `json:"since"` - Game *Game `json:"game"` - AFK bool `json:"afk"` - Status string `json:"status"` + IdleSince *int `json:"since"` + Activities []*Activity `json:"activities"` + AFK bool `json:"afk"` + Status string `json:"status"` } type updateStatusOp struct { @@ -333,7 +333,7 @@ type updateStatusOp struct { Data UpdateStatusData `json:"d"` } -func newUpdateStatusData(idle int, gameType GameType, game, url string) *UpdateStatusData { +func newUpdateStatusData(idle int, activityType ActivityType, name, url string) *UpdateStatusData { usd := &UpdateStatusData{ Status: "online", } @@ -342,12 +342,12 @@ func newUpdateStatusData(idle int, gameType GameType, game, url string) *UpdateS usd.IdleSince = &idle } - if game != "" { - usd.Game = &Game{ - Name: game, - Type: gameType, + if name != "" { + usd.Activities = []*Activity{{ + Name: name, + Type: activityType, URL: url, - } + }} } return usd @@ -355,30 +355,30 @@ func newUpdateStatusData(idle int, gameType GameType, game, url string) *UpdateS // 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.UpdateStatusComplex(*newUpdateStatusData(idle, GameTypeGame, game, "")) +// If name!="" then set game. +// if otherwise, set status to active, and no activity. +func (s *Session) UpdateGameStatus(idle int, name string) (err error) { + return s.UpdateStatusComplex(*newUpdateStatusData(idle, ActivityTypeGame, name, "")) } // 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 name!="" then set game. +// If name!="" 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) UpdateStreamingStatus(idle int, game string, url string) (err error) { - gameType := GameTypeGame +func (s *Session) UpdateStreamingStatus(idle int, name string, url string) (err error) { + gameType := ActivityTypeGame if url != "" { - gameType = GameTypeStreaming + gameType = ActivityTypeStreaming } - return s.UpdateStatusComplex(*newUpdateStatusData(idle, gameType, game, url)) + return s.UpdateStatusComplex(*newUpdateStatusData(idle, gameType, name, url)) } // UpdateListeningStatus is used to set the user to "Listening to..." -// If game!="" then set to what user is listening to -// Else, set user to active and no game. -func (s *Session) UpdateListeningStatus(game string) (err error) { - return s.UpdateStatusComplex(*newUpdateStatusData(0, GameTypeListening, game, "")) +// If name!="" then set to what user is listening to +// Else, set user to active and no activity. +func (s *Session) UpdateListeningStatus(name string) (err error) { + return s.UpdateStatusComplex(*newUpdateStatusData(0, ActivityTypeListening, name, "")) } // UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.