fix: improve match notification handling and embed display
This commit is contained in:
@@ -117,11 +117,8 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateMatchData(matchData) {
|
validateMatchData(matchData) {
|
||||||
if (matchData.type !== 'match_request') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
|
'type',
|
||||||
'game_name',
|
'game_name',
|
||||||
'game_id',
|
'game_id',
|
||||||
'created_by_user_id',
|
'created_by_user_id',
|
||||||
@@ -134,7 +131,27 @@ class NotificationService {
|
|||||||
'match_class'
|
'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 matchDateTime = new Date(matchData.match_date);
|
||||||
const formattedDateTime = matchDateTime.toLocaleString();
|
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()
|
return new EmbedBuilder()
|
||||||
.setColor('#00ff00') // Green for new match requests
|
.setColor('#00ff00') // Green for new match requests
|
||||||
.setTitle(`🎮 New ${matchData.game_name} Match`)
|
.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(
|
.addFields(
|
||||||
{
|
{
|
||||||
name: '⏰ Starting',
|
name: '⏰ Starting',
|
||||||
@@ -165,6 +169,11 @@ class EmbedBuilders {
|
|||||||
name: '📊 Status',
|
name: '📊 Status',
|
||||||
value: matchData.status,
|
value: matchData.status,
|
||||||
inline: true
|
inline: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '🎲 Match Type',
|
||||||
|
value: matchData.match_type,
|
||||||
|
inline: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
|
|||||||
Reference in New Issue
Block a user