| @@ -112,5 +112,23 @@ namespace Discord.API | |||||
| var request = new APIRequests.SetMemberDeaf { Deaf = false }; | var request = new APIRequests.SetMemberDeaf { Deaf = false }; | ||||
| return Http.Patch(Endpoints.ServerMember(serverId, memberId)); | return Http.Patch(Endpoints.ServerMember(serverId, memberId)); | ||||
| } | } | ||||
| //Profile | |||||
| public static Task<SelfUserInfo> ChangeUsername(string newUsername, string currentEmail, string currentPassword) | |||||
| { | |||||
| var request = new APIRequests.ChangeUsername { Username = newUsername, CurrentEmail = currentEmail, CurrentPassword = currentPassword }; | |||||
| return Http.Patch<SelfUserInfo>(Endpoints.UserMe, request); | |||||
| } | |||||
| public static Task<SelfUserInfo> ChangeEmail(string newEmail, string currentPassword) | |||||
| { | |||||
| var request = new APIRequests.ChangeEmail { Email = newEmail, CurrentPassword = currentPassword }; | |||||
| return Http.Patch<SelfUserInfo>(Endpoints.UserMe, request); | |||||
| } | |||||
| public static Task<SelfUserInfo> ChangePassword(string newPassword, string currentEmail, string currentPassword) | |||||
| { | |||||
| var request = new APIRequests.ChangePassword { NewPassword = newPassword, CurrentEmail = currentEmail, CurrentPassword = currentPassword }; | |||||
| return Http.Patch<SelfUserInfo>(Endpoints.UserMe, request); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -40,7 +40,8 @@ | |||||
| // /api/users | // /api/users | ||||
| public static readonly string Users = $"{BaseApi}/users"; | public static readonly string Users = $"{BaseApi}/users"; | ||||
| public static string UserChannels(string userId) => $"{Users}/{userId}/channels"; | |||||
| public static string UserMe => $"{Users}/@me"; | |||||
| public static string UserChannels(string userId) => $"{Users}/{userId}/channels"; | |||||
| public static string UserAvatar(string userId, string avatarId) => $"{Users}/{userId}/avatars/{avatarId}.jpg"; | public static string UserAvatar(string userId, string avatarId) => $"{Users}/{userId}/avatars/{avatarId}.jpg"; | ||||
| // /api/voice | // /api/voice | ||||
| @@ -75,5 +75,31 @@ namespace Discord.API.Models | |||||
| [JsonProperty(PropertyName = "deaf")] | [JsonProperty(PropertyName = "deaf")] | ||||
| public bool Deaf; | public bool Deaf; | ||||
| } | } | ||||
| public class ChangeUsername | |||||
| { | |||||
| [JsonProperty(PropertyName = "username")] | |||||
| public string Username; | |||||
| [JsonProperty(PropertyName = "email")] | |||||
| public string CurrentEmail; | |||||
| [JsonProperty(PropertyName = "password")] | |||||
| public string CurrentPassword; | |||||
| } | |||||
| public class ChangeEmail | |||||
| { | |||||
| [JsonProperty(PropertyName = "email")] | |||||
| public string Email; | |||||
| [JsonProperty(PropertyName = "password")] | |||||
| public string CurrentPassword; | |||||
| } | |||||
| public class ChangePassword | |||||
| { | |||||
| [JsonProperty(PropertyName = "new_password")] | |||||
| public string NewPassword; | |||||
| [JsonProperty(PropertyName = "email")] | |||||
| public string CurrentEmail; | |||||
| [JsonProperty(PropertyName = "password")] | |||||
| public string CurrentPassword; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -89,6 +89,12 @@ namespace Discord | |||||
| public readonly User User; | public readonly User User; | ||||
| internal UserEventArgs(User user) { User = user; } | internal UserEventArgs(User user) { User = user; } | ||||
| } | } | ||||
| public event EventHandler<UserEventArgs> UserUpdated; | |||||
| private void RaiseUserUpdated(User user) | |||||
| { | |||||
| if (UserUpdated != null) | |||||
| UserUpdated(this, new UserEventArgs(user)); | |||||
| } | |||||
| //Message | //Message | ||||
| public sealed class MessageEventArgs : EventArgs | public sealed class MessageEventArgs : EventArgs | ||||
| @@ -381,6 +381,13 @@ namespace Discord | |||||
| break; | break; | ||||
| //Settings | //Settings | ||||
| case "USER_UPDATE": | |||||
| { | |||||
| var data = e.Event.ToObject<WebSocketEvents.UserUpdate>(); | |||||
| var user = _users.Update(data.Id, data); | |||||
| RaiseUserUpdate(user); | |||||
| } | |||||
| break; | |||||
| case "USER_SETTINGS_UPDATE": | case "USER_SETTINGS_UPDATE": | ||||
| { | { | ||||
| //TODO: Process this | //TODO: Process this | ||||
| @@ -844,6 +851,27 @@ namespace Discord | |||||
| return DiscordAPI.Undeafen(serverId, userId); | return DiscordAPI.Undeafen(serverId, userId); | ||||
| } | } | ||||
| //Profile | |||||
| public async Task ChangeUsername(string newName, string currentEmail, string currentPassword) | |||||
| { | |||||
| CheckReady(); | |||||
| var response = await DiscordAPI.ChangeUsername(newName, currentEmail, currentPassword); | |||||
| _users.Update(response.Id, response); | |||||
| } | |||||
| public async Task ChangeEmail(string newEmail, string currentPassword) | |||||
| { | |||||
| CheckReady(); | |||||
| var response = await DiscordAPI.ChangeEmail(newEmail, currentPassword); | |||||
| _users.Update(response.Id, response); | |||||
| } | |||||
| public async Task ChangePassword(string newPassword, string currentEmail, string currentPassword) | |||||
| { | |||||
| CheckReady(); | |||||
| var response = await DiscordAPI.ChangePassword(newPassword, currentEmail, currentPassword); | |||||
| _users.Update(response.Id, response); | |||||
| } | |||||
| //Helpers | |||||
| private void CheckReady() | private void CheckReady() | ||||
| { | { | ||||
| if (!_isReady) | if (!_isReady) | ||||