src/interactions/commands/codes.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import config from "@/config";
import { tsExact, tsRelative } from "@/roblox/profile";
import { text } from "@/utils/discord/components";
import {
type ChatInputCommandInteraction,
type Client,
ContainerBuilder,
SlashCommandBuilder,
} from "discord.js";
const commandData = new SlashCommandBuilder()
.setName("codes")
.setDescription(`Get the codes for all ${config.terminology}s`)
.addUserOption((option) =>
option
.setName("user")
.setDescription("Optional user to mention")
.setRequired(false),
);
async function execute(
_client: Client,
interaction: ChatInputCommandInteraction,
) {
const user = interaction.options.getUser("user");
const container = new ContainerBuilder();
const containerTextArr = ["## Codes"];
for (const project of Object.values(config.projects)) {
containerTextArr.push(`### ${project.displayName}`);
if (!project.codes || project.codes.length === 0) {
containerTextArr.push("No codes available.");
continue;
}
for (const code of project.codes) {
const codeText = code.expired ? `~~${code.code}~~` : `**${code.code}**`;
const addedString = code.addedAt
? `added ${tsRelative(code.addedAt)}`
: undefined;
const lineParts = [
`- ${codeText}`,
addedString ? `(${addedString})` : undefined,
].filter(Boolean);
containerTextArr.push(lineParts.join(" "));
}
}
const containerText = text(containerTextArr.join("\n"));
const footerText = text(
[
`\n-# Please tell <@${config.developerId}> if this is incorrect`,
user ? `<@${user.id}>` : undefined,
]
.filter(Boolean)
.join(" • "),
);
container.addTextDisplayComponents(containerText, footerText);
await interaction.reply({
components: [container],
flags: ["IsComponentsV2"],
...(user
? { allowedMentions: { users: [user?.id] } }
: { allowedMentions: { users: [] } }),
});
}
export default {
data: commandData,
execute,
};
|