make positions for channels and roles nicer (#1211)

* make role calculated position nicer

* make channels sortable in a nice way too

* stupid git web rebase editor

* Update Guild.js

* Update Guild.js

* Update Guild.js

* Update Guild.js

* Update RESTMethods.js
This commit is contained in:
Gus Caplan
2017-04-01 01:28:54 -05:00
committed by Crawl
parent c4e5292516
commit a4e0af2e45
7 changed files with 142 additions and 54 deletions

View File

@@ -46,6 +46,15 @@ class GuildChannel extends Channel {
}
}
/**
* The position of the channel
* @type {number}
*/
get calculatedPosition() {
const sorted = this.guild._sortedChannels(this.type);
return sorted.array().indexOf(sorted.get(this.id));
}
/**
* Gets the overall set of permissions for a user in this channel, taking into account roles and permission
* overwrites.
@@ -220,6 +229,7 @@ class GuildChannel extends Channel {
/**
* Set a new position for the guild channel
* @param {number} position The new position for the guild channel
* @param {boolean} [relative=false] Move the position relative to its current value
* @returns {Promise<GuildChannel>}
* @example
* // set a new channel position
@@ -227,8 +237,8 @@ class GuildChannel extends Channel {
* .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`))
* .catch(console.error);
*/
setPosition(position) {
return this.client.rest.methods.updateChannel(this, { position });
setPosition(position, relative) {
return this.guild.setChannelPosition(this, position, relative).then(() => this);
}
/**