diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-05 19:37:20 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-05 19:37:20 +0200 |
commit | b9391bfac1aefc02bb51fb532c95a8a3e1c9f818 (patch) | |
tree | 39a7040d8f701aa83f1e1389706c4e12f55b0f21 /api/src/routes/guilds | |
parent | :art: move field error to util (diff) | |
download | server-b9391bfac1aefc02bb51fb532c95a8a3e1c9f818.tar.xz |
:sparkles: added autoJoin guild to config
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r-- | api/src/routes/guilds/index.ts | 77 |
1 files changed, 7 insertions, 70 deletions
diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts index 48aab092..7b676211 100644 --- a/api/src/routes/guilds/index.ts +++ b/api/src/routes/guilds/index.ts @@ -29,80 +29,17 @@ router.post("/", route({ body: "GuildCreateSchema" }), async (req: Request, res: throw DiscordApiErrors.MAXIMUM_GUILDS.withParams(maxGuilds); } - const guild_id = Snowflake.generate(); + const guild = await Guild.createGuild({ ...body, owner_id: req.user_id }); - await new Guild({ - name: body.name, - icon: await handleFile(`/icons/${guild_id}`, body.icon as string), - region: Config.get().regions.default, - owner_id: req.user_id, - afk_timeout: 300, - default_message_notifications: 0, - explicit_content_filter: 0, - features: [], - id: guild_id, - max_members: 250000, - max_presences: 250000, - max_video_channel_users: 25, - presence_count: 0, - member_count: 0, // will automatically be increased by addMember() - mfa_level: 0, - preferred_locale: "en-US", - premium_subscription_count: 0, - premium_tier: 0, - system_channel_flags: 0, - unavailable: false, - nsfw: false, - nsfw_level: 0, - verification_level: 0, - welcome_screen: { - enabled: false, - description: "No description", - welcome_channels: [] - }, - widget_enabled: false - }).save(); - - // we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error - await new Role({ - id: guild_id, - guild_id: guild_id, - color: 0, - hoist: false, - managed: false, - mentionable: false, - name: "@everyone", - permissions: String("2251804225"), - position: 0 - }).save(); - - if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; - - const ids = new Map(); - - body.channels.forEach((x) => { - if (x.id) { - ids.set(x.id, Snowflake.generate()); - } - }); - - for (const channel of body.channels?.sort((a, b) => (a.parent_id ? 1 : -1))) { - var id = ids.get(channel.id) || Snowflake.generate(); - - // TODO: should we abort if parent_id is a category? (to disallow sub category channels) - var parent_id = ids.get(channel.parent_id); - - await Channel.createChannel({ ...channel, guild_id, id, parent_id }, req.user_id, { - keepId: true, - skipExistsCheck: true, - skipPermissionCheck: true, - skipEventEmit: true - }); + const { autoJoin } = Config.get().guild; + if (autoJoin.enabled && !autoJoin.guilds?.length) { + // @ts-ignore + await Config.set({ guild: { autoJoin: { guilds: [guild.id] } } }); } - await Member.addToGuild(req.user_id, guild_id); + await Member.addToGuild(req.user_id, guild.id); - res.status(201).json({ id: guild_id }); + res.status(201).json({ id: guild.id }); }); export default router; |