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, };