Clean up status methods.

This commit is contained in:
Chris Rhodes 2018-02-08 21:00:24 -08:00
parent e8cd93cf15
commit 7f8369a45f

View file

@ -323,16 +323,8 @@ type updateStatusOp struct {
Data UpdateStatusData `json:"d"` Data UpdateStatusData `json:"d"`
} }
// UpdateStreamingStatus is used to update the user's streaming status. func newUpdateStatusData(idle int, gameType GameType, game, url string) *UpdateStatusData {
// If idle>0 then set status to idle. usd := &UpdateStatusData{
// 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.
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) {
s.log(LogInformational, "called")
usd := UpdateStatusData{
Status: "online", Status: "online",
} }
@ -341,10 +333,6 @@ func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err
} }
if game != "" { if game != "" {
gameType := GameTypeGame
if url != "" {
gameType = GameTypeStreaming
}
usd.Game = &Game{ usd.Game = &Game{
Name: game, Name: game,
Type: gameType, Type: gameType,
@ -352,7 +340,35 @@ func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err
} }
} }
return s.UpdateStatusComplex(usd) return usd
}
// 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, ""))
}
// 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 otherwise, set status to active, and no game.
func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error) {
gameType := GameTypeGame
if url != "" {
gameType = GameTypeStreaming
}
return s.UpdateStatusComplex(*newUpdateStatusData(idle, gameType, game, 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, ""))
} }
// UpdateStatusComplex allows for sending the raw status update data untouched by discordgo. // UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.
@ -371,31 +387,6 @@ func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (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, "")
}
// 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) {
usd := UpdateStatusData{
Status: "online",
}
if game != "" {
usd.Game = &Game{
Name: game,
Type: GameTypeListening,
URL: "",
}
}
return s.UpdateStatusComplex(usd)
}
type requestGuildMembersData struct { type requestGuildMembersData struct {
GuildID string `json:"guild_id"` GuildID string `json:"guild_id"`
Query string `json:"query"` Query string `json:"query"`