From 0a951cfc0fe345999209285033dca3a1d33a890b Mon Sep 17 00:00:00 2001 From: Isabella Date: Sat, 3 Mar 2018 18:55:54 -0600 Subject: [PATCH 1/4] docs: TextChannel Webhooks fix&improvement --- src/structures/TextChannel.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index 6c5db54c0..ea199d225 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -55,6 +55,11 @@ class TextChannel extends GuildChannel { /** * Fetches all webhooks for the channel. * @returns {Promise>} + * @example + * // Fetch webhooks + * channel.fetchWebhooks() + * .then(hooks => console.log(`This channel has ${hooks.size} hooks`)) + * .catch(console.error); */ fetchWebhooks() { return this.client.api.channels[this.id].webhooks.get().then(data => { @@ -72,8 +77,12 @@ class TextChannel extends GuildChannel { * @param {string} [options.reason] Reason for creating the webhook * @returns {Promise} webhook The created webhook * @example - * channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg') - * .then(webhook => console.log(`Created webhook ${webhook}`)) + * // Create a webhook for the current channel + * channel.createWebhook('Snek', { + * avatar: 'https://i.imgur.com/mI8XcpG.jpg', + * reason: 'Needed a cool new Webhook' + * }) + * .then(console.log) * .catch(console.error) */ async createWebhook(name, { avatar, reason } = {}) { From 8b679913a455ab059b30ded2cd364f874bab7d38 Mon Sep 17 00:00:00 2001 From: Jonah Snider Date: Sun, 4 Mar 2018 00:16:12 -0800 Subject: [PATCH 2/4] docs: Change 'the this' to this (typo) (#2377) --- src/structures/Role.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/structures/Role.js b/src/structures/Role.js index 58124b3b9..777e1f5ae 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -132,8 +132,8 @@ class Role extends Base { /** * Compares this role's position to another role's. * @param {RoleResolvable} role Role to compare to this one - * @returns {number} Negative number if the this role's position is lower (other role's is higher), - * positive number if the this one is higher (other's is lower), 0 if equal + * @returns {number} Negative number if this role's position is lower (other role's is higher), + * positive number if this one is higher (other's is lower), 0 if equal */ comparePositionTo(role) { role = this.guild.roles.resolve(role); From 3f6a0e4de1ff53f2644c70aeb9e96736328663bf Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 5 Mar 2018 11:32:03 +0100 Subject: [PATCH 3/4] fix(GuildMemberRoleStore): only update roles after successful request Fixes #2381 --- src/stores/GuildMemberRoleStore.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/stores/GuildMemberRoleStore.js b/src/stores/GuildMemberRoleStore.js index eb0096554..95d9daa85 100644 --- a/src/stores/GuildMemberRoleStore.js +++ b/src/stores/GuildMemberRoleStore.js @@ -29,11 +29,9 @@ class GuildMemberRoleStore extends DataStore { if (roleOrRoles.includes(null)) { return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true)); - } else { - for (const role of roleOrRoles) super.set(role.id, role); } - - return this.set(this, reason); + const newRoles = [...new Set(roleOrRoles.concat(this.array()))]; + return this.set(newRoles, reason); } /** @@ -71,11 +69,9 @@ class GuildMemberRoleStore extends DataStore { if (roleOrRoles.includes(null)) { return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true)); - } else { - for (const role of roleOrRoles) super.remove(role); } - - return this.set(this, reason); + const newRoles = [...new Set(roleOrRoles.concat(this.array()))]; + return this.set(newRoles, reason); } /** From 3e6c3107c2010fa63abef77d8e1e2d7fba796751 Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 5 Mar 2018 14:50:59 +0100 Subject: [PATCH 4/4] fix(GuildMemberRoleStore): make remove role remove roles again --- src/stores/GuildMemberRoleStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/GuildMemberRoleStore.js b/src/stores/GuildMemberRoleStore.js index 95d9daa85..a5f781338 100644 --- a/src/stores/GuildMemberRoleStore.js +++ b/src/stores/GuildMemberRoleStore.js @@ -70,7 +70,7 @@ class GuildMemberRoleStore extends DataStore { return Promise.reject(new TypeError('INVALID_TYPE', 'roles', 'Array or Collection of Roles or Snowflakes', true)); } - const newRoles = [...new Set(roleOrRoles.concat(this.array()))]; + const newRoles = this.keyArray().filter(role => !roleOrRoles.includes(role)); return this.set(newRoles, reason); }