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

@@ -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,
},