Fix nickname checks and add changing nicknames programmatically

This commit is contained in:
Samuel Elliott 2018-04-25 13:40:18 +01:00
parent c3e4563aeb
commit c294df6b26
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 21 additions and 1 deletions

View File

@ -53,6 +53,7 @@ export const Modules = {
get NotificationSettingsModal() { return this._getModule('NotificationSettingsModal'); },
get PrivacySettingsModal() { return this._getModule('PrivacySettingsModal'); },
get UserProfileModal() { return this._getModule('UserProfileModal'); },
get APIModule() { return this._getModule('APIModule'); },
get DiscordPermissions() { return this.DiscordConstants.Permissions; }
};

View File

@ -170,10 +170,29 @@ export class GuildMember {
* Opens the modal to change this user's nickname.
*/
openChangeNicknameModal() {
if (DiscordApi.currentUser !== this) this.assertPermissions('MANAGE_NICKNAMES', Modules.DiscordPermissions.MANAGE_NICKNAMES);
if (DiscordApi.currentUser === this.user)
this.assertPermissions('CHANGE_NICKNAME', Modules.DiscordPermissions.CHANGE_NICKNAME);
else this.assertPermissions('MANAGE_NICKNAMES', Modules.DiscordPermissions.MANAGE_NICKNAMES);
Modules.ChangeNicknameModal.open(this.guild_id, this.user_id);
}
/**
* Changes the user's nickname on this guild.
* @param {String} nickname The user's new nickname
* @return {Promise}
*/
changeNickname(nick) {
if (DiscordApi.currentUser === this.user)
this.assertPermissions('CHANGE_NICKNAME', Modules.DiscordPermissions.CHANGE_NICKNAME);
else this.assertPermissions('MANAGE_NICKNAMES', Modules.DiscordPermissions.MANAGE_NICKNAMES);
return Modules.APIModule.patch({
url: `${Modules.DiscordConstants.Endpoints.GUILD_MEMBERS(this.guild_id)}/${DiscordApi.currentUser === this.user ? '@me/nick' : this.user_id}`,
body: { nick }
});
}
/**
* Kicks this user from the guild.
* @param {String} reason A reason to attach to the audit log entry