import Discord from 'discord.js'; import roblox from 'noblox.js'; import ms from 'ms'; import fs from 'fs/promises'; import config from '../../../config'; import BotClient from '../../../utils/classes/BotClient'; import RobloxDatastore from '../../../utils/classes/RobloxDatastore'; import GroupHandler from '../../../utils/classes/GroupHandler'; import UniverseHandler from '../../../utils/classes/UniverseHandler'; import CommandFile from '../../../utils/interfaces/CommandFile'; import ModerationData from '../../../utils/interfaces/ModerationData'; import GroupBanEntry from '../../../utils/interfaces/GroupBanEntry'; import SuspensionEntry from '../../../utils/interfaces/SuspensionEntry'; const database = new RobloxDatastore(config); function formatWarnDate(date: Date): string { let hour = date.getHours(); let isAM = false; if (hour === 0) { hour = 12; isAM = true; } else if (hour === 12) { isAM = false; } else { if (hour < 12) { isAM = true; } else { hour -= 12; } } let mins = `${date.getMinutes()}`; if (mins.length === 1) mins = `0${mins}`; return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()} - ${hour}:${mins} ${isAM ? 'AM' : 'PM'}`; } const command: CommandFile = { slashData: new Discord.SlashCommandBuilder() .setName('checkuser') .setDescription("Gets information about the inputted user") .addStringOption(o => o.setName('username').setDescription("The username of the user you wish to check").setRequired(true)) as Discord.SlashCommandBuilder, commandData: { category: 'User', isEphemeral: false, permissions: config.permissions.group.user, hasCooldown: false, preformGeneralVerificationChecks: false, }, run: async (interaction: Discord.CommandInteraction, client: BotClient, args: any): Promise => { let username = args['username']; let robloxID = (await roblox.getIdFromUsername(username)) as number; if (!robloxID) { let embed = client.embedMaker({ title: 'Invalid Username', description: 'The username provided is an invalid Roblox username', type: 'error', author: interaction.user }); return await interaction.editReply({ embeds: [embed] }); } username = await roblox.getUsernameFromId(robloxID); let gameDataValue; let bannedIndex = -1; let isGroupBanned = false; // ... (unchanged) let groupDataValue = ''; // Declare and initialize groupDataValue here let groupRankInfo = ''; // Declare and initialize groupRankInfo here if (client.config.groupIds.length !== 0 && args['group']) { let groupID = GroupHandler.getIDFromName(args['group']); if (groupID === null) { let embed = client.embedMaker({ title: 'Error', description: 'The group ID is null or undefined.', type: 'error', author: interaction.user, }); return await interaction.editReply({ embeds: [embed] }); } let groupRoles; let userRank: string | null = null; // Declare userRank here try { groupRoles = await roblox.getRoles(groupID); if (groupID) { userRank = (await roblox.getRankInGroup(groupID, robloxID)).toString(); // Convert to string } } catch (error) { console.error('Error fetching group roles:', error); let embed = client.embedMaker({ title: 'Error', description: 'An error occurred while fetching group roles.', type: 'error', author: interaction.user, }); return await interaction.editReply({ embeds: [embed] }); } let rolesText = groupRoles.map(role => `Role Name: ${role.name} | Role ID: ${role.id}`).join('\n'); groupDataValue = `Roles:\n${rolesText}`; if (groupID === 11307343) { const rankName = await roblox.getRankNameInGroup(groupID, robloxID); console.log('Rank Name:', rankName); groupRankInfo = `\n\n**Group Rank:**\nRank Name: ${rankName}\nRank ID: ${userRank !== null ? userRank : 'Guest'}`; groupDataValue += groupRankInfo; } } const avatarUrl = (await roblox.getPlayerThumbnail(robloxID, '150x150'))[0]?.imageUrl || ''; const groupID = args['group'] ? parseInt(args['group'], 10) : null; const userRank = groupID ? (await roblox.getRankInGroup(groupID, robloxID)).toString() : null; // Convert to string const userGroups = await roblox.getGroups(robloxID); const maxGroupsToShow = 10; let groupList = ''; for (let i = 0; i < Math.min(userGroups.length, maxGroupsToShow); i++) { const group = userGroups[i]; groupList += `[${group.Name}](https://www.roblox.com/groups/${group.Id}/groupinfo)`; if (i < maxGroupsToShow - 1) { groupList += '\n'; } } if (userGroups.length > maxGroupsToShow) { const remainingGroups = userGroups.length - maxGroupsToShow; groupList += ` and ${remainingGroups} other group${remainingGroups > 1 ? 's' : ''}.`; } let embed = client.embedMaker({ title: 'Information', description: '', type: 'info', author: interaction.user }); embed.addFields({ name: "**User Data**", value: `**Username:** [${username}](https://www.roblox.com/users/${robloxID}/profile)\n**Roblox ID:** ${robloxID}\n**Valor Earned:** 10 / 100\n${groupID ? `**Group Rank:** ${userRank !== null ? await roblox.getRankNameInGroup(groupID, robloxID) : 'Guest'}` : ''}`, inline: false }); if (groupDataValue) { embed.addFields({ name: "**Group Data**", value: groupDataValue }); if (groupID === 11307343) { const rankName = await roblox.getRankNameInGroup(groupID, robloxID); console.log('Rank Name:', rankName); const groupRankField = { name: "**Group Rank**", value: `Rank Name: ${rankName}\nRank ID: ${userRank !== null ? userRank : 'Guest'}` }; embed.addFields(groupRankField); } } embed.addFields({ name: `**Groups [${userGroups.length}]**`, value: groupList, }); embed.setThumbnail(avatarUrl); embed.setColor('#DC143C'); const requestedBy = (interaction.member as Discord.GuildMember)?.displayName || interaction.user.username; const currentDate = new Date().toLocaleString(); embed.addFields({ name: 'Requested by', value: `• ${requestedBy} on ${currentDate}`, }); return await interaction.editReply({ embeds: [embed] }); }, }; if (config.universes.length !== 0) { command.slashData.addStringOption(o => o.setName('universe').setDescription("The universe to check the user's moderation status on").setRequired(false).addChoices(...UniverseHandler.parseUniverses() as any)); } if (config.groupIds.length !== 0) { command.slashData.addStringOption(o => o.setName('group').setDescription("The group to check the user's group data in").setRequired(false).addChoices(...GroupHandler.parseGroups() as any)); } export default command;