52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import { ChatInputCommandInteraction } from "discord.js";
|
|
import { cfg } from "../../systems/config";
|
|
import { resolveUser, hasOfficerRole } from "../../systems/users";
|
|
import { getCurrentWeek, getWeekKey, getBringer } from "../../systems/wrank";
|
|
import { replyAndDelete } from "../../utils";
|
|
|
|
export async function handleRankGet(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
const member = await interaction.guild!.members.fetch(interaction.user.id);
|
|
const isOfficer = hasOfficerRole(member, cfg("officerRoles"));
|
|
const nameArg = interaction.options.getString("name");
|
|
|
|
if (nameArg && !isOfficer) {
|
|
return void replyAndDelete(interaction, "❌ Only officers can view other players' ranks.");
|
|
}
|
|
|
|
let usermapKey: string | null;
|
|
if (nameArg) {
|
|
usermapKey = nameArg;
|
|
} else {
|
|
const user = await resolveUser(member);
|
|
usermapKey = user.usermapKey;
|
|
}
|
|
|
|
if (!usermapKey) return void replyAndDelete(interaction, "❌ You are not registered in the system.");
|
|
|
|
const week = getCurrentWeek();
|
|
const goal = cfg("wRankGoal");
|
|
const weekKey = getWeekKey();
|
|
|
|
for (const nation of ["capella", "procyon"] as const) {
|
|
const entry = week.entries[nation].find((e) => e.usermapKey === usermapKey);
|
|
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 = getBringer(entry.nation);
|
|
const isBringer = bringer === usermapKey && isDone;
|
|
|
|
const lines = [
|
|
`**${entry.characterName}** · ${entry.nation}`,
|
|
`**W.Rank:** ${entry.currentRank}${deltaStr}${isBringer ? ` · ${entry.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 **${usermapKey}** this week.`);
|
|
}
|