summary refs log tree commit diff
path: root/api/src/util/Channel.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-01 10:47:00 +0200
committerGitHub <noreply@github.com>2021-09-01 10:47:00 +0200
commitdf1d633c4b56bea97e0b76da34171d80c0c6a3ff (patch)
tree7e57837ec000a641935a32649ac17b38ef2e29d8 /api/src/util/Channel.ts
parentMerge pull request #287 from EMREOYUN/patch-1 (diff)
parentMerge pull request #299 from AlTech98/typeorm (diff)
downloadserver-df1d633c4b56bea97e0b76da34171d80c0c6a3ff.tar.xz
Merge pull request #300 from fosscord/typeorm
Diffstat (limited to 'api/src/util/Channel.ts')
-rw-r--r--api/src/util/Channel.ts63
1 files changed, 0 insertions, 63 deletions
diff --git a/api/src/util/Channel.ts b/api/src/util/Channel.ts
deleted file mode 100644

index fb6f9c8c..00000000 --- a/api/src/util/Channel.ts +++ /dev/null
@@ -1,63 +0,0 @@ -import { - ChannelCreateEvent, - ChannelModel, - ChannelType, - emitEvent, - getPermission, - GuildModel, - Snowflake, - TextChannel, - toObject, - VoiceChannel -} from "@fosscord/util"; -import { HTTPError } from "lambert-server"; - -// TODO: DM channel -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"); - - switch (channel.type) { - case ChannelType.GUILD_TEXT: - case ChannelType.GUILD_VOICE: - 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"); - } - break; - case ChannelType.GUILD_CATEGORY: - break; - case ChannelType.DM: - case ChannelType.GROUP_DM: - throw new HTTPError("You can't create a dm channel in a guild"); - // TODO: check if guild is community server - case ChannelType.GUILD_STORE: - case ChannelType.GUILD_NEWS: - default: - throw new HTTPError("Not yet supported"); - } - - if (!channel.permission_overwrites) channel.permission_overwrites = []; - // TODO: auto generate position - - channel = await new ChannelModel({ - ...channel, - ...(!opts?.keepId && { id: Snowflake.generate() }), - created_at: new Date(), - // @ts-ignore - recipient_ids: null - }).save(); - - await emitEvent({ event: "CHANNEL_CREATE", data: toObject(channel), guild_id: channel.guild_id } as ChannelCreateEvent); - - return channel; -}