forked from pothtonswer/discordmuffin
Merge pull request #194 from iopred/status
Support streaming status updates.
This commit is contained in:
commit
942d3a8b66
2 changed files with 26 additions and 10 deletions
|
@ -253,6 +253,8 @@ type Presence struct {
|
||||||
// A Game struct holds the name of the "playing .." game for a user
|
// A Game struct holds the name of the "playing .." game for a user
|
||||||
type Game struct {
|
type Game struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Type int `json:"type"`
|
||||||
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Member stores user information for Guild members.
|
// A Member stores user information for Guild members.
|
||||||
|
|
32
wsapi.go
32
wsapi.go
|
@ -306,13 +306,9 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type updateStatusGame struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type updateStatusData struct {
|
type updateStatusData struct {
|
||||||
IdleSince *int `json:"idle_since"`
|
IdleSince *int `json:"idle_since"`
|
||||||
Game *updateStatusGame `json:"game"`
|
Game *Game `json:"game"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type updateStatusOp struct {
|
type updateStatusOp struct {
|
||||||
|
@ -320,10 +316,12 @@ type updateStatusOp struct {
|
||||||
Data updateStatusData `json:"d"`
|
Data updateStatusData `json:"d"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStatus is used to update the authenticated user's status.
|
// UpdateStreamingStatus is used to update the user's streaming status.
|
||||||
// If idle>0 then set status to idle. If game>0 then set game.
|
// 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 otherwise, set status to active, and no game.
|
// if otherwise, set status to active, and no game.
|
||||||
func (s *Session) UpdateStatus(idle int, game string) (err error) {
|
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) {
|
||||||
|
|
||||||
s.log(LogInformational, "called")
|
s.log(LogInformational, "called")
|
||||||
|
|
||||||
|
@ -339,7 +337,15 @@ func (s *Session) UpdateStatus(idle int, game string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if game != "" {
|
if game != "" {
|
||||||
usd.Game = &updateStatusGame{game}
|
gameType := 0
|
||||||
|
if url != "" {
|
||||||
|
gameType = 1
|
||||||
|
}
|
||||||
|
usd.Game = &Game{
|
||||||
|
Name: game,
|
||||||
|
Type: gameType,
|
||||||
|
URL: url,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.wsMutex.Lock()
|
s.wsMutex.Lock()
|
||||||
|
@ -349,6 +355,14 @@ func (s *Session) UpdateStatus(idle int, game string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.UpdateStreamingStatus(idle, game, "")
|
||||||
|
}
|
||||||
|
|
||||||
// onEvent is the "event handler" for all messages received on the
|
// onEvent is the "event handler" for all messages received on the
|
||||||
// Discord Gateway API websocket connection.
|
// Discord Gateway API websocket connection.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue