refactor: Extract UI component creation into new view files for lootdrop, trade, item wizard, and enrollment.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ButtonInteraction, MessageFlags } from "discord.js";
|
||||
import { config } from "@/lib/config";
|
||||
import { createErrorEmbed } from "@/lib/embeds";
|
||||
import { getEnrollmentErrorEmbed, getEnrollmentSuccessMessage } from "./enrollment.view";
|
||||
import { classService } from "@modules/class/class.service";
|
||||
import { userService } from "@modules/user/user.service";
|
||||
import { sendWebhookMessage } from "@/lib/webhookUtils";
|
||||
@@ -15,7 +15,7 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
|
||||
if (!studentRole || !visitorRole) {
|
||||
await interaction.reply({
|
||||
embeds: [createErrorEmbed("No student or visitor role configured for enrollment.", "Configuration Error")],
|
||||
...getEnrollmentErrorEmbed("No student or visitor role configured for enrollment.", "Configuration Error"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
return;
|
||||
@@ -28,7 +28,7 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
// Check DB enrollment
|
||||
if (user.class) {
|
||||
await interaction.reply({
|
||||
embeds: [createErrorEmbed("You are already enrolled in a class.", "Enrollment Failed")],
|
||||
...getEnrollmentErrorEmbed("You are already enrolled in a class.", "Enrollment Failed"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
return;
|
||||
@@ -39,7 +39,7 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
// Check Discord role enrollment (Double safety)
|
||||
if (member.roles.cache.has(studentRole)) {
|
||||
await interaction.reply({
|
||||
embeds: [createErrorEmbed("You already have the student role.", "Enrollment Failed")],
|
||||
...getEnrollmentErrorEmbed("You already have the student role.", "Enrollment Failed"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
return;
|
||||
@@ -51,7 +51,7 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
|
||||
if (validClasses.length === 0) {
|
||||
await interaction.reply({
|
||||
embeds: [createErrorEmbed("No classes with specified roles found in database.", "Configuration Error")],
|
||||
...getEnrollmentErrorEmbed("No classes with specified roles found in database.", "Configuration Error"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
return;
|
||||
@@ -65,7 +65,7 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
const classRole = interaction.guild.roles.cache.get(classRoleId);
|
||||
if (!classRole) {
|
||||
await interaction.reply({
|
||||
embeds: [createErrorEmbed(`The configured role ID \`${classRoleId}\` for class **${selectedClass.name}** does not exist in this server.`, "Configuration Error")],
|
||||
...getEnrollmentErrorEmbed(`The configured role ID \`${classRoleId}\` for class **${selectedClass.name}** does not exist in this server.`, "Configuration Error"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
return;
|
||||
@@ -81,7 +81,7 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
await classService.assignClass(user.id.toString(), selectedClass.id);
|
||||
|
||||
await interaction.reply({
|
||||
content: `🎉 You have been successfully enrolled! You received the **${classRole.name}** role.`,
|
||||
...getEnrollmentSuccessMessage(classRole.name),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
|
||||
@@ -113,8 +113,8 @@ export async function handleEnrollmentInteraction(interaction: ButtonInteraction
|
||||
} catch (error) {
|
||||
console.error("Enrollment error:", error);
|
||||
await interaction.reply({
|
||||
embeds: [createErrorEmbed("An unexpected error occurred during enrollment. Please contact an administrator.", "System Error")],
|
||||
...getEnrollmentErrorEmbed("An unexpected error occurred during enrollment. Please contact an administrator.", "System Error"),
|
||||
flags: MessageFlags.Ephemeral
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/modules/user/enrollment.view.ts
Normal file
12
src/modules/user/enrollment.view.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { createErrorEmbed } from "@/lib/embeds";
|
||||
|
||||
export function getEnrollmentErrorEmbed(message: string, title: string = "Enrollment Failed") {
|
||||
const embed = createErrorEmbed(message, title);
|
||||
return { embeds: [embed] };
|
||||
}
|
||||
|
||||
export function getEnrollmentSuccessMessage(roleName: string) {
|
||||
return {
|
||||
content: `🎉 You have been successfully enrolled! You received the **${roleName}** role.`
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user