summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-25 23:55:40 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-25 23:55:40 +0200
commitdd611d0e7c78eee7266788cbb4f249c005faa285 (patch)
treec33470b3aa59e9c2767af7972843e946a9b050f5 /util/src
parent:sparkles: add private and public endpoint (diff)
downloadserver-dd611d0e7c78eee7266788cbb4f249c005faa285.tar.xz
:bug: fix role can't set permission
Diffstat (limited to 'util/src')
-rw-r--r--util/src/util/Permissions.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/util/src/util/Permissions.ts b/util/src/util/Permissions.ts
index 44852f1e..f0012c96 100644
--- a/util/src/util/Permissions.ts
+++ b/util/src/util/Permissions.ts
@@ -3,6 +3,7 @@
 import { Channel, ChannelPermissionOverwrite, Guild, Member, Role } from "../entities";
 import { BitField } from "./BitField";
 import "missing-native-js-functions";
+import { BitFieldResolvable } from ".";
 // TODO: check role hierarchy permission
 
 var HTTPError: any;
@@ -17,11 +18,19 @@ export type PermissionResolvable = bigint | number | Permissions | PermissionRes
 
 type PermissionString = keyof typeof Permissions.FLAGS;
 
-const CUSTOM_PERMISSION_OFFSET = BigInt(1) << BigInt(48); // 16 free custom permission bits, and 11 for discord to add new ones
+// BigInt doesn't have a bit limit (https://stackoverflow.com/questions/53335545/whats-the-biggest-bigint-value-in-js-as-per-spec)
+const CUSTOM_PERMISSION_OFFSET = BigInt(1) << BigInt(64); // 27 permission bits left for discord to add new ones
 
 export class Permissions extends BitField {
 	cache: PermissionCache = {};
 
+	constructor(bits: BitFieldResolvable = 0) {
+		super(bits);
+		if (this.bitfield & Permissions.FLAGS.ADMINISTRATOR) {
+			this.bitfield = ALL_PERMISSIONS;
+		}
+	}
+
 	static FLAGS = {
 		CREATE_INSTANT_INVITE: BigInt(1) << BigInt(0),
 		KICK_MEMBERS: BigInt(1) << BigInt(1),
@@ -92,7 +101,7 @@ export class Permissions extends BitField {
 	}
 
 	overwriteChannel(overwrites: ChannelPermissionOverwrite[]) {
-		if (!overwrites) return this
+		if (!overwrites) return this;
 		if (!this.cache) throw new Error("permission chache not available");
 		overwrites = overwrites.filter((x) => {
 			if (x.type === 0 && this.cache.roles?.some((r) => r.id === x.id)) return true;
@@ -175,6 +184,8 @@ export class Permissions extends BitField {
 	}
 }
 
+const ALL_PERMISSIONS = Object.values(Permissions.FLAGS).reduce((total, val) => total | val, BigInt(0));
+
 export type PermissionCache = {
 	channel?: Channel | undefined;
 	member?: Member | undefined;