import { isApiErrorV2, roblox } from "@/roblox/client"; import type { RobloxUserId } from "@/roblox/types"; import { constructBansSummaryContainer, constructUserContainer, } from "@/utils/profile"; import type { ChatInputCommandInteraction, MessageContextMenuCommandInteraction, } from "discord.js"; export async function processRobloxUserInteraction( interaction: | ChatInputCommandInteraction | MessageContextMenuCommandInteraction, id: RobloxUserId, isModerator: boolean, ) { try { await interaction.editReply(`Fetching user with ID ${id}...`); const [userRes, userErr] = await roblox.getUser(id); if (userErr) { if (isApiErrorV2(userErr)) { await interaction.editReply( `There was an error fetching the user: ${userErr.message}`, ); } else { await interaction.editReply("There was an error fetching the user."); } return; } const user = userRes; await interaction.editReply( `Found user with username ${user.name}, fetching thumbnail...`, ); const [thumbnailRes] = await roblox.getThumbnail(id, { shape: "SQUARE" }); const thumbnailUri = thumbnailRes ? thumbnailRes.response.imageUri : null; const randomMessages = [ "grok is this true", "<:swagong:1176858666452922469>", "awawawawawawawawawawwaawawawwa", "<:wawa:1158423817698430977>", "<:max:1476776753845370991>", "<:snickerdoodle:1477173429575749716>", ]; const message = randomMessages[Math.floor(Math.random() * randomMessages.length)]; await interaction.editReply(message); const { mainContainer } = await constructUserContainer(user, { thumbnailUri, showPrivate: isModerator, }); const banSummary = await constructBansSummaryContainer(id, { showPrivate: isModerator, }); await interaction.editReply(user.id); await interaction.followUp({ flags: ["IsComponentsV2"], components: [mainContainer, banSummary.container], }); } catch (err) { console.error(err); await interaction.editReply( "An unexpected error occurred while fetching the user.", ); } }