Add changes to presences, remove Game type
This commit is contained in:
parent
866ecccb2e
commit
c41dc15a10
5 changed files with 33 additions and 78 deletions
|
@ -125,7 +125,7 @@ func TestOpenClose(t *testing.T) {
|
||||||
// UpdateStatus - maybe we move this into wsapi_test.go but the websocket
|
// UpdateStatus - maybe we move this into wsapi_test.go but the websocket
|
||||||
// created here is needed. This helps tests that the websocket was setup
|
// created here is needed. This helps tests that the websocket was setup
|
||||||
// and it is working.
|
// 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)
|
t.Errorf("UpdateStatus error: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,6 @@ type PresencesReplace []*Presence
|
||||||
type PresenceUpdate struct {
|
type PresenceUpdate struct {
|
||||||
Presence
|
Presence
|
||||||
GuildID string `json:"guild_id"`
|
GuildID string `json:"guild_id"`
|
||||||
Roles []string `json:"roles"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resumed is the data for a Resumed event.
|
// Resumed is the data for a Resumed event.
|
||||||
|
|
18
state.go
18
state.go
|
@ -200,14 +200,10 @@ func (s *State) PresenceAdd(guildID string, presence *Presence) error {
|
||||||
//guild.Presences[i] = presence
|
//guild.Presences[i] = presence
|
||||||
|
|
||||||
//Update status
|
//Update status
|
||||||
guild.Presences[i].Game = presence.Game
|
guild.Presences[i].Activities = presence.Activities
|
||||||
guild.Presences[i].Roles = presence.Roles
|
|
||||||
if presence.Status != "" {
|
if presence.Status != "" {
|
||||||
guild.Presences[i].Status = presence.Status
|
guild.Presences[i].Status = presence.Status
|
||||||
}
|
}
|
||||||
if presence.Nick != "" {
|
|
||||||
guild.Presences[i].Nick = presence.Nick
|
|
||||||
}
|
|
||||||
|
|
||||||
//Update the optionally sent user information
|
//Update the optionally sent user information
|
||||||
//ID Is a mandatory field so you should not need to check if it is empty
|
//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
|
// Member not found; this is a user coming online
|
||||||
m = &Member{
|
m = &Member{
|
||||||
GuildID: t.GuildID,
|
GuildID: t.GuildID,
|
||||||
Nick: t.Nick,
|
|
||||||
User: t.User,
|
User: t.User,
|
||||||
Roles: t.Roles,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if t.Nick != "" {
|
|
||||||
m.Nick = t.Nick
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.User.Username != "" {
|
if t.User.Username != "" {
|
||||||
m.User.Username = 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)
|
err = s.MemberAdd(m)
|
||||||
|
|
34
structs.go
34
structs.go
|
@ -14,6 +14,7 @@ package discordgo
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -694,39 +695,10 @@ type VoiceState struct {
|
||||||
type Presence struct {
|
type Presence struct {
|
||||||
User *User `json:"user"`
|
User *User `json:"user"`
|
||||||
Status Status `json:"status"`
|
Status Status `json:"status"`
|
||||||
Game *Game `json:"game"`
|
Activities []*Activity `json:"activities"`
|
||||||
Activities []*Game `json:"activities"`
|
|
||||||
Nick string `json:"nick"`
|
|
||||||
Roles []string `json:"roles"`
|
|
||||||
Since *int `json:"since"`
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
|
// A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
|
||||||
type TimeStamps struct {
|
type TimeStamps struct {
|
||||||
EndTimestamp int64 `json:"end,omitempty"`
|
EndTimestamp int64 `json:"end,omitempty"`
|
||||||
|
@ -1153,7 +1125,7 @@ type ActivityType int
|
||||||
|
|
||||||
// Valid ActivityType values
|
// Valid ActivityType values
|
||||||
const (
|
const (
|
||||||
ActivityTypeGame GameType = iota
|
ActivityTypeGame ActivityType = iota
|
||||||
ActivityTypeStreaming
|
ActivityTypeStreaming
|
||||||
ActivityTypeListening
|
ActivityTypeListening
|
||||||
// ActivityTypeWatching // not valid in this use case?
|
// ActivityTypeWatching // not valid in this use case?
|
||||||
|
|
42
wsapi.go
42
wsapi.go
|
@ -323,7 +323,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
|
||||||
// UpdateStatusData ia provided to UpdateStatusComplex()
|
// UpdateStatusData ia provided to UpdateStatusComplex()
|
||||||
type UpdateStatusData struct {
|
type UpdateStatusData struct {
|
||||||
IdleSince *int `json:"since"`
|
IdleSince *int `json:"since"`
|
||||||
Game *Game `json:"game"`
|
Activities []*Activity `json:"activities"`
|
||||||
AFK bool `json:"afk"`
|
AFK bool `json:"afk"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ type updateStatusOp struct {
|
||||||
Data UpdateStatusData `json:"d"`
|
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{
|
usd := &UpdateStatusData{
|
||||||
Status: "online",
|
Status: "online",
|
||||||
}
|
}
|
||||||
|
@ -342,12 +342,12 @@ func newUpdateStatusData(idle int, gameType GameType, game, url string) *UpdateS
|
||||||
usd.IdleSince = &idle
|
usd.IdleSince = &idle
|
||||||
}
|
}
|
||||||
|
|
||||||
if game != "" {
|
if name != "" {
|
||||||
usd.Game = &Game{
|
usd.Activities = []*Activity{{
|
||||||
Name: game,
|
Name: name,
|
||||||
Type: gameType,
|
Type: activityType,
|
||||||
URL: url,
|
URL: url,
|
||||||
}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
return usd
|
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.
|
// UpdateStatus is used to update the user's status.
|
||||||
// If idle>0 then set status to idle.
|
// If idle>0 then set status to idle.
|
||||||
// If game!="" then set game.
|
// If name!="" then set game.
|
||||||
// if otherwise, set status to active, and no game.
|
// if otherwise, set status to active, and no activity.
|
||||||
func (s *Session) UpdateStatus(idle int, game string) (err error) {
|
func (s *Session) UpdateGameStatus(idle int, name string) (err error) {
|
||||||
return s.UpdateStatusComplex(*newUpdateStatusData(idle, GameTypeGame, game, ""))
|
return s.UpdateStatusComplex(*newUpdateStatusData(idle, ActivityTypeGame, name, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStreamingStatus is used to update the user's streaming status.
|
// UpdateStreamingStatus is used to update the user's streaming status.
|
||||||
// If idle>0 then set status to idle.
|
// If idle>0 then set status to idle.
|
||||||
// If game!="" then set game.
|
// If name!="" then set game.
|
||||||
// If game!="" and url!="" then set the status type to streaming with the URL set.
|
// If name!="" and url!="" then set the status type to streaming with the URL set.
|
||||||
// if otherwise, set status to active, and no game.
|
// if otherwise, set status to active, and no game.
|
||||||
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) {
|
func (s *Session) UpdateStreamingStatus(idle int, name string, url string) (err error) {
|
||||||
gameType := GameTypeGame
|
gameType := ActivityTypeGame
|
||||||
if url != "" {
|
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..."
|
// UpdateListeningStatus is used to set the user to "Listening to..."
|
||||||
// If game!="" then set to what user is listening to
|
// If name!="" then set to what user is listening to
|
||||||
// Else, set user to active and no game.
|
// Else, set user to active and no activity.
|
||||||
func (s *Session) UpdateListeningStatus(game string) (err error) {
|
func (s *Session) UpdateListeningStatus(name string) (err error) {
|
||||||
return s.UpdateStatusComplex(*newUpdateStatusData(0, GameTypeListening, game, ""))
|
return s.UpdateStatusComplex(*newUpdateStatusData(0, ActivityTypeListening, name, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.
|
// UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.
|
||||||
|
|
Loading…
Reference in a new issue