Skip to content

Commit

Permalink
feat: automatically message the user who added the application on join
Browse files Browse the repository at this point in the history
Signed-off-by: Ar Rakin <rakinar2@onesoftnet.eu.org>
  • Loading branch information
virtual-designer committed Sep 20, 2024
1 parent 2224296 commit 368bb7a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/main/typescript/events/guild/GuildCreateEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,10 +31,13 @@ class GuildCreateEventListener extends EventListener<Events.GuildCreate, Client>
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})`);
Expand All @@ -47,6 +52,29 @@ class GuildCreateEventListener extends EventListener<Events.GuildCreate, Client>
});
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);
}
}

Expand Down

0 comments on commit 368bb7a

Please sign in to comment.