Adds some more polish

This commit is contained in:
Michel Fedde 2025-06-26 21:38:03 +02:00
parent b3d0b3a90c
commit 11bd836ec3
18 changed files with 272 additions and 29 deletions

View file

@ -0,0 +1,60 @@
import {CacheType, ChatInputCommandInteraction, hyperlink, PermissionFlagsBits, SlashCommandBuilder} from "discord.js";
import {ChatInteractionCommand, Command} from "./Command";
import * as fs from "node:fs";
import {UserError} from "../UserError";
import {ifError} from "node:assert";
import {BuildContextGetter} from "../../Utilities/BuildContext";
import {EmbedLibrary} from "../EmbedLibrary";
export class BotCommand implements Command, ChatInteractionCommand {
definition(): SlashCommandBuilder {
return new SlashCommandBuilder()
.setName("bot")
.setDescription("Offers some information about the bot")
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addSubcommand(command => command
.setName("build")
.setDescription("Displays some information about the build the bot is running on.")
)
}
execute(interaction: ChatInputCommandInteraction<CacheType>): Promise<void> {
switch (interaction.options.getSubcommand()) {
case "build":
this.displayBuildInfos(interaction);
break;
}
}
private displayBuildInfos(interaction: ChatInputCommandInteraction<CacheType>) {
const buildContext = new BuildContextGetter().getContext();
if (!buildContext) {
throw new UserError("Can't find required deploy information", "Using a valid docker image or (when running on a dev build) running `npm run build` once.");
}
const embed = EmbedLibrary.base("Current Build")
.setFields(
[
{
name: "Build Target",
value: buildContext.target,
inline: true
},
{
name: "Build Label",
value: buildContext.label,
inline: true
},
{
name: "Latest Commit",
value: hyperlink(buildContext.commitHash, buildContext.commitLink)
}
]
)
interaction.reply({
embeds: [embed]
})
}
}