refactor: add leveling view layer

Create leveling.view.ts with UI logic extracted from leaderboard command:
- getLeaderboardEmbed() for leaderboard display (XP and Balance)
- getMedalEmoji() helper for ranking medals (🥇🥈🥉)
- formatLeaderEntry() helper for entry formatting with null safety

Updated leaderboard.ts to use view functions instead of inline formatting.
This commit is contained in:
syntaxbullet
2025-12-24 22:09:04 +01:00
parent 7d6912cdee
commit 1523a392c2
2 changed files with 51 additions and 8 deletions

View File

@@ -3,7 +3,8 @@ import { SlashCommandBuilder } from "discord.js";
import { DrizzleClient } from "@/lib/DrizzleClient";
import { users } from "@/db/schema";
import { desc } from "drizzle-orm";
import { createWarningEmbed, createBaseEmbed } from "@lib/embeds";
import { createWarningEmbed } from "@lib/embeds";
import { getLeaderboardEmbed } from "@/modules/leveling/leveling.view";
export const leaderboard = createCommand({
data: new SlashCommandBuilder()
@@ -34,13 +35,7 @@ export const leaderboard = createCommand({
return;
}
const description = leaders.map((user, index) => {
const medal = index === 0 ? "🥇" : index === 1 ? "🥈" : index === 2 ? "🥉" : `${index + 1}.`;
const value = isXp ? `Lvl ${user.level} (${user.xp} XP)` : `${user.balance} 🪙`;
return `${medal} **${user.username}** — ${value}`;
}).join("\n");
const embed = createBaseEmbed(isXp ? "🏆 XP Leaderboard" : "💰 Richest Players", description, "Gold");
const embed = getLeaderboardEmbed(leaders, isXp ? 'xp' : 'balance');
await interaction.editReply({ embeds: [embed] });
}