mirror of
https://github.com/aydenjahola/discord-multipurpose-bot.git
synced 2024-11-22 08:45:55 +00:00
trivia: add streaks
This commit is contained in:
parent
b33a4c02cc
commit
9d3a56a640
3 changed files with 9 additions and 2 deletions
|
@ -27,6 +27,7 @@ module.exports = {
|
||||||
name: displayName,
|
name: displayName,
|
||||||
correctAnswers: entry.correctAnswers,
|
correctAnswers: entry.correctAnswers,
|
||||||
gamesPlayed: entry.gamesPlayed,
|
gamesPlayed: entry.gamesPlayed,
|
||||||
|
streak: entry.streak, // Include streak
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
|
@ -38,6 +39,7 @@ module.exports = {
|
||||||
name: entry.username,
|
name: entry.username,
|
||||||
correctAnswers: entry.correctAnswers,
|
correctAnswers: entry.correctAnswers,
|
||||||
gamesPlayed: entry.gamesPlayed,
|
gamesPlayed: entry.gamesPlayed,
|
||||||
|
streak: entry.streak, // Include streak
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -50,7 +52,7 @@ module.exports = {
|
||||||
|
|
||||||
// Add each leaderboard entry
|
// Add each leaderboard entry
|
||||||
leaderboardEntries.forEach((entry) => {
|
leaderboardEntries.forEach((entry) => {
|
||||||
const fieldValue = `${entry.correctAnswers} correct answers in ${entry.gamesPlayed} games`;
|
const fieldValue = `${entry.correctAnswers} correct answers in ${entry.gamesPlayed} games\nCurrent streak: ${entry.streak}`;
|
||||||
|
|
||||||
leaderboardEmbed.addFields({
|
leaderboardEmbed.addFields({
|
||||||
name: `${entry.position}. ${entry.name}`,
|
name: `${entry.position}. ${entry.name}`,
|
||||||
|
|
|
@ -163,17 +163,21 @@ const handleAnswerCollection = async (
|
||||||
username,
|
username,
|
||||||
gamesPlayed: 1,
|
gamesPlayed: 1,
|
||||||
correctAnswers: userAnswer === correctAnswer ? 1 : 0,
|
correctAnswers: userAnswer === correctAnswer ? 1 : 0,
|
||||||
|
streak: userAnswer === correctAnswer ? 1 : 0, // Start streak
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
userScore.gamesPlayed += 1;
|
userScore.gamesPlayed += 1;
|
||||||
if (userAnswer === correctAnswer) {
|
if (userAnswer === correctAnswer) {
|
||||||
userScore.correctAnswers += 1;
|
userScore.correctAnswers += 1;
|
||||||
|
userScore.streak += 1; // Increment streak
|
||||||
|
} else {
|
||||||
|
userScore.streak = 0; // Reset streak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await userScore.save();
|
await userScore.save();
|
||||||
|
|
||||||
await interaction.followUp(
|
await interaction.followUp(
|
||||||
`${resultMessage} <@${userId}> You've answered ${userScore.correctAnswers} questions correctly out of ${userScore.gamesPlayed} games.`
|
`${resultMessage} <@${userId}> You've answered ${userScore.correctAnswers} questions correctly out of ${userScore.gamesPlayed} games. Your current streak is **${userScore.streak}**.`
|
||||||
);
|
);
|
||||||
|
|
||||||
ONGOING_TRIVIA.delete(userId);
|
ONGOING_TRIVIA.delete(userId);
|
||||||
|
|
|
@ -5,6 +5,7 @@ const leaderboardSchema = new mongoose.Schema({
|
||||||
username: { type: String, required: true },
|
username: { type: String, required: true },
|
||||||
gamesPlayed: { type: Number, default: 0 },
|
gamesPlayed: { type: Number, default: 0 },
|
||||||
correctAnswers: { type: Number, default: 0 },
|
correctAnswers: { type: Number, default: 0 },
|
||||||
|
streak: { type: Number, default: 0 },
|
||||||
});
|
});
|
||||||
|
|
||||||
const Leaderboard = mongoose.model("Leaderboard", leaderboardSchema);
|
const Leaderboard = mongoose.model("Leaderboard", leaderboardSchema);
|
||||||
|
|
Loading…
Reference in a new issue