From 09ade1c2d9a4e295a893ef2235234892ed4bb68c Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 8 Jun 2017 00:32:08 +0200 Subject: [PATCH 1/4] using correct properties to apply permissionOverwrites and fixed `GuildChannel#clone` --- src/structures/Guild.js | 9 ++++++++- src/structures/GuildChannel.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 61c3d5d25231..5d6bcdec994a 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -843,7 +843,14 @@ class Guild { * .catch(console.error); */ createChannel(name, type, { overwrites, reason } = {}) { - if (overwrites instanceof Collection) overwrites = overwrites.array(); + if (overwrites instanceof Collection) { + overwrites = overwrites.map(overwrite => ({ + allow: overwrite._allowed, + deny: overwrite._denied, + type: overwrite.type, + id: overwrite.id, + })); + } return this.client.api.guilds(this.id).channels.post({ data: { name, type, permission_overwrites: overwrites, diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index 81976e987a60..c50efe63f5b6 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -301,7 +301,7 @@ class GuildChannel extends Channel { * @returns {Promise} */ clone(name = this.name, withPermissions = true, withTopic = true) { - return this.guild.createChannel(name, this.type, withPermissions ? this.permissionOverwrites : []) + return this.guild.createChannel(name, this.type, { overwrites: withPermissions ? this.permissionOverwrites : [] }) .then(channel => withTopic ? channel.setTopic(this.topic) : channel); } From e8dc046fab9487e7b63e45c548df5ef1dad2d032 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 8 Jun 2017 01:02:17 +0200 Subject: [PATCH 2/4] also arrays should be mapped and correct properties taking priority --- src/structures/Guild.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 5d6bcdec994a..a6497869038e 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -843,10 +843,10 @@ class Guild { * .catch(console.error); */ createChannel(name, type, { overwrites, reason } = {}) { - if (overwrites instanceof Collection) { + if (overwrites instanceof Collection || overwrites instanceof Array) { overwrites = overwrites.map(overwrite => ({ - allow: overwrite._allowed, - deny: overwrite._denied, + allow: overwrite.allow || overwrite._allowed, + deny: overwrite.deny || overwrite._denied, type: overwrite.type, id: overwrite.id, })); From df3b92f2b1ef7bc22ecb9491adeafc7cbc6d3b16 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 15 Jun 2017 19:20:58 +0200 Subject: [PATCH 3/4] changed .deny and .allow to .denied and .allowed respectively --- src/structures/GuildChannel.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index c50efe63f5b6..528a5b9ef6f3 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -76,20 +76,20 @@ class GuildChannel extends Channel { const overwrites = this.overwritesFor(member, true, roles); if (overwrites.everyone) { - permissions &= ~overwrites.everyone.deny; - permissions |= overwrites.everyone.allow; + permissions &= ~overwrites.everyone._denied; + permissions |= overwrites.everyone._alloweded; } let allow = 0; for (const overwrite of overwrites.roles) { - permissions &= ~overwrite.deny; - allow |= overwrite.allow; + permissions &= ~overwrite._denied; + allow |= overwrite._allowed; } permissions |= allow; if (overwrites.member) { - permissions &= ~overwrites.member.deny; - permissions |= overwrites.member.allow; + permissions &= ~overwrites.member._denied; + permissions |= overwrites.member._allowed; } const admin = Boolean(permissions & Permissions.FLAGS.ADMINISTRATOR); @@ -171,8 +171,8 @@ class GuildChannel extends Channel { const prevOverwrite = this.permissionOverwrites.get(userOrRole.id); if (prevOverwrite) { - payload.allow = prevOverwrite.allow; - payload.deny = prevOverwrite.deny; + payload.allow = prevOverwrite._allowed; + payload.deny = prevOverwrite._denied; } for (const perm in options) { @@ -290,7 +290,7 @@ class GuildChannel extends Channel { return this.client.api.channels(this.id).invites.post({ data: { temporary, max_age: maxAge, max_uses: maxUses, }, reason }) - .then(invite => new Invite(this.client, invite)); + .then(invite => new Invite(this.client, invite)); } /** From da5f238379013a28adcb3f0ee7d0c372021e825c Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Fri, 16 Jun 2017 01:50:17 +0200 Subject: [PATCH 4/4] whoops --- src/structures/GuildChannel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index 528a5b9ef6f3..0ea97a9f6895 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -77,7 +77,7 @@ class GuildChannel extends Channel { if (overwrites.everyone) { permissions &= ~overwrites.everyone._denied; - permissions |= overwrites.everyone._alloweded; + permissions |= overwrites.everyone._allowed; } let allow = 0;