From 584fba7aa039603fec1a744ab2a3366375ad27b2 Mon Sep 17 00:00:00 2001 From: VinceC <33974776+VinceC3@users.noreply.github.com> Date: Sat, 4 Jan 2025 11:16:49 -0600 Subject: [PATCH] Update CommandHandler.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # VRBattles Bot Updates - March 2024 ## Command Improvements ### Find Team Command (`/findteam`) - ๐Ÿ”„ Restructured command to require game selection before team name - ๐Ÿ–ผ๏ธ Added VR Battles image as the main embed image - ๐Ÿงน Removed all buttons for cleaner display - ๐Ÿ“Š Implemented game mode sorting: - Priority order: Squads > Duo > Solo - Secondary sort by creation date (newest first) - ๐ŸŽจ Added game mode icons: - Squads: ๐ŸŽฎ - Duo: ๐ŸŽฏ - Solo: โš”๏ธ - ๐Ÿ“ Condensed stats display format: - M: matches - W: wins - L: losses - WR: win rate - ๐Ÿ‘ฅ Made all team search results visible to everyone in the channel ### Find User Command (`/finduser`) - ๐Ÿ”„ Restructured command to require game selection before username - ๐Ÿ–ผ๏ธ Added VR Battles image as the main embed image - ๐Ÿ” Enhanced user search results: - Shows basic profile info even when no game stats are found - Displays user's avatar, bio, level, XP, and other profile details - Indicates if user is on a team but hasn't played matches - ๐Ÿ”ต Simplified button layout: - Removed Discord invite button - Kept only the "View Profile" button - ๐Ÿ’ฌ Improved status messages: - Clear indication when user exists but hasn't played selected game - Shows team membership status for the selected game --- src/commands/CommandHandler.js | 69 +++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/src/commands/CommandHandler.js b/src/commands/CommandHandler.js index bbbf190..791f5cb 100644 --- a/src/commands/CommandHandler.js +++ b/src/commands/CommandHandler.js @@ -1,4 +1,4 @@ -const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); +const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } = require('discord.js'); const EmbedBuilders = require('../utils/embedBuilders'); class CommandHandler { @@ -206,8 +206,44 @@ class CommandHandler { const teamMessage = isOnTeam ? `\nThey are on a team for ${gameFilter} but haven't played any matches yet.` : ''; + + // Create a basic embed with user info + const basicEmbed = new EmbedBuilder() + .setTitle(`User: ${playerData.username || 'Unknown'}`) + .setDescription(playerData.profile?.bio || 'No bio available') + .setColor('#0099ff') + .setImage('https://www.vrbattles.gg/assets/images/Qubi/vrwearcubesatad.png'); + + // Add avatar if available + if (playerData.profile?.avatar) { + basicEmbed.setThumbnail( + `https://www.vrbattles.gg/assets/uploads/profile/${playerData.profile.avatar}` + ); + } + + // Add basic profile fields + const profileFields = []; + const profile = playerData.profile || {}; + if (profile.country) profileFields.push({ name: 'Country', value: profile.country, inline: true }); + if (profile.level) profileFields.push({ name: 'Level', value: profile.level.toString(), inline: true }); + if (profile.xp) profileFields.push({ name: 'Total XP', value: profile.xp.toString(), inline: true }); + if (profile.prestige) profileFields.push({ name: 'Prestige', value: profile.prestige.toString(), inline: true }); + + if (profileFields.length > 0) { + basicEmbed.addFields(profileFields); + } + + // Add message about no game stats + basicEmbed.addFields({ + name: `${gameFilter} Status`, + value: `โŒ No match history found for ${gameFilter}${teamMessage}` + }); + + const row = this.createActionRow(playerData.username); + await interaction.editReply({ - content: `โœ… User found, but they haven't played ${gameFilter} yet.${teamMessage}` + embeds: [basicEmbed], + components: [row] }); return; } @@ -281,21 +317,22 @@ class CommandHandler { // Input validation if (!teamName || typeof teamName !== 'string') { await interaction.editReply({ - content: 'โŒ Invalid team name provided.' + content: 'โŒ Invalid team name provided.', + ephemeral: false }); return; } - // Enhanced sanitization - only allow alphanumeric characters, spaces, and specific symbols - // Limit the length to prevent buffer overflow attacks + // Enhanced sanitization const sanitizedTeamName = teamName - .replace(/[^a-zA-Z0-9\s\-_.]/g, '') // Remove any characters that aren't alphanumeric, space, hyphen, underscore, or period + .replace(/[^a-zA-Z0-9\s\-_.]/g, '') .trim() - .slice(0, 100); // Limit length to 100 characters + .slice(0, 100); if (!sanitizedTeamName) { await interaction.editReply({ - content: 'โŒ Team name must contain valid characters (letters, numbers, spaces, hyphens, underscores, or periods).' + content: 'โŒ Team name must contain valid characters (letters, numbers, spaces, hyphens, underscores, or periods).', + ephemeral: false }); return; } @@ -309,12 +346,12 @@ class CommandHandler { timestamp: new Date().toISOString() }); - // Game filter is pre-validated by Discord's slash command choices const teamData = await this.playerService.findTeamByName(sanitizedTeamName, gameFilter); if (!teamData || !teamData.success || !teamData.teams || teamData.teams.length === 0) { await interaction.editReply({ - content: 'โŒ No teams found matching your search criteria.' + content: 'โŒ No teams found matching your search criteria.', + ephemeral: false }); return; } @@ -323,7 +360,8 @@ class CommandHandler { await interaction.editReply({ embeds: embeds, - components: [] + components: [], + ephemeral: false }); } catch (error) { this.logger.error('Error in handleFindTeam:', { @@ -334,7 +372,8 @@ class CommandHandler { timestamp: new Date().toISOString() }); await interaction.editReply({ - content: 'โŒ An error occurred while searching for teams.' + content: 'โŒ An error occurred while searching for teams.', + ephemeral: false }); } } @@ -344,11 +383,7 @@ class CommandHandler { new ButtonBuilder() .setLabel('๐Ÿ”ต View Profile') .setStyle(ButtonStyle.Link) - .setURL(`https://www.vrbattles.gg/profile/${username}`), - new ButtonBuilder() - .setLabel('๐ŸŸก Join Main Discord') - .setStyle(ButtonStyle.Link) - .setURL('https://discord.gg/j3DKVATPGQ') + .setURL(`https://www.vrbattles.gg/profile/${username}`) ); } }