Add Support of changing user status (#258)

Add Support of changing user status
This commit is contained in:
robbix1206 2016-09-28 19:04:37 +02:00 committed by Chris Rhodes
parent c6ee0d2dd5
commit af3fe4842a
3 changed files with 60 additions and 14 deletions

View file

@ -332,6 +332,27 @@ func (s *Session) UserSettings() (st *Settings, err error) {
return
}
// UserUpdateStatus update the user status
// status : The new status (Actual valid status are 'online','idle','dnd','invisible')
func (s *Session) UserUpdateStatus(status Status) (st *Settings, err error) {
if status == StatusOffline {
err = errors.New("You can't set your Status to offline")
return
}
data := struct {
Status Status `json:"status"`
}{status}
body, err := s.Request("PATCH", EndpointUserSettings("@me"), data)
if err != nil {
return
}
err = unmarshal(body, &st)
return
}
// UserChannels returns an array of Channel structures for all private
// channels.
func (s *Session) UserChannels() (st []*Channel, err error) {

View file

@ -131,6 +131,17 @@ func TestUserSettings(t *testing.T) {
}
}
func TestUserUpdateStatus(t *testing.T) {
if dg == nil {
t.Skip("Cannot TestUserSettings, dg not set.")
}
_, err := dg.UserUpdateStatus(StatusDoNotDisturb)
if err != nil {
t.Errorf(err.Error())
}
}
// TestLogout tests the Logout() function. This should not return an error.
func TestLogout(t *testing.T) {

View file

@ -267,7 +267,7 @@ type VoiceState struct {
// A Presence stores the online, offline, or idle and game status of Guild members.
type Presence struct {
User *User `json:"user"`
Status string `json:"status"`
Status Status `json:"status"`
Game *Game `json:"game"`
}
@ -304,21 +304,35 @@ type User struct {
// A Settings stores data for a specific users Discord client settings.
type Settings struct {
RenderEmbeds bool `json:"render_embeds"`
InlineEmbedMedia bool `json:"inline_embed_media"`
InlineAttachmentMedia bool `json:"inline_attachment_media"`
EnableTtsCommand bool `json:"enable_tts_command"`
MessageDisplayCompact bool `json:"message_display_compact"`
ShowCurrentGame bool `json:"show_current_game"`
AllowEmailFriendRequest bool `json:"allow_email_friend_request"`
ConvertEmoticons bool `json:"convert_emoticons"`
Locale string `json:"locale"`
Theme string `json:"theme"`
GuildPositions []string `json:"guild_positions"`
RestrictedGuilds []string `json:"restricted_guilds"`
FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
RenderEmbeds bool `json:"render_embeds"`
InlineEmbedMedia bool `json:"inline_embed_media"`
InlineAttachmentMedia bool `json:"inline_attachment_media"`
EnableTtsCommand bool `json:"enable_tts_command"`
MessageDisplayCompact bool `json:"message_display_compact"`
ShowCurrentGame bool `json:"show_current_game"`
ConvertEmoticons bool `json:"convert_emoticons"`
Locale string `json:"locale"`
Theme string `json:"theme"`
GuildPositions []string `json:"guild_positions"`
RestrictedGuilds []string `json:"restricted_guilds"`
FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
Status Status `json:"status"`
DetectPlatformAccounts bool `json:"detect_platform_accounts"`
DeveloperMode bool `json:"developer_mode"`
}
// Status type defination
type Status string
// Constants for Status with the different current available status
const (
StatusOnline Status = "online"
StatusIdle Status = "idle"
StatusDoNotDisturb Status = "dnd"
StatusInvisible Status = "invisible"
StatusOffline Status = "offline"
)
// FriendSourceFlags stores ... TODO :)
type FriendSourceFlags struct {
All bool `json:"all"`