feature(CategoryChannel): backport (#2117)

* feature(CategoryChannel): backport


fix


no

* ????

* bad ternary
This commit is contained in:
Isabella
2017-11-19 22:19:46 -06:00
committed by Schuyler Cebulskie
parent b274dba6ec
commit cce2480bb5
7 changed files with 55 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
const GuildChannel = require('./GuildChannel');
/**
* Represents a guild category channel on Discord.
* @extends {GuildChannel}
*/
class CategoryChannel extends GuildChannel {
/**
* The channels that are part of this category
* @type {?Collection<Snowflake, GuildChannel>}
* @readonly
*/
get children() {
return this.guild.channels.filter(c => c.parentID === this.id);
}
}
module.exports = CategoryChannel;

View File

@@ -876,7 +876,7 @@ class Guild {
/**
* Creates a new channel in the guild.
* @param {string} name The name of the new channel
* @param {string} type The type of the new channel, either `text` or `voice`
* @param {string} type The type of the new channel, either `text` or `voice` or `category`
* @param {Array<PermissionOverwrites|Object>} [overwrites] Permission overwrites to apply to the new channel
* @param {string} [reason] Reason for creating this channel
* @returns {Promise<TextChannel|VoiceChannel>}

View File

@@ -35,6 +35,12 @@ class GuildChannel extends Channel {
*/
this.position = data.position;
/**
* The ID of the category parent of this channel
* @type {?Snowflake}
*/
this.parentID = data.parent_id;
/**
* A map of permission overwrites in this channel for roles and users
* @type {Collection<Snowflake, PermissionOverwrites>}
@@ -57,6 +63,15 @@ class GuildChannel extends Channel {
return sorted.array().indexOf(sorted.get(this.id));
}
/**
* The category parent of this channel
* @type {?CategoryChannel}
* @readonly
*/
get parent() {
return this.guild.channels.get(this.parentID) || null;
}
/**
* Gets the overall set of permissions for a user in this channel, taking into account roles and permission
* overwrites.
@@ -213,7 +228,7 @@ class GuildChannel extends Channel {
* .catch(console.error);
*/
edit(data, reason) {
return this.client.rest.methods.updateChannel(this, data, reason);
return this.client.rest.methods.updateChannel(this, data, reason).then(() => this);
}
/**
@@ -243,7 +258,18 @@ class GuildChannel extends Channel {
* .catch(console.error);
*/
setPosition(position, relative) {
return this.guild.setChannelPosition(this, position, relative).then(() => this);
return this.guild.setChannelPosition(this, position, relative);
}
/**
* Set a new parent for the guild channel.
* @param {GuildChannel|SnowFlake} parent The new parent for the guild channel
* @param {string} [reason] Reason for changing the guild channel's parent
* @returns {Promise<GuildChannel>}
*/
setParent(parent, reason) {
parent = this.client.resolver.resolveChannelID(parent);
return this.edit({ parent }, reason);
}
/**

View File

@@ -124,7 +124,7 @@ class OAuth2Application {
/**
* Reset the app's secret and bot token.
* <warn>This is only available when using a user account.</warn>
* <warn>This is only available when using a user account.</warn>
* @returns {OAuth2Application}
*/
reset() {