import { ChatInputCommandInteraction } from "discord.js"; import { cfg } from "../../systems/config"; import { resolveUser, hasOfficerRole } from "../../systems/users"; import { setCharacterNation, getActiveCharacter } from "../../systems/characters"; import { replyAndDelete } from "../../utils"; import { Nation } from "../../types"; export async function handleCharSetNation(interaction: ChatInputCommandInteraction): Promise { const member = await interaction.guild!.members.fetch(interaction.user.id); const isOfficer = hasOfficerRole(member, cfg("officerRoles")); const nameArg = interaction.options.getString("name"); const nation = interaction.options.getString("nation", true) as Nation; const charName = interaction.options.getString("char_name"); // optional, defaults to active let userKey: string | null; if (nameArg) { if (!isOfficer) return replyAndDelete(interaction, "❌ Only officers can manage other players' characters."); userKey = nameArg; } else { const user = await resolveUser(member); userKey = user.userKey; } if (!userKey) return replyAndDelete(interaction, "❌ You are not registered in the system."); const targetName = charName ?? getActiveCharacter(userKey)?.name; if (!targetName) return replyAndDelete(interaction, "❌ No active character found. Specify a character name."); const set = setCharacterNation(userKey, targetName, nation); if (!set) return replyAndDelete(interaction, `❌ No character named **${targetName}** found.`); return replyAndDelete(interaction, `✅ **«${targetName}»** nation set to **${nation}**.`); }