Introduces new commands like `/automod`, `/giveaway`, `/rolepanel`, and `/schedule`. Enhances existing commands such as `/announce`, `/help`, `/leaderboard`, `/profile`, and `/serverinfo` with new features and improved embed designs. Updates welcome and goodbye listeners with rich embeds. Fixes a critical issue in the `/rolepanel` command regarding channel fetching. Adds interaction handling for role buttons and giveaway entries. Replit-Commit-Author: Agent Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: eefee140-1301-4b6f-9439-2b0b883aa40a Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/qAaysIh Replit-Helium-Checkpoint-Created: true
198 lines
6.3 KiB
JavaScript
198 lines
6.3 KiB
JavaScript
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName("leaderboard")
|
|
.setDescription("View the top AeThex contributors")
|
|
.addStringOption((option) =>
|
|
option
|
|
.setName("category")
|
|
.setDescription("Leaderboard category")
|
|
.setRequired(false)
|
|
.addChoices(
|
|
{ name: "🔥 Most Active (Posts)", value: "posts" },
|
|
{ name: "❤️ Most Liked", value: "likes" },
|
|
{ name: "🎨 Top Creators", value: "creators" },
|
|
{ name: "⭐ XP Leaders", value: "xp" }
|
|
)
|
|
),
|
|
|
|
async execute(interaction, supabase) {
|
|
if (!supabase) {
|
|
return interaction.reply({ content: "This feature requires Supabase to be configured.", ephemeral: true });
|
|
}
|
|
await interaction.deferReply();
|
|
|
|
try {
|
|
const category = interaction.options.getString("category") || "xp";
|
|
|
|
let leaderboardData = [];
|
|
let title = "";
|
|
let emoji = "";
|
|
let color = 0x7c3aed;
|
|
|
|
if (category === "xp") {
|
|
title = "XP Leaderboard";
|
|
emoji = "⭐";
|
|
color = 0xfbbf24;
|
|
|
|
const { data: profiles } = await supabase
|
|
.from("user_profiles")
|
|
.select("id, username, full_name, avatar_url, xp")
|
|
.not("xp", "is", null)
|
|
.order("xp", { ascending: false })
|
|
.limit(10);
|
|
|
|
for (const profile of profiles || []) {
|
|
const level = Math.floor(Math.sqrt((profile.xp || 0) / 100));
|
|
leaderboardData.push({
|
|
name: profile.full_name || profile.username || "Anonymous",
|
|
value: `Level ${level} • ${(profile.xp || 0).toLocaleString()} XP`,
|
|
username: profile.username,
|
|
xp: profile.xp || 0
|
|
});
|
|
}
|
|
} else if (category === "posts") {
|
|
title = "Most Active Posters";
|
|
emoji = "🔥";
|
|
color = 0xef4444;
|
|
|
|
const { data: posts } = await supabase
|
|
.from("community_posts")
|
|
.select("user_id")
|
|
.not("user_id", "is", null);
|
|
|
|
const postCounts = {};
|
|
posts?.forEach((post) => {
|
|
postCounts[post.user_id] = (postCounts[post.user_id] || 0) + 1;
|
|
});
|
|
|
|
const sortedUsers = Object.entries(postCounts)
|
|
.sort(([, a], [, b]) => b - a)
|
|
.slice(0, 10);
|
|
|
|
for (const [userId, count] of sortedUsers) {
|
|
const { data: profile } = await supabase
|
|
.from("user_profiles")
|
|
.select("username, full_name, avatar_url")
|
|
.eq("id", userId)
|
|
.single();
|
|
|
|
if (profile) {
|
|
leaderboardData.push({
|
|
name: profile.full_name || profile.username || "Anonymous",
|
|
value: `${count} posts`,
|
|
username: profile.username,
|
|
});
|
|
}
|
|
}
|
|
} else if (category === "likes") {
|
|
title = "Most Liked Users";
|
|
emoji = "❤️";
|
|
color = 0xec4899;
|
|
|
|
const { data: posts } = await supabase
|
|
.from("community_posts")
|
|
.select("user_id, likes_count")
|
|
.not("user_id", "is", null)
|
|
.order("likes_count", { ascending: false });
|
|
|
|
const likeCounts = {};
|
|
posts?.forEach((post) => {
|
|
likeCounts[post.user_id] =
|
|
(likeCounts[post.user_id] || 0) + (post.likes_count || 0);
|
|
});
|
|
|
|
const sortedUsers = Object.entries(likeCounts)
|
|
.sort(([, a], [, b]) => b - a)
|
|
.slice(0, 10);
|
|
|
|
for (const [userId, count] of sortedUsers) {
|
|
const { data: profile } = await supabase
|
|
.from("user_profiles")
|
|
.select("username, full_name, avatar_url")
|
|
.eq("id", userId)
|
|
.single();
|
|
|
|
if (profile) {
|
|
leaderboardData.push({
|
|
name: profile.full_name || profile.username || "Anonymous",
|
|
value: `${count.toLocaleString()} likes`,
|
|
username: profile.username,
|
|
});
|
|
}
|
|
}
|
|
} else if (category === "creators") {
|
|
title = "Top Creators";
|
|
emoji = "🎨";
|
|
color = 0x8b5cf6;
|
|
|
|
const { data: creators } = await supabase
|
|
.from("aethex_creators")
|
|
.select("user_id, total_projects, verified, featured")
|
|
.order("total_projects", { ascending: false })
|
|
.limit(10);
|
|
|
|
for (const creator of creators || []) {
|
|
const { data: profile } = await supabase
|
|
.from("user_profiles")
|
|
.select("username, full_name, avatar_url")
|
|
.eq("id", creator.user_id)
|
|
.single();
|
|
|
|
if (profile) {
|
|
const badges = [];
|
|
if (creator.verified) badges.push("✅");
|
|
if (creator.featured) badges.push("⭐");
|
|
|
|
leaderboardData.push({
|
|
name: profile.full_name || profile.username || "Anonymous",
|
|
value: `${creator.total_projects || 0} projects ${badges.join(" ")}`,
|
|
username: profile.username,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
const medals = ['🥇', '🥈', '🥉'];
|
|
|
|
const description = leaderboardData.length > 0
|
|
? leaderboardData
|
|
.map((user, index) => {
|
|
const medal = index < 3 ? medals[index] : `\`${index + 1}.\``;
|
|
return `${medal} **${user.name}**\n └ ${user.value}`;
|
|
})
|
|
.join("\n\n")
|
|
: "No data available yet. Be the first to contribute!";
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(color)
|
|
.setTitle(`${emoji} ${title}`)
|
|
.setDescription(description)
|
|
.setThumbnail(interaction.guild.iconURL({ size: 128 }))
|
|
.setFooter({
|
|
text: `${interaction.guild.name} • Updated in real-time`,
|
|
iconURL: interaction.guild.iconURL({ size: 32 })
|
|
})
|
|
.setTimestamp();
|
|
|
|
if (leaderboardData.length > 0) {
|
|
embed.addFields({
|
|
name: '📊 Stats',
|
|
value: `Showing top ${leaderboardData.length} contributors`,
|
|
inline: true
|
|
});
|
|
}
|
|
|
|
await interaction.editReply({ embeds: [embed] });
|
|
} catch (error) {
|
|
console.error("Leaderboard command error:", error);
|
|
const embed = new EmbedBuilder()
|
|
.setColor(0xff0000)
|
|
.setTitle("❌ Error")
|
|
.setDescription("Failed to fetch leaderboard. Please try again.");
|
|
|
|
await interaction.editReply({ embeds: [embed] });
|
|
}
|
|
},
|
|
};
|