import { ChatInputCommandInteraction } from "discord.js"; import { cfg } from "../../systems/config"; import { resolveUser, hasOfficerRole } from "../../systems/users"; import { addCharacter } from "../../systems/characters"; import { replyAndDelete } from "../../utils"; import { ClassKey, Nation } from "../../types"; export async function handleCharAdd(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 charName = interaction.options.getString("char_name", true); const cls = interaction.options.getString("class", true) as ClassKey; const level = interaction.options.getInteger("level", true); const nation = interaction.options.getString("nation", true) as Nation; let usermapKey: string | null; if (nameArg) { if (!isOfficer) return replyAndDelete(interaction, "❌ Only officers can manage other players' characters."); usermapKey = nameArg; } else { const user = await resolveUser(member); usermapKey = user.usermapKey; } if (!usermapKey) return replyAndDelete(interaction, "❌ You are not registered in the system."); const added = addCharacter(usermapKey, { name: charName, class: cls, level, nation }); if (!added) return replyAndDelete(interaction, `❌ A character named **${charName}** already exists.`); return replyAndDelete(interaction, `✅ Character **«${charName}»** (${cls} · Lv${level} · ${nation}) added.`); }