feat: update match request embed format and notification handling
This commit is contained in:
@@ -49,6 +49,8 @@ class NotificationService {
|
||||
return res.status(400).json({ error: 'Invalid match data' });
|
||||
}
|
||||
|
||||
matchData.match_date = `${matchData.match_date}T${matchData.match_time}Z`;
|
||||
|
||||
const { data: subscriptions, error } = await this.supabase
|
||||
.from('active_subscriptions')
|
||||
.select('*')
|
||||
@@ -59,9 +61,22 @@ class NotificationService {
|
||||
return res.status(500).json({ error: 'Failed to fetch subscriptions' });
|
||||
}
|
||||
|
||||
const results = [];
|
||||
for (const subscription of (subscriptions || [])) {
|
||||
try {
|
||||
const channel = await this.bot.client.channels.fetch(subscription.notification_channel_id);
|
||||
|
||||
// Check if bot has permissions to send messages in this channel
|
||||
if (!channel.permissionsFor(this.bot.client.user).has(['SendMessages', 'ViewChannel'])) {
|
||||
console.warn(`Missing permissions for channel ${subscription.notification_channel_id} in server ${channel.guild.name}`);
|
||||
results.push({
|
||||
channelId: subscription.notification_channel_id,
|
||||
status: 'failed',
|
||||
error: 'Missing permissions'
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const embed = createMatchRequestEmbed(matchData);
|
||||
const actionRow = createMatchActionRow(matchData.game_name);
|
||||
|
||||
@@ -69,12 +84,32 @@ class NotificationService {
|
||||
embeds: [embed],
|
||||
components: [actionRow]
|
||||
});
|
||||
|
||||
results.push({
|
||||
channelId: subscription.notification_channel_id,
|
||||
status: 'success'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Error sending notification to channel ${subscription.notification_channel_id}:`, error);
|
||||
results.push({
|
||||
channelId: subscription.notification_channel_id,
|
||||
status: 'failed',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ success: true });
|
||||
res.json({
|
||||
success: true,
|
||||
results,
|
||||
summary: {
|
||||
total: results.length,
|
||||
successful: results.filter(r => r.status === 'success').length,
|
||||
failed: results.filter(r => r.status === 'failed').length
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error handling match notification:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
@@ -89,12 +124,14 @@ class NotificationService {
|
||||
const requiredFields = [
|
||||
'game_name',
|
||||
'game_id',
|
||||
'created_by_user_id',
|
||||
'status',
|
||||
'team_size',
|
||||
'match_type',
|
||||
'region',
|
||||
'match_date',
|
||||
'match_class',
|
||||
'status'
|
||||
'match_time',
|
||||
'match_class'
|
||||
];
|
||||
|
||||
return requiredFields.every(field => matchData[field] !== undefined);
|
||||
|
||||
@@ -147,6 +147,7 @@ class EmbedBuilders {
|
||||
}
|
||||
|
||||
static createMatchRequestEmbed(matchData) {
|
||||
// Parse the match date from the provided format
|
||||
const matchDateTime = new Date(matchData.match_date);
|
||||
const formattedDateTime = matchDateTime.toLocaleString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user