ClientUser Fixes (#1741)

* Fixes #1702

* Remove Comments

* Follow what Gus said... I hope

* JSDoc

* Update ClientUser.js

* TIL my knowledge about JSDocs was a lie
This commit is contained in:
Johnson Chen
2017-08-12 20:01:43 +10:00
committed by Crawl
parent 8034c0437d
commit 9c52030c29

View File

@@ -93,19 +93,20 @@ class ClientUser extends User {
} }
} }
edit(data, password) { edit(data, passcode) {
const _data = {};
_data.username = data.username || this.username;
_data.avatar = this.client.resolver.resolveBase64(data.avatar);
if (!this.bot) { if (!this.bot) {
_data.email = data.email || this.email; if (typeof passcode !== 'object') {
_data.password = password; data.password = passcode;
if (data.new_password) _data.new_password = data.newPassword; } else {
data.code = passcode.mfaCode;
data.password = passcode.password;
}
} }
return this.client.api.users('@me').patch({ data }) return this.client.api.users('@me').patch({ data })
.then(newData => this.client.actions.UserUpdate.handle(newData).updated); .then(newData => {
this.client.token = newData.token;
return this.client.actions.UserUpdate.handle(newData).updated;
});
} }
/** /**
@@ -145,7 +146,10 @@ class ClientUser extends User {
* Changes the password for the client user's account. * Changes the password for the client user's account.
* <warn>This is only available when using a user account.</warn> * <warn>This is only available when using a user account.</warn>
* @param {string} newPassword New password to change to * @param {string} newPassword New password to change to
* @param {string} oldPassword Current password * @param {Object|string} options Object containing an MFA code, password or both.
* Can be just a string for the password.
* @param {string} [options.oldPassword] Current password
* @param {string} [options.mfaCode] Timed MFA Code
* @returns {Promise<ClientUser>} * @returns {Promise<ClientUser>}
* @example * @example
* // Set password * // Set password
@@ -153,8 +157,8 @@ class ClientUser extends User {
* .then(user => console.log('New password set!')) * .then(user => console.log('New password set!'))
* .catch(console.error); * .catch(console.error);
*/ */
setPassword(newPassword, oldPassword) { setPassword(newPassword, options) {
return this.edit({ password: newPassword }, oldPassword); return this.edit({ new_password: newPassword }, { password: options.oldPassword, mfaCode: options.mfaCode });
} }
/** /**