serious role position stuff (#1159)

* serious role position stuff

* kill meh

* Update Role.js

* Update Guild.js

* Update Role.js
This commit is contained in:
Gus Caplan
2017-02-01 16:02:16 -06:00
committed by Amish Shah
parent a2d6791cd8
commit 1e94a9e2a4
4 changed files with 39 additions and 23 deletions

View File

@@ -48,7 +48,7 @@ class Role {
this.hoist = data.hoist;
/**
* The position of the role in the role manager
* The position of the role from the API
* @type {number}
*/
this.position = data.position;
@@ -122,6 +122,16 @@ class Role {
return clientMember.highestRole.comparePositionTo(this) > 0;
}
/**
* The position of the role in the role manager
* @type {number}
*/
get calculatedPosition() {
const sorted = this.guild.roles.array()
.sort((r1, r2) => r1.position !== r2.position ? r1.position - r2.position : r1.id - r2.id);
return sorted.indexOf(sorted.find(r => r.id === this.id));
}
/**
* Get an object mapping permission names to whether or not the role enables that permission
* @returns {Object<string, boolean>}
@@ -246,6 +256,7 @@ class Role {
/**
* Set the position of the role
* @param {number} position The position of the role
* @param {boolean} [relative=false] Move the position relative to its current value
* @returns {Promise<Role>}
* @example
* // set the position of the role
@@ -253,8 +264,8 @@ class Role {
* .then(r => console.log(`Role position: ${r.position}`))
* .catch(console.error);
*/
setPosition(position) {
return this.guild.setRolePosition(this, position).then(() => this);
setPosition(position, relative) {
return this.guild.setRolePosition(this, position, relative).then(() => this);
}
/**