From 194229acefe817b89826bf2af74f3eb35a88b331 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 15 Jul 2026 13:03:26 -0500 Subject: [PATCH] fix perms for server update --- src/webpage/channel.ts | 14 ++++++++++---- src/webpage/permissions.ts | 28 ++++++++++++++++++++++++++++ src/webpage/role.ts | 1 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index 840283e..47f5f55 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -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, }), diff --git a/src/webpage/permissions.ts b/src/webpage/permissions.ts index e5ece1e..f2e8bf6 100644 --- a/src/webpage/permissions.ts +++ b/src/webpage/permissions.ts @@ -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((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[]; + 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 (infer ElementType)[] ? ElementType : never; export {Permissions}; diff --git a/src/webpage/role.ts b/src/webpage/role.ts index f9f65f4..4cc6994 100644 --- a/src/webpage/role.ts +++ b/src/webpage/role.ts @@ -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) {