mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Convert overwrites
- Removed integration in createChannel - Converting from DiscordOverwrite to Overwrite in cloneChannel function
This commit is contained in:
@@ -2,6 +2,8 @@ import { cacheHandlers } from "../../cache.ts";
|
|||||||
import { createChannel } from "./create_channel.ts";
|
import { createChannel } from "./create_channel.ts";
|
||||||
import { Errors } from "../../types/misc/errors.ts";
|
import { Errors } from "../../types/misc/errors.ts";
|
||||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||||
|
import { calculatePermissions } from "../../util/permissions.ts";
|
||||||
|
import { Overwrite } from "../../types/channels/overwrite.ts";
|
||||||
|
|
||||||
/** Create a copy of a channel */
|
/** Create a copy of a channel */
|
||||||
export async function cloneChannel(channelId: string, reason?: string) {
|
export async function cloneChannel(channelId: string, reason?: string) {
|
||||||
@@ -17,6 +19,20 @@ export async function cloneChannel(channelId: string, reason?: string) {
|
|||||||
throw new Error(Errors.CHANNEL_NOT_IN_GUILD);
|
throw new Error(Errors.CHANNEL_NOT_IN_GUILD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Convert channel permission
|
||||||
|
const newOverwrites: Overwrite[] = [];
|
||||||
|
|
||||||
|
channelToClone.permissionOverwrites.forEach((overwrite) => {
|
||||||
|
newOverwrites.push({
|
||||||
|
id: overwrite.id,
|
||||||
|
type: overwrite.type,
|
||||||
|
allow: calculatePermissions(BigInt(overwrite.allow)),
|
||||||
|
deny: calculatePermissions(BigInt(overwrite.deny)),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
channelToClone.permissionOverwrites = newOverwrites;
|
||||||
|
|
||||||
//Create the channel (also handles permissions)
|
//Create the channel (also handles permissions)
|
||||||
return createChannel(channelToClone.guildId!, channelToClone, reason);
|
return createChannel(channelToClone.guildId!, channelToClone, reason);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,7 @@ export async function createChannel(
|
|||||||
) {
|
) {
|
||||||
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
const requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||||
|
|
||||||
//Integration with permissions for channel cloning
|
|
||||||
let useDefaultOverwrites = false;
|
|
||||||
|
|
||||||
options?.permissionOverwrites?.forEach((overwrite) => {
|
options?.permissionOverwrites?.forEach((overwrite) => {
|
||||||
if (overwrite.id && parseInt(overwrite.allow)) {
|
|
||||||
useDefaultOverwrites = true;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
eventHandlers.debug?.(
|
eventHandlers.debug?.(
|
||||||
"loop",
|
"loop",
|
||||||
`Running forEach loop in create_channel file.`,
|
`Running forEach loop in create_channel file.`,
|
||||||
@@ -48,14 +40,12 @@ export async function createChannel(
|
|||||||
endpoints.GUILD_CHANNELS(guildId),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
{
|
{
|
||||||
...camelKeysToSnakeCase<DiscordCreateGuildChannel>(options ?? {}),
|
...camelKeysToSnakeCase<DiscordCreateGuildChannel>(options ?? {}),
|
||||||
permission_overwrites: useDefaultOverwrites
|
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||||
? options?.permissionOverwrites
|
...perm,
|
||||||
: options?.permissionOverwrites?.map((perm) => ({
|
|
||||||
...perm,
|
|
||||||
|
|
||||||
allow: calculateBits(perm.allow),
|
allow: calculateBits(perm.allow),
|
||||||
deny: calculateBits(perm.deny),
|
deny: calculateBits(perm.deny),
|
||||||
})),
|
})),
|
||||||
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
|
||||||
},
|
},
|
||||||
)) as DiscordChannel;
|
)) as DiscordChannel;
|
||||||
|
|||||||
Reference in New Issue
Block a user