forked from pothtonswer/discordmuffin
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:
parent
28dc6f6f33
commit
8737777ce7
2 changed files with 39 additions and 12 deletions
21
structs.go
21
structs.go
|
@ -326,6 +326,27 @@ type Game struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type GameType `json:"type"`
|
Type GameType `json:"type"`
|
||||||
URL string `json:"url,omitempty"`
|
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.
|
// A Member stores user information for Guild members.
|
||||||
|
|
24
wsapi.go
24
wsapi.go
|
@ -249,7 +249,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type updateStatusData struct {
|
type UpdateStatusData struct {
|
||||||
IdleSince *int `json:"since"`
|
IdleSince *int `json:"since"`
|
||||||
Game *Game `json:"game"`
|
Game *Game `json:"game"`
|
||||||
AFK bool `json:"afk"`
|
AFK bool `json:"afk"`
|
||||||
|
@ -258,7 +258,7 @@ type updateStatusData struct {
|
||||||
|
|
||||||
type updateStatusOp struct {
|
type updateStatusOp struct {
|
||||||
Op int `json:"op"`
|
Op int `json:"op"`
|
||||||
Data updateStatusData `json:"d"`
|
Data UpdateStatusData `json:"d"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStreamingStatus is used to update the user's streaming status.
|
// 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.log(LogInformational, "called")
|
||||||
|
|
||||||
s.RLock()
|
usd := UpdateStatusData{
|
||||||
defer s.RUnlock()
|
|
||||||
if s.wsConn == nil {
|
|
||||||
return ErrWSNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
usd := updateStatusData{
|
|
||||||
Status: "online",
|
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()
|
s.wsMutex.Lock()
|
||||||
err = s.wsConn.WriteJSON(updateStatusOp{3, usd})
|
err = s.wsConn.WriteJSON(updateStatusOp{3, usd})
|
||||||
s.wsMutex.Unlock()
|
s.wsMutex.Unlock()
|
||||||
|
|
Loading…
Reference in a new issue