fix(GuildChannel|Role.edit) Editing with a position not being right (#2010)

* Fix GuildChannel.edit and Role.edit for positions

* Re-use Util.setPosition
And also make it even more compact! And it works! \o/
This commit is contained in:
Frangu Vlad
2017-10-19 08:10:39 +03:00
committed by Crawl
parent 8d7e745ee8
commit 37f5256a04
2 changed files with 22 additions and 4 deletions

View File

@@ -275,12 +275,21 @@ class GuildChannel extends Channel {
* .then(c => console.log(`Edited channel ${c}`))
* .catch(console.error);
*/
edit(data, reason) {
async edit(data, reason) {
if (typeof data.position !== 'undefined') {
await Util.setPosition(this, data.position, false,
this.guild._sortedChannels(this), this.client.api.guilds(this.guild.id).channels, reason)
.then(updatedChannels => {
this.client.actions.GuildChannelsPositionUpdate.handle({
guild_id: this.guild.id,
channels: updatedChannels,
});
});
}
return this.client.api.channels(this.id).patch({
data: {
name: (data.name || this.name).trim(),
topic: data.topic,
position: typeof data.position === 'number' ? data.position : this.rawPosition,
bitrate: data.bitrate || (this.bitrate ? this.bitrate * 1000 : undefined),
user_limit: data.userLimit != null ? data.userLimit : this.userLimit, // eslint-disable-line eqeqeq
parent_id: data.parentID,

View File

@@ -165,15 +165,24 @@ class Role extends Base {
* .then(r => console.log(`Edited role ${r}`))
* .catch(console.error);
*/
edit(data, reason) {
async edit(data, reason) {
if (data.permissions) data.permissions = Permissions.resolve(data.permissions);
else data.permissions = this.permissions.bitfield;
if (typeof data.position !== 'undefined') {
await Util.setPosition(this, data.position, false, this.guild._sortedRoles(),
this.client.api.guilds(this.guild.id).roles, reason)
.then(updatedRoles => {
this.client.actions.GuildRolesPositionUpdate.handle({
guild_id: this.guild.id,
roles: updatedRoles,
});
});
}
return this.client.api.guilds[this.guild.id].roles[this.id].patch({
data: {
name: data.name || this.name,
color: Util.resolveColor(data.color || this.color),
hoist: typeof data.hoist !== 'undefined' ? data.hoist : this.hoist,
position: typeof data.position !== 'undefined' ? data.position : this.position,
permissions: data.permissions,
mentionable: typeof data.mentionable !== 'undefined' ? data.mentionable : this.mentionable,
},