export async function updateMessage(initialInteractionId) {
const game = selectGameById(store.getState(), initialInteractionId);
if (!game) return;
const round = selectCurrentRound(store.getState(), initialInteractionId);
const timeLeft = Math.max(0, Math.ceil((round.startTime + game.timeout * 1000 - Date.now()) / 1000));
store.dispatch(updateRoundTimeLeft({ interactionId: initialInteractionId, timeLeft: timeLeft }));
let messageContent = {
content: timeLeft > 0 ?
`## 🚦 Round ${game.rounds.length} ⏳ **${timeLeft}** seconds remaining... ⏳\n\n🔥 *Type the sentence shown in the image.*` :
`## 🚦 Round ${game.rounds.length}\n\n🏁 **Time's up!** 🏁`
};
if(timeLeft <= 0){
collectors[initialInteractionId].stop();
}
let embeds = [];
if (Object.keys(round.userAttempts).length > 0) {
embeds.push(buildAttemptsEmbed(round.userAttempts));
}
if (round.ended) {
embeds.push(buildRoundResultsEmbed(round.raceResults));
}
messageContent.embeds = embeds;
// Conditionally add the button only if the round has not ended
if (!round.ended) {
const button = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`show_last_attempt|${game.interactionData.id}`)
.setLabel('👀 Last Attempt')
.setStyle(ButtonStyle.Secondary)
);
messageContent.components = [button];
} else {
// Explicitly set components to an empty array to ensure they are removed when the round ends
messageContent.components = [];
}
const attachment = await getMessageAttachment(initialInteractionId);
if (attachment){
messageContent.files = [attachment];
}
try {
await sendFollowUpMessage(initialInteractionId, messageContent);
} catch (error) {
console.error('Error sending follow-up message:', error);
}
}
export async function updateMessage(initialInteractionId) {
const game = selectGameById(store.getState(), initialInteractionId);
if (!game) return;
const round = selectCurrentRound(store.getState(), initialInteractionId);
const timeLeft = Math.max(0, Math.ceil((round.startTime + game.timeout * 1000 - Date.now()) / 1000));
store.dispatch(updateRoundTimeLeft({ interactionId: initialInteractionId, timeLeft: timeLeft }));
let messageContent = {
content: timeLeft > 0 ?
`## 🚦 Round ${game.rounds.length} ⏳ **${timeLeft}** seconds remaining... ⏳\n\n🔥 *Type the sentence shown in the image.*` :
`## 🚦 Round ${game.rounds.length}\n\n🏁 **Time's up!** 🏁`
};
if(timeLeft <= 0){
collectors[initialInteractionId].stop();
}
let embeds = [];
if (Object.keys(round.userAttempts).length > 0) {
embeds.push(buildAttemptsEmbed(round.userAttempts));
}
if (round.ended) {
embeds.push(buildRoundResultsEmbed(round.raceResults));
}
messageContent.embeds = embeds;
// Conditionally add the button only if the round has not ended
if (!round.ended) {
const button = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`show_last_attempt|${game.interactionData.id}`)
.setLabel('👀 Last Attempt')
.setStyle(ButtonStyle.Secondary)
);
messageContent.components = [button];
} else {
// Explicitly set components to an empty array to ensure they are removed when the round ends
messageContent.components = [];
}
const attachment = await getMessageAttachment(initialInteractionId);
if (attachment){
messageContent.files = [attachment];
}
try {
await sendFollowUpMessage(initialInteractionId, messageContent);
} catch (error) {
console.error('Error sending follow-up message:', error);
}
}