forked from syntaxbullet/AuroraBot-discord
feat: Introduce new modules for class, inventory, leveling, and quests with expanded schema, refactor user service, and add verification scripts.
This commit is contained in:
50
src/commands/leveling/leaderboard.ts
Normal file
50
src/commands/leveling/leaderboard.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { createCommand } from "@/lib/utils";
|
||||
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
|
||||
import { DrizzleClient } from "@/lib/DrizzleClient";
|
||||
import { users } from "@/db/schema";
|
||||
import { desc } from "drizzle-orm";
|
||||
|
||||
export const leaderboard = createCommand({
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("leaderboard")
|
||||
.setDescription("View the top players")
|
||||
.addStringOption(option =>
|
||||
option.setName("type")
|
||||
.setDescription("Sort by XP or Balance")
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: "Level / XP", value: "xp" },
|
||||
{ name: "Balance", value: "balance" }
|
||||
)
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
await interaction.deferReply();
|
||||
|
||||
const type = interaction.options.getString("type", true);
|
||||
const isXp = type === "xp";
|
||||
|
||||
const leaders = await DrizzleClient.query.users.findMany({
|
||||
orderBy: isXp ? desc(users.xp) : desc(users.balance),
|
||||
limit: 10
|
||||
});
|
||||
|
||||
if (leaders.length === 0) {
|
||||
await interaction.editReply({ content: "❌ No users found." });
|
||||
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 = new EmbedBuilder()
|
||||
.setTitle(isXp ? "🏆 XP Leaderboard" : "💰 Richest Players")
|
||||
.setDescription(description)
|
||||
.setColor("Gold")
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user