Update index.js
This commit is contained in:
120
index.js
120
index.js
@@ -46,10 +46,9 @@ async function findUserByUsername(username) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getBadgeImageUrl(badgeName) {
|
||||
badgeName = badgeName.toUpperCase().replace(/ /g, '_');
|
||||
let badgeUrl = 'https://www.vrbattles.gg/assets/images/badges/xp_badges/';
|
||||
let badgeUrl = 'assets/images/badges/xp_badges/';
|
||||
|
||||
if (badgeName.startsWith('BADGE_A')) {
|
||||
badgeUrl += 'A/';
|
||||
@@ -66,73 +65,72 @@ function getBadgeImageUrl(badgeName) {
|
||||
console.log(badgeUrl);
|
||||
return badgeUrl;
|
||||
}
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
if (!interaction.isCommand()) return;
|
||||
|
||||
const { commandName } = interaction;
|
||||
|
||||
if (commandName === 'finduser') {
|
||||
if (commandName === 'ping') {
|
||||
await interaction.reply('Pong!');
|
||||
} else if (commandName === 'finduser') {
|
||||
const username = interaction.options.getString('username');
|
||||
|
||||
await interaction.deferReply(); // Defer the reply to give more time for processing
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
const userData = await findUserByUsername(username);
|
||||
if (userData && userData.success) {
|
||||
let playerData;
|
||||
try {
|
||||
playerData = JSON.parse(userData.player_data);
|
||||
} catch (error) {
|
||||
await interaction.editReply('Error parsing player data.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!playerData || !playerData.profile) {
|
||||
await interaction.editReply('User found but profile data is null. They need to log in to VRBattles to update their profile.');
|
||||
return;
|
||||
}
|
||||
|
||||
const user = playerData.profile;
|
||||
const badgeImageUrl = getBadgeImageUrl(user.current_level_badge);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`User: ${playerData.username}`)
|
||||
.setDescription(`Bio: ${user.bio || 'No bio available'}`)
|
||||
.addFields(
|
||||
{ name: 'Country', value: user.country || 'Unknown', inline: true },
|
||||
{ name: 'Rank', value: user.rank || 'Unranked', inline: true },
|
||||
{ name: 'Level', value: user.level.toString(), inline: true },
|
||||
{ name: 'Prestige', value: user.prestige?.toString() || 'None', inline: true },
|
||||
{ name: 'Current Level Badge', value: user.current_level_badge || 'None', inline: true },
|
||||
{ name: 'XP', value: user.xp.toString(), inline: true }
|
||||
)
|
||||
.iconURL('badgeImageUrl'); // Directly set the image URL
|
||||
.setColor('#0099ff');
|
||||
|
||||
if (user.avatar) {
|
||||
embed.setThumbnail(`https://www.vrbattles.gg/assets/uploads/profile/${user.avatar}`);
|
||||
}
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setLabel('🔵 View Profile')
|
||||
.setStyle(ButtonStyle.Link)
|
||||
.setURL(`https://www.vrbattles.gg/profile/${playerData.username}`),
|
||||
new ButtonBuilder()
|
||||
.setLabel('🟡 Join Discord')
|
||||
.setStyle(ButtonStyle.Link)
|
||||
.setURL('https://discord.gg/j3DKVATPGQ') // Replace with your Discord invite URL
|
||||
);
|
||||
|
||||
await interaction.editReply({ embeds: [embed], components: [row] });
|
||||
} else {
|
||||
await interaction.editReply('User not found or error occurred while fetching data.');
|
||||
const userData = await findUserByUsername(username);
|
||||
if (userData && userData.success) {
|
||||
let playerData;
|
||||
try {
|
||||
playerData = JSON.parse(userData.player_data);
|
||||
} catch (error) {
|
||||
await interaction.editReply('Error parsing player data.');
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error handling interaction:', error);
|
||||
await interaction.editReply('An error occurred while processing your request.');
|
||||
|
||||
if (!playerData || !playerData.profile) {
|
||||
await interaction.editReply('User found but profile data is null. They need to log in to VRBattles to update their profile.');
|
||||
return;
|
||||
}
|
||||
|
||||
const user = playerData.profile;
|
||||
const badgeImageUrl = getBadgeImageUrl(user.current_level_badge);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`User: ${playerData.username}`)
|
||||
.setDescription(`Bio: ${user.bio || 'No bio available'}`)
|
||||
.addFields(
|
||||
{ name: 'Country', value: user.country || 'Unknown', inline: true },
|
||||
{ name: 'Rank', value: user.rank || 'Unranked', inline: true },
|
||||
{ name: 'Level', value: user.level.toString(), inline: true },
|
||||
{ name: 'Prestige', value: user.prestige?.toString() || 'None', inline: true },
|
||||
{ name: 'Current Level Badge', value: user.current_level_badge || 'None', inline: true },
|
||||
{ name: 'XP', value: user.xp.toString(), inline: true }
|
||||
)
|
||||
.setImage(badgeImageUrl)
|
||||
.setColor('#0099ff');
|
||||
|
||||
if (user.avatar) {
|
||||
embed.setThumbnail(`https://www.vrbattles.gg/assets/uploads/profile/${user.avatar}`);
|
||||
}
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setLabel('🔵 View Profile')
|
||||
.setStyle(ButtonStyle.Link)
|
||||
.setURL(`https://www.vrbattles.gg/profile/${playerData.username}`),
|
||||
new ButtonBuilder()
|
||||
.setLabel('🟡 Join Discord')
|
||||
.setStyle(ButtonStyle.Link)
|
||||
.setURL('https://discord.gg/j3DKVATPGQ') // Replace with your Discord invite URL
|
||||
);
|
||||
|
||||
await interaction.editReply({ embeds: [embed], components: [row] });
|
||||
} else {
|
||||
await interaction.editReply('User not found or error occurred while fetching data.');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Use the bot token here
|
||||
client.login(process.env.BOT_TOKEN);
|
||||
Reference in New Issue
Block a user