summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorxnacly <matteogropp@gmail.com>2021-04-08 15:56:09 +0200
committerxnacly <matteogropp@gmail.com>2021-04-08 15:56:09 +0200
commit9e7963824a47757d747ff5eda0226d939812f462 (patch)
tree3b8301c915b0cbffb2babcf19c3c505dff139e27 /src
parent:art: Message (diff)
downloadserver-9e7963824a47757d747ff5eda0226d939812f462.tar.xz
added hasThrow
Diffstat (limited to 'src')
-rw-r--r--src/util/Permissions.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/Permissions.ts b/src/util/Permissions.ts

index ae21e138..88a54954 100644 --- a/src/util/Permissions.ts +++ b/src/util/Permissions.ts
@@ -97,6 +97,16 @@ export class Permissions extends BitField { return (checkAdmin && super.has(Permissions.FLAGS.ADMINISTRATOR)) || super.has(permission); } + /** + * Checks whether the bitfield has a permission, or multiple permissions, but throws an Error if user fails to match auth criteria. + */ + hasThrow(permission: PermissionResolvable, checkAdmin = true) { + if ((checkAdmin && super.has(Permissions.FLAGS.ADMINISTRATOR)) || super.has(permission)) { + return true; + } + throw new Error(`User doesn't fulfill the following permission criteria: ${permission}`); + } + static channelPermission(overwrites: ChannelPermissionOverwrite[], init?: bigint) { // TODO: do not deny any permissions if admin return overwrites.reduce((permission, overwrite) => {