swc/crates/swc_bundler/tests/.cache/deno/12f22fe84a446f5ac2c6b7eed8621763d67c9717.ts

34 lines
1.2 KiB
TypeScript
Raw Normal View History

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/helpers/channels/channel_overwrite_has_permission.ts
import type { DiscordOverwrite } from "../../types/channels/overwrite.ts";
import { DiscordBitwisePermissionFlags } from "../../types/permissions/bitwise_permission_flags.ts";
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
export function channelOverwriteHasPermission(
guildId: bigint,
id: bigint,
overwrites: (Omit<DiscordOverwrite, "id" | "allow" | "deny"> & {
id: bigint;
allow: bigint;
deny: bigint;
})[],
permissions: PermissionStrings[]
) {
const overwrite = overwrites.find((perm) => perm.id === id) || overwrites.find((perm) => perm.id === guildId);
if (!overwrite) return false;
return permissions.every((perm) => {
const allowBits = overwrite.allow;
const denyBits = overwrite.deny;
if (BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm])) {
return false;
}
if (BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm])) {
return true;
}
});
}