set-layout.ts
· 1.4 KiB · TypeScript
Неформатований
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<void> {
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<void> {
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);
}
| 1 | import { ChatInputCommandInteraction } from "discord.js"; |
| 2 | import { cfg, saveConfig } from "@systems/config"; |
| 3 | import { PollUI } from "@ui/poll"; |
| 4 | import { replyAndDelete } from "@utils"; |
| 5 | import { hasOfficerRole } from "@systems/users"; |
| 6 | |
| 7 | export 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 | |
| 31 | export 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 | } |