diff options
author | xnacly <matteogropp@gmail.com> | 2021-04-08 15:56:09 +0200 |
---|---|---|
committer | xnacly <matteogropp@gmail.com> | 2021-04-08 15:56:09 +0200 |
commit | 9e7963824a47757d747ff5eda0226d939812f462 (patch) | |
tree | 3b8301c915b0cbffb2babcf19c3c505dff139e27 | |
parent | :art: Message (diff) | |
download | server-9e7963824a47757d747ff5eda0226d939812f462.tar.xz |
added hasThrow
-rw-r--r-- | src/util/Permissions.ts | 10 |
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) => { |