Improved Guild#createChannel, added RoleResolvable and fixed a bit of Emoji stuff (#1754)

* Made creating channels with overwrites nicer
and added ClientDataResolver#resolveRole

* Renamed ChannelPermissionOverwrites to ChannelCreationOverwrites

* Added RoleResolvables everywhere possible

* Fixed Emoji#setName resetting restricted roles and Emoji#equals

Which will lead to emojis not to update when roles are being added removed.
This commit is contained in:
SpaceEEC
2017-08-10 01:22:57 +02:00
committed by Crawl
parent 48b69c6e2f
commit 87cdad332c
5 changed files with 132 additions and 53 deletions

View File

@@ -324,7 +324,7 @@ class GuildMember {
* The data for editing a guild member.
* @typedef {Object} GuildMemberEditData
* @property {string} [nick] The nickname to set for the member
* @property {Collection<Snowflake, Role>|Role[]|Snowflake[]} [roles] The roles or role IDs to apply
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles or role IDs to apply
* @property {boolean} [mute] Whether or not the member should be muted
* @property {boolean} [deaf] Whether or not the member should be deafened
* @property {ChannelResolvable} [channel] Channel to move member to (if they are connected to voice)
@@ -384,7 +384,7 @@ class GuildMember {
/**
* Sets the roles applied to the member.
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to apply
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role IDs to apply
* @param {string} [reason] Reason for applying the roles
* @returns {Promise<GuildMember>}
*/
@@ -394,12 +394,12 @@ class GuildMember {
/**
* Adds a single role to the member.
* @param {Role|Snowflake} role The role or ID of the role to add
* @param {RoleResolvable} role The role or ID of the role to add
* @param {string} [reason] Reason for adding the role
* @returns {Promise<GuildMember>}
*/
addRole(role, reason) {
if (!(role instanceof Role)) role = this.guild.roles.get(role);
role = this.client.resolver.resolveRole(this.guild, role);
if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake'));
if (this._roles.includes(role.id)) return Promise.resolve(this);
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
@@ -409,30 +409,33 @@ class GuildMember {
/**
* Adds multiple roles to the member.
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to add
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role IDs to add
* @param {string} [reason] Reason for adding the roles
* @returns {Promise<GuildMember>}
*/
addRoles(roles, reason) {
let allRoles;
if (roles instanceof Collection) {
allRoles = this._roles.slice();
for (const role of roles.values()) allRoles.push(role.id ? role.id : role);
} else {
allRoles = this._roles.concat(roles.map(r => r.id ? r.id : r));
let allRoles = this._roles.slice();
for (let role of roles instanceof Collection ? roles.values() : roles) {
role = this.client.resolver.resolveRole(this.guild, role);
if (!role) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true));
}
allRoles.push(role.id);
}
return this.edit({ roles: allRoles }, reason);
}
/**
* Removes a single role from the member.
* @param {Role|Snowflake} role The role or ID of the role to remove
* @param {RoleResolvable} role The role or ID of the role to remove
* @param {string} [reason] Reason for removing the role
* @returns {Promise<GuildMember>}
*/
removeRole(role, reason) {
if (!(role instanceof Role)) role = this.guild.roles.get(role);
role = this.client.resolver.resolveRole(this.guild, role);
if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake'));
if (!this._roles.includes(role.id)) return Promise.resolve(this);
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
.delete({ reason })
.then(() => this);
@@ -440,22 +443,20 @@ class GuildMember {
/**
* Removes multiple roles from the member.
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to remove
* @param {Collection<Snowflake, Role>|RoleResolvable[]} roles The roles or role IDs to remove
* @param {string} [reason] Reason for removing the roles
* @returns {Promise<GuildMember>}
*/
removeRoles(roles, reason) {
const allRoles = this._roles.slice();
if (roles instanceof Collection) {
for (const role of roles.values()) {
const index = allRoles.indexOf(role.id);
if (index >= 0) allRoles.splice(index, 1);
}
} else {
for (const role of roles) {
const index = allRoles.indexOf(role instanceof Role ? role.id : role);
if (index >= 0) allRoles.splice(index, 1);
for (let role of roles instanceof Collection ? roles.values() : roles) {
role = this.client.resolver.resolveRole(this.guild, role);
if (!role) {
return Promise.reject(new TypeError('INVALID_TYPE', 'roles',
'Array or Collection of Roles or Snowflakes', true));
}
const index = allRoles.indexOf(role.id);
if (index >= 0) allRoles.splice(index, 1);
}
return this.edit({ roles: allRoles }, reason);
}