fix perms for server update

This commit is contained in:
MathMan05
2026-07-15 13:03:26 -05:00
parent f2d04f5786
commit 194229acef
3 changed files with 39 additions and 4 deletions
+10 -4
View File
@@ -868,15 +868,21 @@ class Channel extends SnowFlake {
}
}
let deny = false;
for (const role of member.roles) {
const premission = this.permissionOverwriteMap.get(role.id);
if (premission) {
const perm = premission.getPermission(name);
if (perm) {
return perm === 1;
if (perm === 1) {
return true;
} else {
deny = true;
}
}
}
if (deny) return false;
for (const role of member.roles) {
if (role.permissions.getPermission(name)) {
return true;
@@ -3955,8 +3961,8 @@ class Channel extends SnowFlake {
method: "PUT",
headers: this.headers,
body: JSON.stringify({
allow: perms.allow.toString(),
deny: perms.deny.toString(),
allow: (perms.allow & ~Permissions.noOverwriteMask).toString(),
deny: (perms.deny & ~Permissions.noOverwriteMask).toString(),
id,
type: this.localuser.userMap.get(id) ? 1 : 0,
}),
+28
View File
@@ -24,6 +24,15 @@ class Permissions {
const bit = 1n << BigInt(b);
return (big & ~bit) | (BigInt(state) << BigInt(b)); //thanks to geotale for this code :3
}
static toMask(perms: string[]): bigint {
return perms.reduce<bigint>((p, c) => {
const bit = this.permisions.indexOf(c as any);
if (bit !== -1) {
return p | (1n << BigInt(bit));
}
return p;
}, 0n);
}
//private static info: { name: string; readableName: string; description: string }[];
static *info(): Generator<{name: string; readableName: string; description: string}> {
for (const thing of this.permisions) {
@@ -87,6 +96,22 @@ class Permissions {
"PIN_MESSAGES",
"BYPASS_SLOWMODE",
] as const;
static noOverwrite = [
"KICK_MEMBERS",
"BAN_MEMBERS",
"ADMINISTRATOR",
"MANAGE_GUILD",
"VIEW_AUDIT_LOG",
"VIEW_GUILD_INSIGHTS",
"CHANGE_NICKNAME",
"MANAGE_NICKNAMES",
"MANAGE_GUILD_EXPRESSIONS",
"MODERATE_MEMBERS",
"VIEW_CREATOR_MONETIZATION_ANALYTICS",
"CREATE_GUILD_EXPRESSIONS",
"CREATE_EVENTS",
] satisfies ArrayElement<typeof Permissions.permisions>[];
static noOverwriteMask = this.toMask(this.noOverwrite);
getPermission(name: string): number {
if (undefined === Permissions.permisions.indexOf(name as any)) {
console.error(name + " is not found in map", Permissions.permisions);
@@ -131,4 +156,7 @@ class Permissions {
}
}
}
type ArrayElement<ArrayType extends readonly unknown[]> =
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
export {Permissions};
+1
View File
@@ -255,6 +255,7 @@ class RoleList extends Buttons {
this.makeguildmenus(options);
}
for (const thing of Permissions.info()) {
if (channel && Permissions.noOverwrite.includes(thing.name as any)) continue;
options.options.push(new PermissionToggle(thing, this.permission, options));
}
if (!channel) {