34 lines
1.7 KiB
TypeScript
34 lines
1.7 KiB
TypeScript
import { ChatInputCommandInteraction } from "discord.js";
|
|
import { cfg } from "../../systems/config";
|
|
import { resolveUser, hasOfficerRole } from "../../systems/users";
|
|
import { setCharacterStats, getActiveCharacter } from "../../systems/characters";
|
|
import { replyAndDelete } from "../../utils";
|
|
|
|
export async function handleCharSetStats(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");
|
|
const charName = interaction.options.getString("char_name");
|
|
const atk = interaction.options.getInteger("atk") ?? undefined;
|
|
const def = interaction.options.getInteger("def") ?? undefined;
|
|
const heal = interaction.options.getInteger("heal") ?? undefined;
|
|
|
|
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 = setCharacterStats(userKey, targetName, { atk, def, heal });
|
|
if (!set) return replyAndDelete(interaction, `❌ No character named **${targetName}** found.`);
|
|
|
|
return replyAndDelete(interaction, `✅ Stats updated for **«${targetName}»**.`);
|
|
}
|