feat: Implement welcome messages for new enrollments using a new webhook utility and refactor the admin webhook command to utilize it.

This commit is contained in:
syntaxbullet
2025-12-20 20:59:44 +01:00
parent 65f5dc3721
commit 5833224ba9
4 changed files with 96 additions and 27 deletions

View File

@@ -3,6 +3,7 @@ import { config } from "@/lib/config";
import { createErrorEmbed } from "@/lib/embeds";
import { classService } from "@modules/class/class.service";
import { userService } from "@modules/user/user.service";
import { sendWebhookMessage } from "@/lib/webhookUtils";
export async function handleEnrollmentInteraction(interaction: ButtonInteraction) {
if (!interaction.inCachedGuild()) {
@@ -84,6 +85,31 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
flags: MessageFlags.Ephemeral
});
// 5. Send Welcome Message (if configured)
if (config.welcomeChannelId) {
const welcomeChannel = interaction.guild.channels.cache.get(config.welcomeChannelId);
if (welcomeChannel && welcomeChannel.isTextBased()) {
const rawMessage = config.welcomeMessage || "Welcome to Aurora, {user}! You have been enrolled as a **{class}**.";
const processedMessage = rawMessage
.replace(/{user}/g, member.toString())
.replace(/{username}/g, member.user.username)
.replace(/{class}/g, selectedClass.name)
.replace(/{guild}/g, interaction.guild.name);
let payload;
try {
payload = JSON.parse(processedMessage);
} catch {
payload = processedMessage;
}
// Fire and forget webhook
sendWebhookMessage(welcomeChannel, payload, interaction.client.user, "New Student Enrollment")
.catch((err: any) => console.error("Failed to send welcome message:", err));
}
}
} catch (error) {
console.error("Enrollment error:", error);
await interaction.reply({