Ostatnio aktywny 3 weeks ago

Rewizja d02cd0bbef46efe82451141b883ba49fb0d02770

set-layout.ts Surowy
1import { ChatInputCommandInteraction } from "discord.js";
2import { cfg, saveConfig } from "@systems/config";
3import { PollUI } from "@ui/poll";
4import { replyAndDelete } from "@utils";
5import { hasOfficerRole } from "@systems/users";
6
7export async function handleSetLayout(interaction: ChatInputCommandInteraction): Promise<void> {
8 const member = await interaction.guild!.members.fetch(interaction.user.id);
9 if (!hasOfficerRole(member, cfg("officerRoles"))) {
10 return void replyAndDelete(interaction, "❌ Only officers can change the poll layout.", true);
11 }
12
13 const name = interaction.options.getString("layout", true);
14
15 if (!PollUI.setLayout(name)) {
16 const available = PollUI.layouts()
17 .map((l) => `\`${l.name}\`${l.description}`)
18 .join("\n");
19 return void replyAndDelete(interaction,
20 `❌ Layout \`${name}\` not found. Available layouts:\n${available}`, true
21 );
22 }
23
24 saveConfig();
25
26 return void replyAndDelete(interaction,
27 `✅ Poll layout set to \`${name}\`. Use \`/tg poll reload\` to apply.`, true
28 );
29}
30
31export async function autocompleteLayout(interaction: any): Promise<void> {
32 const focused = interaction.options.getFocused().toLowerCase();
33 const choices = PollUI.layouts()
34 .filter((l) => l.name.includes(focused))
35 .map((l) => ({ name: `${l.name}${l.description}`, value: l.name }));
36 await interaction.respond(choices);
37}