From 9c52030c292fef774567201633f4dc53f532c081 Mon Sep 17 00:00:00 2001 From: Johnson Chen Date: Sat, 12 Aug 2017 20:01:43 +1000 Subject: [PATCH] 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 --- src/structures/ClientUser.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index e533e2284..1190feb3c 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -93,19 +93,20 @@ class ClientUser extends User { } } - edit(data, password) { - const _data = {}; - _data.username = data.username || this.username; - _data.avatar = this.client.resolver.resolveBase64(data.avatar); - + edit(data, passcode) { if (!this.bot) { - _data.email = data.email || this.email; - _data.password = password; - if (data.new_password) _data.new_password = data.newPassword; + if (typeof passcode !== 'object') { + data.password = passcode; + } else { + data.code = passcode.mfaCode; + data.password = passcode.password; + } } - 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. * This is only available when using a user account. * @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} * @example * // Set password @@ -153,8 +157,8 @@ class ClientUser extends User { * .then(user => console.log('New password set!')) * .catch(console.error); */ - setPassword(newPassword, oldPassword) { - return this.edit({ password: newPassword }, oldPassword); + setPassword(newPassword, options) { + return this.edit({ new_password: newPassword }, { password: options.oldPassword, mfaCode: options.mfaCode }); } /**