swc/bundler/tests/.cache/deno/12f22fe84a446f5ac2c6b7eed8621763d67c9717.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

34 lines
1.2 KiB
TypeScript

// 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;
}
});
}