Organise structure methods

This commit is contained in:
Schuyler Cebulskie
2016-09-07 02:07:39 -04:00
parent 73cb34ed37
commit 818649b94f
13 changed files with 493 additions and 577 deletions

View File

@@ -48,33 +48,6 @@ class GuildChannel extends Channel {
}
}
/**
* Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel.
* In most cases, a simple `channel.id === channel2.id` will do, and is much faster too.
* @param {GuildChannel} channel The channel to compare this channel to
* @returns {boolean}
*/
equals(channel) {
let equal = channel &&
this.id === channel.id &&
this.type === channel.type &&
this.topic === channel.topic &&
this.position === channel.position &&
this.name === channel.name;
if (equal) {
if (channel.permission_overwrites) {
const thisIDSet = Array.from(this.permissionOverwrites.keys());
const otherIDSet = channel.permission_overwrites.map(overwrite => overwrite.id);
equal = arraysEqual(thisIDSet, otherIDSet);
} else {
equal = false;
}
}
return equal;
}
/**
* Gets the overall set of permissions for a user in this channel, taking into account roles and permission
* overwrites.
@@ -237,20 +210,6 @@ class GuildChannel extends Channel {
return this.client.rest.methods.updateChannel(this, { topic });
}
/**
* When concatenated with a string, this automatically returns the Channel's mention instead of the Channel object.
* @returns {string}
* @example
* // Outputs: Hello from #general
* console.log(`Hello from ${channel}`);
* @example
* // Outputs: Hello from #general
* console.log('Hello from ' + channel);
*/
toString() {
return `<#${this.id}>`;
}
/**
* Options given when creating a Guild Channel Invite:
* ```js
@@ -271,6 +230,47 @@ class GuildChannel extends Channel {
createInvite(options = {}) {
return this.client.rest.methods.createChannelInvite(this, options);
}
/**
* Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel.
* In most cases, a simple `channel.id === channel2.id` will do, and is much faster too.
* @param {GuildChannel} channel The channel to compare this channel to
* @returns {boolean}
*/
equals(channel) {
let equal = channel &&
this.id === channel.id &&
this.type === channel.type &&
this.topic === channel.topic &&
this.position === channel.position &&
this.name === channel.name;
if (equal) {
if (channel.permission_overwrites) {
const thisIDSet = Array.from(this.permissionOverwrites.keys());
const otherIDSet = channel.permission_overwrites.map(overwrite => overwrite.id);
equal = arraysEqual(thisIDSet, otherIDSet);
} else {
equal = false;
}
}
return equal;
}
/**
* When concatenated with a string, this automatically returns the Channel's mention instead of the Channel object.
* @returns {string}
* @example
* // Outputs: Hello from #general
* console.log(`Hello from ${channel}`);
* @example
* // Outputs: Hello from #general
* console.log('Hello from ' + channel);
*/
toString() {
return `<#${this.id}>`;
}
}
module.exports = GuildChannel;