mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
Replace bit perm calculating with function
This commit is contained in:
@@ -21,7 +21,10 @@ import {
|
||||
} from "../types/types.ts";
|
||||
import { cache } from "../utils/cache.ts";
|
||||
import { endpoints } from "../utils/constants.ts";
|
||||
import { botHasChannelPermissions } from "../utils/permissions.ts";
|
||||
import {
|
||||
botHasChannelPermissions,
|
||||
calculateBits,
|
||||
} from "../utils/permissions.ts";
|
||||
|
||||
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||
export function channelOverwriteHasPermission(
|
||||
@@ -402,14 +405,8 @@ export async function editChannel(
|
||||
(overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: overwrite.allow.reduce(
|
||||
(bits, perm) => bits |= BigInt(Permissions[perm]),
|
||||
BigInt(0),
|
||||
).toString(),
|
||||
deny: overwrite.deny.reduce(
|
||||
(bits, perm) => bits |= BigInt(Permissions[perm]),
|
||||
BigInt(0),
|
||||
).toString(),
|
||||
allow: calculateBits(overwrite.allow),
|
||||
deny: calculateBits(overwrite.deny),
|
||||
};
|
||||
},
|
||||
),
|
||||
@@ -452,14 +449,8 @@ export async function editChannelOverwrite(
|
||||
})),
|
||||
{
|
||||
...info,
|
||||
allow: allow.reduce(
|
||||
(bits, perm) => bits |= BigInt(Permissions[perm]),
|
||||
BigInt(0),
|
||||
).toString(),
|
||||
deny: deny.reduce(
|
||||
(bits, perm) => bits |= BigInt(Permissions[perm]),
|
||||
BigInt(0),
|
||||
).toString(),
|
||||
allow: calculateBits(allow),
|
||||
deny: calculateBits(deny),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -33,7 +33,6 @@ import {
|
||||
ImageSize,
|
||||
Intents,
|
||||
MemberCreatePayload,
|
||||
Permissions,
|
||||
PositionSwap,
|
||||
PruneOptions,
|
||||
PrunePayload,
|
||||
@@ -131,14 +130,8 @@ export async function createGuildChannel(
|
||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||
...perm,
|
||||
|
||||
allow: perm.allow.reduce(
|
||||
(bits, p) => bits |= BigInt(Permissions[p]),
|
||||
BigInt(0),
|
||||
).toString(),
|
||||
deny: perm.deny.reduce(
|
||||
(bits, p) => bits |= BigInt(Permissions[p]),
|
||||
BigInt(0),
|
||||
).toString(),
|
||||
allow: calculateBits(perm.allow),
|
||||
deny: calculateBits(perm.deny),
|
||||
})),
|
||||
type: options?.type || ChannelTypes.GUILD_TEXT,
|
||||
})) as ChannelCreatePayload;
|
||||
@@ -318,15 +311,13 @@ export async function createGuildRole(
|
||||
throw new Error(Errors.MISSING_MANAGE_ROLES);
|
||||
}
|
||||
|
||||
const bits = calculateBits(options.permissions || []);
|
||||
|
||||
const result = await RequestManager.post(
|
||||
endpoints.GUILD_ROLES(guildID),
|
||||
{
|
||||
...options,
|
||||
permissions: options.permissions
|
||||
?.reduce((subtotal, perm) => {
|
||||
subtotal |= Permissions[perm];
|
||||
return subtotal;
|
||||
}, 0),
|
||||
permissions: calculateBits(options?.permissions || []),
|
||||
reason,
|
||||
},
|
||||
);
|
||||
@@ -448,7 +439,9 @@ export async function getAuditLogs(
|
||||
|
||||
return RequestManager.get(endpoints.GUILD_AUDIT_LOGS(guildID), {
|
||||
...options,
|
||||
action_type: options.action_type ? AuditLogs[options.action_type] : undefined,
|
||||
action_type: options.action_type
|
||||
? AuditLogs[options.action_type]
|
||||
: undefined,
|
||||
limit: options.limit && options.limit >= 1 && options.limit <= 100
|
||||
? options.limit
|
||||
: 50,
|
||||
|
||||
Reference in New Issue
Block a user