import { ChatInputCommandInteraction } from "discord.js"; import { cfg, saveConfig } from "@systems/config"; import { PollUI } from "@ui/poll"; import { replyAndDelete } from "@utils"; import { hasOfficerRole } from "@systems/users"; export async function handleSetLayout(interaction: ChatInputCommandInteraction): Promise { const member = await interaction.guild!.members.fetch(interaction.user.id); if (!hasOfficerRole(member, cfg("officerRoles"))) { return void replyAndDelete(interaction, "❌ Only officers can change the poll layout.", true); } const name = interaction.options.getString("layout", true); if (!PollUI.setLayout(name)) { const available = PollUI.layouts() .map((l) => `\`${l.name}\` — ${l.description}`) .join("\n"); return void replyAndDelete(interaction, `❌ Layout \`${name}\` not found. Available layouts:\n${available}`, true ); } saveConfig(); return void replyAndDelete(interaction, `✅ Poll layout set to \`${name}\`. Use \`/tg poll reload\` to apply.`, true ); } export async function autocompleteLayout(interaction: any): Promise { const focused = interaction.options.getFocused().toLowerCase(); const choices = PollUI.layouts() .filter((l) => l.name.includes(focused)) .map((l) => ({ name: `${l.name} — ${l.description}`, value: l.name })); await interaction.respond(choices); }