import { type ChatInputCommandInteraction, type Client, type GuildMember, SlashCommandBuilder, } from "discord.js"; import { isApiErrorV2, roblox } from "@/roblox/client"; import type { RobloxUserId } from "@/roblox/types"; import { hasManagerPermissions } from "@/utils/permissions"; import { constructUserContainer } from "@/utils/profile"; const commandData = new SlashCommandBuilder() .setName("user") .setDescription("Get information about a Roblox user") .addSubcommand((subcommand) => subcommand .setName("discord") .setDescription("Use Bloxlink to get Roblox info from a Discord user") .addUserOption((option) => option .setName("user") .setDescription("The Discord user to look up") .setRequired(true), ), ) .addSubcommand((subcommand) => subcommand .setName("roblox") .setDescription("Get Roblox info from a user ID or username") .addStringOption((option) => option .setName("input") .setDescription( "The Roblox username to lookup - prefix with id: for IDs", ) .setRequired(true), ), ); async function execute( _client: Client, interaction: ChatInputCommandInteraction, ) { const subcommand = interaction.options.getSubcommand(); const isModerator = await hasManagerPermissions( interaction.member as GuildMember, ); await interaction.deferReply(); try { if (subcommand === "discord") { await interaction.editReply("Not implemented"); return; } const input = interaction.options.getString("input", true); const isId = input.startsWith("id:"); let id: RobloxUserId; if (isId) { id = input.slice(3); if (!id) { await interaction.editReply("Invalid ID provided."); return; } } else { const [usersRes] = await roblox.getUsersByUsernames([input]); if (!usersRes || !usersRes.data || usersRes.data.length === 0) { await interaction.editReply("User not found"); return; } id = usersRes.data[0].id; } 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; await interaction.editReply(`Fetching bans for user with ID ${id}...`); const [bansRes] = await roblox.getUserRestrictionLogs("21449357", id); const bans = bansRes ?? 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, bans: { container: bansContainer }, } = await constructUserContainer(user, { bans, thumbnailUri, showPrivate: isModerator, }); interaction.editReply(user.id); await interaction.followUp({ flags: ["IsComponentsV2"], components: [mainContainer, bansContainer], }); } catch (err) { console.error(err); await interaction.editReply( "An unexpected error occurred while fetching the user.", ); } } export default { data: commandData, execute, };