Fix issues

This commit is contained in:
root
2025-10-12 10:47:58 +02:00
commit ddb5412b91
35 changed files with 2370 additions and 0 deletions

33
dist/commands/leaderboard.js vendored Normal file
View File

@@ -0,0 +1,33 @@
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { withConn } from '../db/pool.js';
export const data = new SlashCommandBuilder()
.setName('leaderboard')
.setDescription('Show top users by XP');
export async function execute(interaction) {
if (!interaction.guildId)
return interaction.reply({ content: 'Guild only command.', ephemeral: true });
const rows = await withConn(async (conn) => {
return conn.query('SELECT user_id, xp FROM user_xp WHERE guild_id = ? ORDER BY xp DESC LIMIT 10', [interaction.guildId]);
});
const list = rows;
if (!list.length)
return interaction.reply('No XP data yet. Start chatting!');
const medals = ['🥇', '🥈', '🥉'];
const XP_PER_LEVEL = 500;
const desc = list
.map((r, i) => {
const rank = i + 1;
const level = Math.floor((r.xp || 0) / XP_PER_LEVEL);
const tag = `<@${r.user_id}>`;
const medal = medals[i] || `#${rank}`;
return `${medal} ${tag}${r.xp} XP (Lvl ${level})`;
})
.join('\n');
const embed = new EmbedBuilder()
.setTitle('Server Leaderboard')
.setColor(0xFEE75C)
.setDescription(desc)
.setFooter({ text: interaction.guild?.name || 'Leaderboard' })
.setTimestamp();
await interaction.reply({ embeds: [embed], allowedMentions: { parse: [] } });
}