feat: add UpdateCustomStatus (#1425)

Add Session.UpdateCustomStatus, which allows to set and reset the custom status of a bot.
This commit is contained in:
Fedor Lapshin 2023-09-02 01:38:18 +03:00 committed by GitHub
parent ff9176adcc
commit b51655404a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -389,6 +389,26 @@ func (s *Session) UpdateListeningStatus(name string) (err error) {
return s.UpdateStatusComplex(*newUpdateStatusData(0, ActivityTypeListening, name, ""))
}
// UpdateCustomStatus is used to update the user's custom status.
// If state!="" then set the custom status.
// Else, set user to active and remove the custom status.
func (s *Session) UpdateCustomStatus(state string) (err error) {
data := UpdateStatusData{
Status: "online",
}
if state != "" {
// Discord requires a non-empty activity name, therefore we provide "Custom Status" as a placeholder.
data.Activities = []*Activity{{
Name: "Custom Status",
Type: ActivityTypeCustom,
State: state,
}}
}
return s.UpdateStatusComplex(data)
}
// UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.
func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error) {
// The comment does say "untouched by discordgo", but we might need to lie a bit here.