Остання активність 3 weeks ago

Версія 725529c8fb8d8aa86d2a6e7e0b30af13628a3a8d

gistfile1.txt Неформатований
1import { ChatInputCommandInteraction } from "discord.js";
2import { Updates } from "@systems/updates";
3import { Discord } from "@discord";
4
5export 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
24export 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
38export 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
53export 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
66export const UpdatesCommands = {
67 post: handleUpdatesPost,
68 preview: handleUpdatesPreview,
69 list: handleUpdatesList,
70 autocomplete: autocompleteVersion,
71};