33import { Channel , ChannelPermissionOverwrite , Guild , Member , Role } from "../entities" ;
44import { BitField } from "./BitField" ;
55import "missing-native-js-functions" ;
6+ import { BitFieldResolvable } from "." ;
67// TODO: check role hierarchy permission
78
89var HTTPError : any ;
@@ -17,11 +18,19 @@ export type PermissionResolvable = bigint | number | Permissions | PermissionRes
1718
1819type PermissionString = keyof typeof Permissions . FLAGS ;
1920
20- const CUSTOM_PERMISSION_OFFSET = BigInt ( 1 ) << BigInt ( 48 ) ; // 16 free custom permission bits, and 11 for discord to add new ones
21+ // BigInt doesn't have a bit limit (https://stackoverflow.com/questions/53335545/whats-the-biggest-bigint-value-in-js-as-per-spec)
22+ const CUSTOM_PERMISSION_OFFSET = BigInt ( 1 ) << BigInt ( 64 ) ; // 27 permission bits left for discord to add new ones
2123
2224export class Permissions extends BitField {
2325 cache : PermissionCache = { } ;
2426
27+ constructor ( bits : BitFieldResolvable = 0 ) {
28+ super ( bits ) ;
29+ if ( this . bitfield & Permissions . FLAGS . ADMINISTRATOR ) {
30+ this . bitfield = ALL_PERMISSIONS ;
31+ }
32+ }
33+
2534 static FLAGS = {
2635 CREATE_INSTANT_INVITE : BigInt ( 1 ) << BigInt ( 0 ) ,
2736 KICK_MEMBERS : BigInt ( 1 ) << BigInt ( 1 ) ,
@@ -92,7 +101,7 @@ export class Permissions extends BitField {
92101 }
93102
94103 overwriteChannel ( overwrites : ChannelPermissionOverwrite [ ] ) {
95- if ( ! overwrites ) return this
104+ if ( ! overwrites ) return this ;
96105 if ( ! this . cache ) throw new Error ( "permission chache not available" ) ;
97106 overwrites = overwrites . filter ( ( x ) => {
98107 if ( x . type === 0 && this . cache . roles ?. some ( ( r ) => r . id === x . id ) ) return true ;
@@ -175,6 +184,8 @@ export class Permissions extends BitField {
175184 }
176185}
177186
187+ const ALL_PERMISSIONS = Object . values ( Permissions . FLAGS ) . reduce ( ( total , val ) => total | val , BigInt ( 0 ) ) ;
188+
178189export type PermissionCache = {
179190 channel ?: Channel | undefined ;
180191 member ?: Member | undefined ;
0 commit comments