From 616d823ddecbac853d1c498dbc5d1abaaa6067ad Mon Sep 17 00:00:00 2001 From: Ayden Jahola Date: Sat, 7 Sep 2024 12:35:19 +0100 Subject: [PATCH] trivia: reset user's steak when time is up --- commands/fun/trivia.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/commands/fun/trivia.js b/commands/fun/trivia.js index c946b33..cd3d912 100644 --- a/commands/fun/trivia.js +++ b/commands/fun/trivia.js @@ -191,11 +191,27 @@ const handleAnswerCollection = async ( } }); - answerCollector.on("end", (collected, reason) => { + answerCollector.on("end", async (collected, reason) => { if (reason === "time") { - interaction.followUp( - `<@${userId}> Time's up! the correct answer is **${correctAnswer}.**` - ); + // Reset the user's streak when time runs out + try { + let userScore = await Leaderboard.findOne({ userId }); + if (userScore) { + userScore.streak = 0; // Reset streak + await userScore.save(); + } + + await interaction.followUp( + `<@${userId}> Time's up! The correct answer is **${correctAnswer}**. Your current streak is **${userScore.streak}**.` + ); + } catch (error) { + console.error("Error resetting streak after time limit:", error); + await interaction.followUp({ + content: "There was an error resetting your streak.", + ephemeral: true, + }); + } + ONGOING_TRIVIA.delete(userId); } });