Implement Raw sending of status (Rich Presence and Online Status) (#462)

* Added ability to change the online status

* Add structs for rick presence implementation

* Refractor and publicise UpdateStatusData

* Add UpdateStatusComplex for raw status data sending

* Case gameType to int, stopped it compiling

* Might want to gofmt.

Doesn't do it on save because Gogland removed it and their new thing I
can't make sense of.

* Revert "Added ability to change the online status"

This reverts commit 235cd15a8eebbec070cb95a5853295387bceae1c.

* Change gametypeto match

* Move RLock to UpdateStatusComplex
This commit is contained in:
Cory Ory 2017-10-22 22:08:08 +01:00 committed by Chris Rhodes
parent 28dc6f6f33
commit 8737777ce7
2 changed files with 39 additions and 12 deletions

View file

@ -323,9 +323,30 @@ const (
// 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"`
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
type TimeStamps struct {
EndTimestamp uint `json:"end,omitempty"`
StartTimestamp uint `json:"start,omitempty"`
}
// An Assets struct contains assets and labels used in the rich presence "playing .." Game
type Assets struct {
LargeImageID string `json:"large_image,omitempty"`
SmallImageID string `json:"small_image,omitempty"`
LargeText string `json:"large_text,omitempty"`
SmallText string `json:"small_text,omitempty"`
}
// A Member stores user information for Guild members.

View file

@ -249,7 +249,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
}
}
type updateStatusData struct {
type UpdateStatusData struct {
IdleSince *int `json:"since"`
Game *Game `json:"game"`
AFK bool `json:"afk"`
@ -258,7 +258,7 @@ type updateStatusData struct {
type updateStatusOp struct {
Op int `json:"op"`
Data updateStatusData `json:"d"`
Data UpdateStatusData `json:"d"`
}
// UpdateStreamingStatus is used to update the user's streaming status.
@ -270,13 +270,7 @@ func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err
s.log(LogInformational, "called")
s.RLock()
defer s.RUnlock()
if s.wsConn == nil {
return ErrWSNotFound
}
usd := updateStatusData{
usd := UpdateStatusData{
Status: "online",
}
@ -296,6 +290,18 @@ func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err
}
}
return s.UpdateStatusComplex(usd)
}
// UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.
func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) {
s.RLock()
defer s.RUnlock()
if s.wsConn == nil {
return ErrWSNotFound
}
s.wsMutex.Lock()
err = s.wsConn.WriteJSON(updateStatusOp{3, usd})
s.wsMutex.Unlock()