From 7f8369a45fc1d2df208d7bbfdbd9226a85815143 Mon Sep 17 00:00:00 2001 From: Chris Rhodes Date: Thu, 8 Feb 2018 21:00:24 -0800 Subject: [PATCH] Clean up status methods. --- wsapi.go | 71 +++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/wsapi.go b/wsapi.go index f9d6029..80e85ac 100644 --- a/wsapi.go +++ b/wsapi.go @@ -323,16 +323,8 @@ type updateStatusOp struct { Data UpdateStatusData `json:"d"` } -// 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) { - - s.log(LogInformational, "called") - - usd := UpdateStatusData{ +func newUpdateStatusData(idle int, gameType GameType, game, url string) *UpdateStatusData { + usd := &UpdateStatusData{ Status: "online", } @@ -341,10 +333,6 @@ func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err } if game != "" { - gameType := GameTypeGame - if url != "" { - gameType = GameTypeStreaming - } usd.Game = &Game{ Name: game, 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. @@ -371,31 +387,6 @@ func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) { 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 { GuildID string `json:"guild_id"` Query string `json:"query"`