diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/context.rs | 4 | ||||
| -rw-r--r-- | src/client/rest/mod.rs | 22 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index bc983bf..6968233 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -828,7 +828,7 @@ impl Context { rest::edit_nickname(guild_id.into().0, new_nickname) } - /// Edits the current user's settings. + /// Edits the current user's profile settings. /// /// Refer to `EditProfile`'s documentation for its methods. /// @@ -840,7 +840,7 @@ impl Context { /// context.edit_member(|p| /// p.username("meew zero")); /// ``` - pub fn edit_profile<F: FnOnce(EditProfile) -> EditProfile>(&mut self, f: F) + pub fn edit_profile<F: FnOnce(EditProfile) -> EditProfile>(&self, f: F) -> Result<CurrentUser> { let user = try!(rest::get_current_user()); diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs index a325f15..d5e5761 100644 --- a/src/client/rest/mod.rs +++ b/src/client/rest/mod.rs @@ -690,12 +690,30 @@ pub fn edit_note(user_id: u64, map: Value) -> Result<()> { user_id)) } -/// Edits profile we're connected to. +/// Edits the current user's profile settings. +/// +/// For bot users, the password is optional. +/// +/// # User Accounts +/// +/// If a new token is received due to a password change, then the stored token +/// internally will be updated. +/// +/// **Note**: this token change may cause requests made between the actual token +/// change and when the token is internally changed to be invalid requests, as +/// the token may be outdated. +/// pub fn edit_profile(map: Value) -> Result<CurrentUser> { let body = try!(serde_json::to_string(&map)); let response = request!(Route::UsersMe, patch(body), "/users/@me"); - CurrentUser::decode(try!(serde_json::from_reader(response))) + let mut map: BTreeMap<String, Value> = try!(serde_json::from_reader(response)); + + if let Some(Value::String(token)) = map.remove("token") { + set_token(&token) + } + + CurrentUser::decode(Value::Object(map)) } /// Changes a role in a guild. |