diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-14 13:56:46 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-14 13:56:46 +0200 |
commit | 31a6c416a623c2461f1bdad56a4cbae1743d837f (patch) | |
tree | da50a1997d93e6bd3d98a59eb960e8b1f1906058 /api/src/util | |
parent | :bug: fix guild create with channel template (diff) | |
download | server-31a6c416a623c2461f1bdad56a4cbae1743d837f.tar.xz |
:bug: fix Guild + Channel create
Diffstat (limited to 'api/src/util')
-rw-r--r-- | api/src/util/Channel.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/api/src/util/Channel.ts b/api/src/util/Channel.ts index ef04d521..fb6f9c8c 100644 --- a/api/src/util/Channel.ts +++ b/api/src/util/Channel.ts @@ -13,7 +13,14 @@ import { import { HTTPError } from "lambert-server"; // TODO: DM channel -export async function createChannel(channel: Partial<TextChannel | VoiceChannel>, user_id: string = "0") { +export async function createChannel( + channel: Partial<TextChannel | VoiceChannel>, + user_id: string = "0", + opts?: { + keepId?: boolean; + skipExistsCheck?: boolean; + } +) { // Always check if user has permission first const permissions = await getPermission(user_id, channel.guild_id); permissions.hasThrow("MANAGE_CHANNELS"); @@ -21,7 +28,7 @@ export async function createChannel(channel: Partial<TextChannel | VoiceChannel> switch (channel.type) { case ChannelType.GUILD_TEXT: case ChannelType.GUILD_VOICE: - if (channel.parent_id) { + if (channel.parent_id && !opts?.skipExistsCheck) { const exists = await ChannelModel.findOne({ id: channel.parent_id }, { guild_id: true }).exec(); if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400); if (exists.guild_id !== channel.guild_id) throw new HTTPError("The category channel needs to be in the guild"); @@ -44,7 +51,7 @@ export async function createChannel(channel: Partial<TextChannel | VoiceChannel> channel = await new ChannelModel({ ...channel, - id: Snowflake.generate(), + ...(!opts?.keepId && { id: Snowflake.generate() }), created_at: new Date(), // @ts-ignore recipient_ids: null |