summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorZane Helton <zane99@me.com>2025-06-28 22:09:56 -0400
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2025-06-29 13:27:14 +1000
commit33fde3bc4a338dccd8707a7712763535862aa037 (patch)
tree0a0c9742ce8867295c4df814a64bf624ec2c082f /src/util
parentSet `premium_tier` to 0 when creating guild from template (diff)
downloadserver-ts-33fde3bc4a338dccd8707a7712763535862aa037.tar.xz
Fix the creation of guilds from templates
The biggest hold-up was missing fields (`premium_tier`,
`welcome_screen`, etc.) but it looks like someone has provided a
helpful function called `createGuild(...)` to provide sensible default
values.

This commit fixes the errors related to creating a guild from a
template. I've also refactored the code to include roles and channels in
the template.

To make sure that the @everyone role is cloned correctly, when
creating the guild from a template, we check if the role's ID
matches the template's `source_guild_id`. If it does, we set the
@everyone role to the new guild's ID.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/entities/Guild.ts29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts

index 4e49ce9b8..30cbb5734 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts
@@ -270,6 +270,9 @@ export class Guild extends BaseClass { @Column({ nullable: true }) verification_level?: number; + /** + * DEPRECATED: Look at the new Guild onboarding screens. + */ @Column({ type: "simple-json" }) welcome_screen: GuildWelcomeScreen; @@ -308,7 +311,9 @@ export class Guild extends BaseClass { name?: string; icon?: string | null; owner_id?: string; + roles?: Partial<Role>[]; channels?: Partial<Channel>[]; + template_guild_id: string | null; }) { const guild_id = Snowflake.generate(); @@ -364,10 +369,32 @@ export class Guild extends BaseClass { flags: 0, // TODO? }).save(); - if (!body.channels || !body.channels.length) + // create custom roles if provided + if (body.roles && body.roles.length) { + await Promise.all( + body.roles?.map((role) => { + new Promise((resolve) => { + Role.create({ + ...role, + guild_id, + id: + // role.id === body.template_guild_id indicates that this is the @everyone role + role.id === body.template_guild_id + ? guild_id + : Snowflake.generate(), + }) + .save() + .then(resolve); + }); + }), + ); + } + + if (!body.channels || !body.channels.length) { body.channels = [ { id: "01", type: 0, name: "general", nsfw: false }, ]; + } const ids = new Map();