diff --git a/src/main/typescript/events/guild/GuildCreateEventListener.ts b/src/main/typescript/events/guild/GuildCreateEventListener.ts index b5d0a47d6..cd83c6089 100644 --- a/src/main/typescript/events/guild/GuildCreateEventListener.ts +++ b/src/main/typescript/events/guild/GuildCreateEventListener.ts @@ -21,6 +21,8 @@ import { Inject } from "@framework/container/Inject"; import EventListener from "@framework/events/EventListener"; import { Logger } from "@framework/log/Logger"; import { Events } from "@framework/types/ClientEvents"; +import { fetchMember } from "@framework/utils/entities"; +import GuildSetupService from "@main/services/GuildSetupService"; import type { Guild } from "discord.js"; import type Client from "../../core/Client"; import ConfigurationManager from "../../services/ConfigurationManager"; @@ -29,10 +31,13 @@ class GuildCreateEventListener extends EventListener public override readonly name = Events.GuildCreate; @Inject() - public readonly configManager!: ConfigurationManager; + private readonly configManager!: ConfigurationManager; @Inject() - public readonly logger!: Logger; + private readonly logger!: Logger; + + @Inject() + private readonly guildSetupService!: GuildSetupService; public override async execute(guild: Guild) { this.logger.info(`Joined a guild: ${guild.name} (${guild.id})`); @@ -47,6 +52,29 @@ class GuildCreateEventListener extends EventListener }); await this.configManager.load(); } + + const integration = await guild.fetchIntegrations(); + const id = this.client.application?.id; + + if (!id) { + return; + } + + const systemIntegration = integration.find( + integration => integration.application?.id === id + ); + + if (!systemIntegration?.user) { + return; + } + + const member = await fetchMember(guild, systemIntegration.user.id); + + if (!member) { + return; + } + + await this.guildSetupService.initialize(member).catch(this.logger.error); } }