import { ChatInputCommandInteraction } from "discord.js"; import { Config } from "@systems/config"; import { resolveUser, hasOfficerRole } from "@systems/users"; import { WRank } from "@systems/wrank"; import { Bringer } from "@systems/bringer"; import { replyAndDelete } from "@src/utils"; import { Nation } from "@types"; import { TG } from "@systems/tg"; import { Nations } from "@systems/nations"; export async function handleRankGet(interaction: ChatInputCommandInteraction): Promise { const member = await interaction.guild!.members.fetch(interaction.user.id); const isOfficer = hasOfficerRole(member, Config.get({ section: "roles", key: "officer" })); const nameArg = interaction.options.getString("name"); if (nameArg && !isOfficer) { return void replyAndDelete(interaction, "❌ Only officers can view other players' ranks."); } let userKey: string | null; if (nameArg) { userKey = nameArg; } else { const user = await resolveUser(member); userKey = user.userKey; } if (!userKey) return void replyAndDelete(interaction, "❌ You are not registered in the system."); const week = TG.currentWeek(); const goal = Config.get({ section: "wrank", key: "goal" }); const weekKey = WRank.weekKey(); for (const nation of Nations.all()) { const entry = week.entries[nation].find((e) => e.userKey === userKey); if (!entry) continue; const isDone = entry.tgCount >= goal; const delta = entry.previousRank !== undefined ? entry.currentRank - entry.previousRank : 0; const deltaStr = delta < 0 ? ` (↑${Math.abs(delta)})` : delta > 0 ? ` (↓${delta})` : ""; const bringer = Bringer.get({ nation: entry.nation }); const isBringer = bringer === userKey && isDone; const lines = [ `**${entry.characterName}** · ${entry.nation}`, `**W.Rank:** ${entry.currentRank}${deltaStr}${isBringer ? ` · ${entry.nation === Nation.Capella ? "Luminous Bringer" : "Storm Bringer"}` : ""}`, `**Points:** ${entry.weeklyPoints}`, `**TGs done:** ${entry.tgCount}/${goal}${isDone ? " ✅" : ""}`, `**Week:** ${weekKey}`, ].join("\n"); return void replyAndDelete(interaction, lines); } return void replyAndDelete(interaction, `❌ No rank found for **${userKey}** this week.`); }