backport: GuildChannel#permissionsFor(role)

This commit is contained in:
Lewdcario
2018-08-08 22:16:46 -05:00
parent c76f3048af
commit 1e5b5b83c8
2 changed files with 52 additions and 29 deletions

View File

@@ -82,11 +82,13 @@ class Permissions {
*/
add(...permissions) {
let total = 0;
for (let p = 0; p < permissions.length; p++) {
for (let p = permissions.length - 1; p >= 0; p--) {
const perm = this.constructor.resolve(permissions[p]);
if ((this.bitfield & perm) !== perm) total |= perm;
total |= perm;
}
return new this.constructor(this.member, this.bitfield | total);
if (Object.isFrozen(this)) return new this.constructor(this.bitfield | total);
this.bitfield |= total;
return this;
}
/**
@@ -96,11 +98,13 @@ class Permissions {
*/
remove(...permissions) {
let total = 0;
for (let p = 0; p < permissions.length; p++) {
for (let p = permissions.length - 1; p >= 0; p--) {
const perm = this.constructor.resolve(permissions[p]);
if ((this.bitfield & perm) === perm) total |= perm;
total |= perm;
}
return new this.constructor(this.member, this.bitfield & ~total);
if (Object.isFrozen(this)) return new this.constructor(this.bitfield & ~total);
this.bitfield &= ~total;
return this;
}
/**