From ac47e03d19784a74797473aad9a91331ca805e5a Mon Sep 17 00:00:00 2001 From: Rory& Date: Mon, 14 Jul 2025 22:34:27 +0200 Subject: [PATCH] Fix creating guilds --- src/util/entities/Guild.ts | 94 +++++++++----------------------------- 1 file changed, 22 insertions(+), 72 deletions(-) diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts index 2df44955..37728aa6 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts @@ -16,14 +16,7 @@ along with this program. If not, see . */ -import { - Column, - Entity, - JoinColumn, - ManyToOne, - OneToMany, - RelationId, -} from "typeorm"; +import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm"; import { Config, GuildWelcomeScreen, Snowflake, handleFile } from ".."; import { Ban } from "./Ban"; import { BaseClass } from "./BaseClass"; @@ -337,17 +330,13 @@ export class Guild extends BaseClass { welcome_channels: [], }, channel_ordering: [], - afk_timeout: Config.get().defaults.guild.afkTimeout, - default_message_notifications: - Config.get().defaults.guild.defaultMessageNotifications, - explicit_content_filter: - Config.get().defaults.guild.explicitContentFilter, + default_message_notifications: Config.get().defaults.guild.defaultMessageNotifications, + explicit_content_filter: Config.get().defaults.guild.explicitContentFilter, features: Config.get().guild.defaultFeatures, max_members: Config.get().limits.guild.maxMembers, max_presences: Config.get().defaults.guild.maxPresences, - max_video_channel_users: - Config.get().defaults.guild.maxVideoChannelUsers, + max_video_channel_users: Config.get().defaults.guild.maxVideoChannelUsers, region: Config.get().regions.default, }).save(); @@ -357,12 +346,12 @@ export class Guild extends BaseClass { id: guild_id, guild_id: guild_id, color: 0, + colors: { primary_color: 0 }, hoist: false, managed: false, - // NB: in Spacebar, every role will be non-managed, as we use user-groups instead of roles for managed groups mentionable: false, name: "@everyone", - permissions: String("2251804225"), + permissions: "2251804225", position: 0, icon: undefined, unicode_emoji: undefined, @@ -379,9 +368,7 @@ export class Guild extends BaseClass { 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(), + role.id === body.template_guild_id ? guild_id : Snowflake.generate(), }) .save() .then(resolve); @@ -391,9 +378,7 @@ export class Guild extends BaseClass { } if (!body.channels || !body.channels.length) { - body.channels = [ - { id: "01", type: 0, name: "general", nsfw: false }, - ]; + body.channels = [{ id: "01", type: 0, name: "general", nsfw: false }]; } const ids = new Map(); @@ -404,60 +389,29 @@ export class Guild extends BaseClass { } }); - for (const channel of body.channels.sort((a) => - a.parent_id ? 1 : -1, - )) { + for (const channel of body.channels.sort((a) => (a.parent_id ? 1 : -1))) { const id = ids.get(channel.id) || Snowflake.generate(); const parent_id = ids.get(channel.parent_id); - const saved = await Channel.createChannel( - { ...channel, guild_id, id, parent_id }, - body.owner_id, - { - keepId: true, - skipExistsCheck: true, - skipPermissionCheck: true, - skipEventEmit: true, - }, - ); + const saved = await Channel.createChannel({ ...channel, guild_id, id, parent_id }, body.owner_id, { + keepId: true, + skipExistsCheck: true, + skipPermissionCheck: true, + skipEventEmit: true, + }); - await Guild.insertChannelInOrder( - guild.id, - saved.id, - parent_id ?? channel.position ?? 0, - guild, - ); + await Guild.insertChannelInOrder(guild.id, saved.id, parent_id ?? channel.position ?? 0, guild); } return guild; } /** Insert a channel into the guild ordering by parent channel id or position */ - static async insertChannelInOrder( - guild_id: string, - channel_id: string, - position: number, - guild?: Guild, - ): Promise; - static async insertChannelInOrder( - guild_id: string, - channel_id: string, - parent_id: string, - guild?: Guild, - ): Promise; - static async insertChannelInOrder( - guild_id: string, - channel_id: string, - insertPoint: string | number, - guild?: Guild, - ): Promise; - static async insertChannelInOrder( - guild_id: string, - channel_id: string, - insertPoint: string | number, - guild?: Guild, - ): Promise { + static async insertChannelInOrder(guild_id: string, channel_id: string, position: number, guild?: Guild): Promise; + static async insertChannelInOrder(guild_id: string, channel_id: string, parent_id: string, guild?: Guild): Promise; + static async insertChannelInOrder(guild_id: string, channel_id: string, insertPoint: string | number, guild?: Guild): Promise; + static async insertChannelInOrder(guild_id: string, channel_id: string, insertPoint: string | number, guild?: Guild): Promise { if (!guild) guild = await Guild.findOneOrFail({ where: { id: guild_id }, @@ -465,17 +419,13 @@ export class Guild extends BaseClass { }); let position; - if (typeof insertPoint == "string") - position = guild.channel_ordering.indexOf(insertPoint) + 1; + if (typeof insertPoint == "string") position = guild.channel_ordering.indexOf(insertPoint) + 1; else position = insertPoint; guild.channel_ordering.remove(channel_id); guild.channel_ordering.splice(position, 0, channel_id); - await Guild.update( - { id: guild_id }, - { channel_ordering: guild.channel_ordering }, - ); + await Guild.update({ id: guild_id }, { channel_ordering: guild.channel_ordering }); return position; }