mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
d60c3242af
swc_bundler: - Fix cycle detection for complex circular imports. (denoland/deno#10752) swc_ecma_transforms_typescript: - Allow using large values for an enum variant.
34 lines
1.2 KiB
TypeScript
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;
|
|
}
|
|
});
|
|
}
|