Update index.js
This commit is contained in:
73
index.js
73
index.js
@@ -124,6 +124,9 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Before adding fields to the embed, initialize a counter
|
||||||
|
let totalFields = 0;
|
||||||
|
|
||||||
// Add profile fields dynamically
|
// Add profile fields dynamically
|
||||||
const profileFields = [];
|
const profileFields = [];
|
||||||
|
|
||||||
@@ -156,6 +159,7 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
|
|
||||||
if (profileFields.length > 0) {
|
if (profileFields.length > 0) {
|
||||||
embed.addFields(profileFields);
|
embed.addFields(profileFields);
|
||||||
|
totalFields += profileFields.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set badge image if available
|
// Set badge image if available
|
||||||
@@ -165,8 +169,11 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
|
|
||||||
// Dynamically add game statistics
|
// Dynamically add game statistics
|
||||||
const games = playerData.stats?.games;
|
const games = playerData.stats?.games;
|
||||||
if (games && Object.keys(games).length > 0) {
|
if (games && Object.keys(games).length > 0 && totalFields < 25) {
|
||||||
embed.addFields({ name: '\u200B', value: '**Game Statistics**' });
|
if (totalFields + 1 <= 25) {
|
||||||
|
embed.addFields({ name: '\u200B', value: '**Game Statistics**' });
|
||||||
|
totalFields += 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (const [gameName, gameData] of Object.entries(games)) {
|
for (const [gameName, gameData] of Object.entries(games)) {
|
||||||
if (
|
if (
|
||||||
@@ -211,19 +218,41 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (statsFields.length > 0) {
|
// Calculate the number of fields to be added
|
||||||
embed.addFields(
|
const fieldsToAdd = 1 + statsFields.length; // 1 for the section header
|
||||||
{ name: '\u200B', value: `**${gameName} - ${modeName}**` },
|
|
||||||
...statsFields
|
// Check if adding these fields would exceed the limit
|
||||||
);
|
if (totalFields + fieldsToAdd > 25) {
|
||||||
|
// You can choose to skip adding these fields or break the loop
|
||||||
|
break; // Stops adding more fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the section header
|
||||||
|
embed.addFields({
|
||||||
|
name: '\u200B',
|
||||||
|
value: `**${gameName} - ${modeName}**`,
|
||||||
|
});
|
||||||
|
totalFields += 1;
|
||||||
|
|
||||||
|
// Add the stats fields
|
||||||
|
embed.addFields(statsFields);
|
||||||
|
totalFields += statsFields.length;
|
||||||
|
|
||||||
|
// Check after each addition
|
||||||
|
if (totalFields >= 25) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalFields >= 25) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add teams dynamically
|
// Add teams dynamically
|
||||||
const teams = playerData.teams;
|
const teams = playerData.teams;
|
||||||
if (teams && Object.keys(teams).length > 0) {
|
if (teams && Object.keys(teams).length > 0 && totalFields < 25) {
|
||||||
const teamList = Object.values(teams)
|
const teamList = Object.values(teams)
|
||||||
.map(
|
.map(
|
||||||
(team) =>
|
(team) =>
|
||||||
@@ -231,15 +260,22 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
)
|
)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
embed.addFields(
|
const teamsField = [
|
||||||
{ name: '\u200B', value: '**Teams**' },
|
{ name: '\u200B', value: '**Teams**' },
|
||||||
{ name: 'Team List', value: teamList || 'No teams available' }
|
{ name: 'Team List', value: teamList || 'No teams available' },
|
||||||
);
|
];
|
||||||
|
|
||||||
|
// Check if adding these fields would exceed the limit
|
||||||
|
const fieldsToAdd = teamsField.length;
|
||||||
|
if (totalFields + fieldsToAdd <= 25) {
|
||||||
|
embed.addFields(teamsField);
|
||||||
|
totalFields += fieldsToAdd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add recent matches dynamically
|
// Add recent matches dynamically
|
||||||
const matches = playerData.matches;
|
const matches = playerData.matches;
|
||||||
if (matches && Object.keys(matches).length > 0) {
|
if (matches && Object.keys(matches).length > 0 && totalFields < 25) {
|
||||||
const matchList = Object.values(matches)
|
const matchList = Object.values(matches)
|
||||||
.sort((a, b) => new Date(b.start_time) - new Date(a.start_time)) // Sort by date descending
|
.sort((a, b) => new Date(b.start_time) - new Date(a.start_time)) // Sort by date descending
|
||||||
.slice(0, 3) // Limit to recent 3 matches
|
.slice(0, 3) // Limit to recent 3 matches
|
||||||
@@ -252,10 +288,17 @@ client.on('interactionCreate', async (interaction) => {
|
|||||||
})
|
})
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
||||||
embed.addFields(
|
const matchesField = [
|
||||||
{ name: '\u200B', value: '**Recent Matches**' },
|
{ name: '\u200B', value: '**Recent Matches**' },
|
||||||
{ name: 'Match History', value: matchList || 'No recent matches' }
|
{ name: 'Match History', value: matchList || 'No recent matches' },
|
||||||
);
|
];
|
||||||
|
|
||||||
|
// Check if adding these fields would exceed the limit
|
||||||
|
const fieldsToAdd = matchesField.length;
|
||||||
|
if (totalFields + fieldsToAdd <= 25) {
|
||||||
|
embed.addFields(matchesField);
|
||||||
|
totalFields += fieldsToAdd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add action buttons
|
// Add action buttons
|
||||||
|
|||||||
Reference in New Issue
Block a user