mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
fix permission change in v8
This commit is contained in:
@@ -33,8 +33,8 @@ export function hasChannelPermission(
|
|||||||
|
|
||||||
return permissions.every((perm) => {
|
return permissions.every((perm) => {
|
||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
if (BigInt(overwrite.deny_new) & BigInt(perm)) return false;
|
if (BigInt(overwrite.deny) & BigInt(perm)) return false;
|
||||||
if (BigInt(overwrite.allow_new) & BigInt(perm)) return true;
|
if (BigInt(overwrite.allow) & BigInt(perm)) return true;
|
||||||
}
|
}
|
||||||
if (channel.guildID) {
|
if (channel.guildID) {
|
||||||
return botHasPermission(channel.guildID, [perm]);
|
return botHasPermission(channel.guildID, [perm]);
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ export function createChannel(data: ChannelCreatePayload, guildID?: string) {
|
|||||||
permissions: data.permission_overwrites
|
permissions: data.permission_overwrites
|
||||||
? data.permission_overwrites.map((perm) => ({
|
? data.permission_overwrites.map((perm) => ({
|
||||||
...perm,
|
...perm,
|
||||||
allow: calculatePermissions(BigInt(perm.allow_new)),
|
allow: calculatePermissions(BigInt(perm.allow)),
|
||||||
deny: calculatePermissions(BigInt(perm.deny_new)),
|
deny: calculatePermissions(BigInt(perm.deny)),
|
||||||
}))
|
}))
|
||||||
: [],
|
: [],
|
||||||
/** Whether this channel is nsfw or not */
|
/** Whether this channel is nsfw or not */
|
||||||
|
|||||||
+2
-2
@@ -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.) */
|
/** The permissions that this id is NOT allowed to do. (This will mark it as a red x.) */
|
||||||
deny: number;
|
deny: number;
|
||||||
/** permission bit set for new perms until new api version released. */
|
/** 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. */
|
/** permission bit set for new perms until new api version released. */
|
||||||
deny_new: string;
|
deny: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ChannelCreateOptions {
|
export interface ChannelCreateOptions {
|
||||||
|
|||||||
+12
-11
@@ -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);
|
const guild = await cacheHandlers.get("guilds", guildID);
|
||||||
if (!guild) return false;
|
if (!guild) return false;
|
||||||
|
|
||||||
@@ -111,9 +114,7 @@ export async function hasChannelPermissions(
|
|||||||
if (memberOverwrite) {
|
if (memberOverwrite) {
|
||||||
// One of the necessary permissions is denied
|
// One of the necessary permissions is denied
|
||||||
if (
|
if (
|
||||||
permissions.some((perm) =>
|
permissions.some((perm) => BigInt(memberOverwrite.deny) & BigInt(perm))
|
||||||
BigInt(memberOverwrite.deny_new) & BigInt(perm)
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -121,7 +122,7 @@ export async function hasChannelPermissions(
|
|||||||
// Already allowed perm
|
// Already allowed perm
|
||||||
if (allowedPermissions.has(perm)) return;
|
if (allowedPermissions.has(perm)) return;
|
||||||
// This perm is allowed so we save it
|
// This perm is allowed so we save it
|
||||||
if (BigInt(memberOverwrite.allow_new) & BigInt(perm)) {
|
if (BigInt(memberOverwrite.allow) & BigInt(perm)) {
|
||||||
allowedPermissions.add(perm);
|
allowedPermissions.add(perm);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -132,11 +133,11 @@ export async function hasChannelPermissions(
|
|||||||
if (
|
if (
|
||||||
rolesOverwrites.some((overwrite) =>
|
rolesOverwrites.some((overwrite) =>
|
||||||
permissions.some((perm) =>
|
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
|
// 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
|
// 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;
|
if (allowedPermissions.has(perm)) return;
|
||||||
rolesOverwrites.forEach((overwrite) => {
|
rolesOverwrites.forEach((overwrite) => {
|
||||||
// This perm is allowed so we save it
|
// This perm is allowed so we save it
|
||||||
if (BigInt(overwrite.allow_new) & BigInt(perm)) {
|
if (BigInt(overwrite.allow) & BigInt(perm)) {
|
||||||
allowedPermissions.add(perm);
|
allowedPermissions.add(perm);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -161,7 +162,7 @@ export async function hasChannelPermissions(
|
|||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
permissions.some((perm) =>
|
permissions.some((perm) =>
|
||||||
BigInt(everyoneOverwrite.deny_new) & BigInt(perm) &&
|
BigInt(everyoneOverwrite.deny) & BigInt(perm) &&
|
||||||
!allowedPermissions.has(perm)
|
!allowedPermissions.has(perm)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@@ -170,7 +171,7 @@ export async function hasChannelPermissions(
|
|||||||
// If all permissions are granted
|
// If all permissions are granted
|
||||||
if (
|
if (
|
||||||
permissions.every((perm) =>
|
permissions.every((perm) =>
|
||||||
BigInt(everyoneOverwrite.allow_new) & BigInt(perm)
|
BigInt(everyoneOverwrite.allow) & BigInt(perm)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user