fix permission change in v8

This commit is contained in:
Skillz
2020-09-16 11:22:37 -04:00
parent 742569fd9d
commit d7c25f9b8f
4 changed files with 18 additions and 17 deletions
+2 -2
View File
@@ -33,8 +33,8 @@ export function hasChannelPermission(
return permissions.every((perm) => {
if (overwrite) {
if (BigInt(overwrite.deny_new) & BigInt(perm)) return false;
if (BigInt(overwrite.allow_new) & BigInt(perm)) return true;
if (BigInt(overwrite.deny) & BigInt(perm)) return false;
if (BigInt(overwrite.allow) & BigInt(perm)) return true;
}
if (channel.guildID) {
return botHasPermission(channel.guildID, [perm]);
+2 -2
View File
@@ -31,8 +31,8 @@ export function createChannel(data: ChannelCreatePayload, guildID?: string) {
permissions: data.permission_overwrites
? data.permission_overwrites.map((perm) => ({
...perm,
allow: calculatePermissions(BigInt(perm.allow_new)),
deny: calculatePermissions(BigInt(perm.deny_new)),
allow: calculatePermissions(BigInt(perm.allow)),
deny: calculatePermissions(BigInt(perm.deny)),
}))
: [],
/** Whether this channel is nsfw or not */
+2 -2
View File
@@ -467,9 +467,9 @@ export interface RawOverwrite {
/** The permissions that this id is NOT allowed to do. (This will mark it as a red x.) */
deny: number;
/** permission bit set for new perms until new api version released. */
allow_new: string;
allow: string;
/** permission bit set for new perms until new api version released. */
deny_new: string;
deny: string;
}
export interface ChannelCreateOptions {
+12 -11
View File
@@ -48,7 +48,10 @@ export function memberHasPermission(
);
}
export async function botHasPermission(guildID: string, permissions: Permissions[]) {
export async function botHasPermission(
guildID: string,
permissions: Permissions[],
) {
const guild = await cacheHandlers.get("guilds", guildID);
if (!guild) return false;
@@ -111,9 +114,7 @@ export async function hasChannelPermissions(
if (memberOverwrite) {
// One of the necessary permissions is denied
if (
permissions.some((perm) =>
BigInt(memberOverwrite.deny_new) & BigInt(perm)
)
permissions.some((perm) => BigInt(memberOverwrite.deny) & BigInt(perm))
) {
return false;
}
@@ -121,7 +122,7 @@ export async function hasChannelPermissions(
// Already allowed perm
if (allowedPermissions.has(perm)) return;
// This perm is allowed so we save it
if (BigInt(memberOverwrite.allow_new) & BigInt(perm)) {
if (BigInt(memberOverwrite.allow) & BigInt(perm)) {
allowedPermissions.add(perm);
}
});
@@ -132,11 +133,11 @@ export async function hasChannelPermissions(
if (
rolesOverwrites.some((overwrite) =>
permissions.some((perm) =>
(BigInt(overwrite.deny_new) & BigInt(perm)) &&
(BigInt(overwrite.deny) & BigInt(perm)) &&
// If another role allows these perms then they are not denied
!rolesOverwrites.some((o) => BigInt(o.allow_new) & BigInt(perm)) &&
!rolesOverwrites.some((o) => BigInt(o.allow) & BigInt(perm)) &&
// Make sure the memberOverwrite does not allow this perm
!(memberOverwrite && BigInt(memberOverwrite.allow_new) & BigInt(perm))
!(memberOverwrite && BigInt(memberOverwrite.allow) & BigInt(perm))
)
)
) {
@@ -148,7 +149,7 @@ export async function hasChannelPermissions(
if (allowedPermissions.has(perm)) return;
rolesOverwrites.forEach((overwrite) => {
// This perm is allowed so we save it
if (BigInt(overwrite.allow_new) & BigInt(perm)) {
if (BigInt(overwrite.allow) & BigInt(perm)) {
allowedPermissions.add(perm);
}
});
@@ -161,7 +162,7 @@ export async function hasChannelPermissions(
) {
if (
permissions.some((perm) =>
BigInt(everyoneOverwrite.deny_new) & BigInt(perm) &&
BigInt(everyoneOverwrite.deny) & BigInt(perm) &&
!allowedPermissions.has(perm)
)
) {
@@ -170,7 +171,7 @@ export async function hasChannelPermissions(
// If all permissions are granted
if (
permissions.every((perm) =>
BigInt(everyoneOverwrite.allow_new) & BigInt(perm)
BigInt(everyoneOverwrite.allow) & BigInt(perm)
)
) {
return true;