nuno bu gisti düzenledi 3 weeks ago. Düzenlemeye git
1 file changed, 37 insertions
set-layout.ts(dosya oluşturuldu)
| @@ -0,0 +1,37 @@ | |||
| 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 | + | } | |
Daha yeni
Daha eski