Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly mapping overwrites when creating a channel and renamed all relevant property names as of #1562 #1570

Merged
merged 4 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 instanceof Array) {
overwrites = overwrites.map(overwrite => ({
allow: overwrite.allow || overwrite._allowed,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.allowed

deny: overwrite.deny || overwrite._denied,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.denied

type: overwrite.type,
id: overwrite.id,
}));
}
return this.client.api.guilds(this.id).channels.post({
data: {
name, type, permission_overwrites: overwrites,
Expand Down
20 changes: 10 additions & 10 deletions src/structures/GuildChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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._allowed;
}

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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -301,7 +301,7 @@ class GuildChannel extends Channel {
* @returns {Promise<GuildChannel>}
*/
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);
}

Expand Down