Convert overwrites

- Removed integration in createChannel
- Converting from DiscordOverwrite to Overwrite in cloneChannel function
This commit is contained in:
Exists
2021-04-14 13:28:59 -04:00
parent 215141171a
commit 3088cc0693
2 changed files with 21 additions and 15 deletions
+16
View File
@@ -2,6 +2,8 @@ import { cacheHandlers } from "../../cache.ts";
import { createChannel } from "./create_channel.ts";
import { Errors } from "../../types/misc/errors.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 */
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);
}
//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)
return createChannel(channelToClone.guildId!, channelToClone, reason);
}