From 412ba2b28dd321c544ee3f6ab825f7b5ea707dd5 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Thu, 8 Sep 2022 00:02:18 -0500 Subject: [PATCH] refactor: permissions (which fixes bug on last commit) --- packages/core/src/structures/special/permissions.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/core/src/structures/special/permissions.ts b/packages/core/src/structures/special/permissions.ts index fac8190..f8931f5 100644 --- a/packages/core/src/structures/special/permissions.ts +++ b/packages/core/src/structures/special/permissions.ts @@ -13,7 +13,8 @@ export type PermissionResolvable = | bigint | PermissionString | PermissionString[] - | BitwisePermissionFlags; + | BitwisePermissionFlags + | BitwisePermissionFlags[]; export class Permissions implements BitField { /** Stores a reference to BitwisePermissionFlags */ @@ -71,7 +72,7 @@ export class Permissions implements BitField { return true; } - return (this.bitfield & bbit) !== bbit; + return (this.bitfield & bbit) === bbit; } any(bit: PermissionResolvable): boolean { @@ -81,7 +82,7 @@ export class Permissions implements BitField { return true; } - return (this.bitfield & bbit) === 0n; + return (this.bitfield & bbit) !== Permissions.None; } equals(bit: PermissionResolvable): boolean { @@ -113,13 +114,17 @@ export class Permissions implements BitField { return Permissions.resolve( bit .map(p => BigInt(Permissions.Flags[p])) - .reduce((acc, cur) => acc | cur, 0n) + .reduce((acc, cur) => acc | cur, Permissions.None) ); default: throw new TypeError(`Cannot resolve permission: ${bit}`); } } + static sum(permissions: Array) { + return permissions.reduce((y, x) => BigInt(y) | BigInt(x), Permissions.None); + } + static reduce(permissions: PermissionResolvable[]): Permissions { const solved = permissions.map(Permissions.resolve);