Skip to content

Commit dd611d0

Browse files
committed
🐛 fix role can't set permission
1 parent 286b4a6 commit dd611d0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

util/src/util/Permissions.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Channel, ChannelPermissionOverwrite, Guild, Member, Role } from "../entities";
44
import { BitField } from "./BitField";
55
import "missing-native-js-functions";
6+
import { BitFieldResolvable } from ".";
67
// TODO: check role hierarchy permission
78

89
var HTTPError: any;
@@ -17,11 +18,19 @@ export type PermissionResolvable = bigint | number | Permissions | PermissionRes
1718

1819
type 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

2224
export 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+
178189
export type PermissionCache = {
179190
channel?: Channel | undefined;
180191
member?: Member | undefined;

0 commit comments

Comments
 (0)