fix: improve match notification handling and embed display
This commit is contained in:
@@ -117,11 +117,8 @@ class NotificationService {
|
||||
}
|
||||
|
||||
validateMatchData(matchData) {
|
||||
if (matchData.type !== 'match_request') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const requiredFields = [
|
||||
'type',
|
||||
'game_name',
|
||||
'game_id',
|
||||
'created_by_user_id',
|
||||
@@ -134,7 +131,27 @@ class NotificationService {
|
||||
'match_class'
|
||||
];
|
||||
|
||||
return requiredFields.every(field => matchData[field] !== undefined);
|
||||
// Check if all required fields are present
|
||||
const hasAllFields = requiredFields.every(field => {
|
||||
const hasField = matchData.hasOwnProperty(field) && matchData[field] !== null && matchData[field] !== undefined;
|
||||
if (!hasField) {
|
||||
console.log(`Missing or null field: ${field}`);
|
||||
}
|
||||
return hasField;
|
||||
});
|
||||
|
||||
if (!hasAllFields) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate team size format (should be a number or string containing a number)
|
||||
const teamSize = matchData.team_size.toString().replace(/[^0-9]/g, '');
|
||||
if (!teamSize || isNaN(teamSize) || teamSize < 1) {
|
||||
console.log('Invalid team size format');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,10 +151,14 @@ class EmbedBuilders {
|
||||
const matchDateTime = new Date(matchData.match_date);
|
||||
const formattedDateTime = matchDateTime.toLocaleString();
|
||||
|
||||
// Format team size to be "4v4" regardless of input format
|
||||
const teamSize = matchData.team_size.toString().replace(/[^0-9]/g, ''); // Keep only numbers
|
||||
const formattedTeamSize = `${teamSize}v${teamSize}`;
|
||||
|
||||
return new EmbedBuilder()
|
||||
.setColor('#00ff00') // Green for new match requests
|
||||
.setTitle(`🎮 New ${matchData.game_name} Match`)
|
||||
.setDescription(`${matchData.team_size}v${matchData.team_size} Match in ${matchData.region} Region`)
|
||||
.setDescription(`${formattedTeamSize} Match in ${matchData.region} Region`)
|
||||
.addFields(
|
||||
{
|
||||
name: '⏰ Starting',
|
||||
@@ -165,6 +169,11 @@ class EmbedBuilders {
|
||||
name: '📊 Status',
|
||||
value: matchData.status,
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: '🎲 Match Type',
|
||||
value: matchData.match_type,
|
||||
inline: true
|
||||
}
|
||||
)
|
||||
.setTimestamp()
|
||||
|
||||
Reference in New Issue
Block a user