diff --git a/package.json b/package.json index a94704d2..74ba2f0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "revolt.js", - "version": "6.0.0-rc.19", + "version": "6.0.0-rc.20", "main": "dist/index.js", "typings": "dist/index.d.ts", "module": "esm/index.js", diff --git a/src/maps/Channels.ts b/src/maps/Channels.ts index 1f04cc44..eda15859 100644 --- a/src/maps/Channels.ts +++ b/src/maps/Channels.ts @@ -653,11 +653,14 @@ export class Channel { /** * Check whether we have a given permission in a channel - * @param permission Permission Name + * @param permission Permission Names * @returns Whether we have this permission */ - @computed havePermission(permission: keyof typeof Permission) { - return bitwiseAndEq(this.permission, Permission[permission]); + @computed havePermission(...permission: (keyof typeof Permission)[]) { + return bitwiseAndEq( + this.permission, + ...permission.map((x) => Permission[x]), + ); } } diff --git a/src/maps/Members.ts b/src/maps/Members.ts index 15f8102a..cc4d1acb 100644 --- a/src/maps/Members.ts +++ b/src/maps/Members.ts @@ -143,16 +143,16 @@ export class Member { /** * Check whether a member has a certain permission against a certain object * @param target Target object to check permissions against - * @param permission Permission string to check for + * @param permission Permission names to check for * @returns Whether the member has this permission */ @computed hasPermission( target: Server | Channel, - permission: keyof typeof Permission, + ...permission: (keyof typeof Permission)[] ) { return bitwiseAndEq( this.getPermissions(target), - Permission[permission], + ...permission.map((x) => Permission[x]), ); } } diff --git a/src/maps/Servers.ts b/src/maps/Servers.ts index 485d32fe..ff114d8d 100644 --- a/src/maps/Servers.ts +++ b/src/maps/Servers.ts @@ -389,11 +389,14 @@ export class Server { /** * Check whether we have a given permission in a server - * @param permission Permission Name + * @param permission Permission Names * @returns Whether we have this permission */ - @computed havePermission(permission: keyof typeof Permission) { - return bitwiseAndEq(this.permission, Permission[permission]); + @computed havePermission(...permission: (keyof typeof Permission)[]) { + return bitwiseAndEq( + this.permission, + ...permission.map((x) => Permission[x]), + ); } } diff --git a/src/permissions/calculator.ts b/src/permissions/calculator.ts index e72efc09..fdc6686b 100644 --- a/src/permissions/calculator.ts +++ b/src/permissions/calculator.ts @@ -10,10 +10,11 @@ import { /** * Check whether `b` is present in `a` * @param a Input A - * @param b Input B + * @param b Inputs (OR'd together) */ -export function bitwiseAndEq(a: number, b: number) { - return Long.fromNumber(a).and(b).eq(b); +export function bitwiseAndEq(a: number, ...b: number[]) { + const value = b.reduce((prev, cur) => prev.or(cur), Long.fromNumber(0)); + return value.and(a).eq(value); } /**