71 lines
No EOL
2.4 KiB
TypeScript
71 lines
No EOL
2.4 KiB
TypeScript
import { ChatInputCommandInteraction } from "discord.js";
|
|
import { Updates } from "@systems/updates";
|
|
import { Discord } from "@discord";
|
|
|
|
export async function handleUpdatesPost(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
await Discord.Interaction.deferReply(interaction, { ephemeral: true });
|
|
|
|
const opts = Discord.Interaction.options(interaction);
|
|
const version = opts.string({ key: "version" }) ?? Updates.latest();
|
|
|
|
if (!version) {
|
|
await Discord.Interaction.editReply(interaction, "❌ No versions found.");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await Updates.post({ version, client: interaction.client });
|
|
await Discord.Interaction.editReply(interaction, `✅ Update \`${version}\` posted.`);
|
|
} catch (err: any) {
|
|
await Discord.Interaction.editReply(interaction, `❌ Failed: ${err.message}`);
|
|
}
|
|
}
|
|
|
|
export async function handleUpdatesPreview(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
await Discord.Interaction.deferReply(interaction, { ephemeral: true });
|
|
|
|
const opts = Discord.Interaction.options(interaction);
|
|
const version = opts.string({ key: "version" }) ?? Updates.latest();
|
|
|
|
if (!version) {
|
|
await Discord.Interaction.editReply(interaction, "❌ No versions found.");
|
|
return;
|
|
}
|
|
|
|
await Updates.preview({ version, interaction });
|
|
}
|
|
|
|
export async function handleUpdatesList(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
const versions = Updates.list();
|
|
const latest = Updates.latest();
|
|
const lines = versions.map((v) => {
|
|
const entry = Updates.get({ version: v });
|
|
const tag = v === latest ? " ← latest" : "";
|
|
return `⬜ \`${v}\` — ${entry?.title ?? ""}${tag}`;
|
|
});
|
|
|
|
await Discord.Interaction.reply(interaction, {
|
|
content: lines.length > 0 ? lines.join("\n") : "No versions found.",
|
|
ephemeral: true,
|
|
});
|
|
}
|
|
|
|
export async function autocompleteVersion(interaction: any): Promise<void> {
|
|
const focused = interaction.options.getFocused().toLowerCase();
|
|
const versions = Updates.list();
|
|
const choices = versions
|
|
.filter((v) => v.toLowerCase().includes(focused))
|
|
.map((v) => {
|
|
const entry = Updates.get({ version: v });
|
|
return { name: `${v} — ${entry?.title ?? ""}`, value: v };
|
|
})
|
|
.slice(0, 25);
|
|
await interaction.respond(choices);
|
|
}
|
|
|
|
export const UpdatesCommands = {
|
|
post: handleUpdatesPost,
|
|
preview: handleUpdatesPreview,
|
|
list: handleUpdatesList,
|
|
autocomplete: autocompleteVersion,
|
|
}; |