nuno ha revisionato questo gist 3 weeks ago. Vai alla revisione
1 file changed, 71 insertions
gistfile1.txt(file creato)
| @@ -0,0 +1,71 @@ | |||
| 1 | + | import { ChatInputCommandInteraction } from "discord.js"; | |
| 2 | + | import { Updates } from "@systems/updates"; | |
| 3 | + | import { Discord } from "@discord"; | |
| 4 | + | ||
| 5 | + | export async function handleUpdatesPost(interaction: ChatInputCommandInteraction): Promise<void> { | |
| 6 | + | await Discord.Interaction.deferReply(interaction, { ephemeral: true }); | |
| 7 | + | ||
| 8 | + | const opts = Discord.Interaction.options(interaction); | |
| 9 | + | const version = opts.string({ key: "version" }) ?? Updates.latest(); | |
| 10 | + | ||
| 11 | + | if (!version) { | |
| 12 | + | await Discord.Interaction.editReply(interaction, "❌ No versions found."); | |
| 13 | + | return; | |
| 14 | + | } | |
| 15 | + | ||
| 16 | + | try { | |
| 17 | + | await Updates.post({ version, client: interaction.client }); | |
| 18 | + | await Discord.Interaction.editReply(interaction, `✅ Update \`${version}\` posted.`); | |
| 19 | + | } catch (err: any) { | |
| 20 | + | await Discord.Interaction.editReply(interaction, `❌ Failed: ${err.message}`); | |
| 21 | + | } | |
| 22 | + | } | |
| 23 | + | ||
| 24 | + | export async function handleUpdatesPreview(interaction: ChatInputCommandInteraction): Promise<void> { | |
| 25 | + | await Discord.Interaction.deferReply(interaction, { ephemeral: true }); | |
| 26 | + | ||
| 27 | + | const opts = Discord.Interaction.options(interaction); | |
| 28 | + | const version = opts.string({ key: "version" }) ?? Updates.latest(); | |
| 29 | + | ||
| 30 | + | if (!version) { | |
| 31 | + | await Discord.Interaction.editReply(interaction, "❌ No versions found."); | |
| 32 | + | return; | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | await Updates.preview({ version, interaction }); | |
| 36 | + | } | |
| 37 | + | ||
| 38 | + | export async function handleUpdatesList(interaction: ChatInputCommandInteraction): Promise<void> { | |
| 39 | + | const versions = Updates.list(); | |
| 40 | + | const latest = Updates.latest(); | |
| 41 | + | const lines = versions.map((v) => { | |
| 42 | + | const entry = Updates.get({ version: v }); | |
| 43 | + | const tag = v === latest ? " ← latest" : ""; | |
| 44 | + | return `⬜ \`${v}\` — ${entry?.title ?? ""}${tag}`; | |
| 45 | + | }); | |
| 46 | + | ||
| 47 | + | await Discord.Interaction.reply(interaction, { | |
| 48 | + | content: lines.length > 0 ? lines.join("\n") : "No versions found.", | |
| 49 | + | ephemeral: true, | |
| 50 | + | }); | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | export async function autocompleteVersion(interaction: any): Promise<void> { | |
| 54 | + | const focused = interaction.options.getFocused().toLowerCase(); | |
| 55 | + | const versions = Updates.list(); | |
| 56 | + | const choices = versions | |
| 57 | + | .filter((v) => v.toLowerCase().includes(focused)) | |
| 58 | + | .map((v) => { | |
| 59 | + | const entry = Updates.get({ version: v }); | |
| 60 | + | return { name: `${v} — ${entry?.title ?? ""}`, value: v }; | |
| 61 | + | }) | |
| 62 | + | .slice(0, 25); | |
| 63 | + | await interaction.respond(choices); | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | export const UpdatesCommands = { | |
| 67 | + | post: handleUpdatesPost, | |
| 68 | + | preview: handleUpdatesPreview, | |
| 69 | + | list: handleUpdatesList, | |
| 70 | + | autocomplete: autocompleteVersion, | |
| 71 | + | }; | |
Più nuovi
Più vecchi