fix: Normalize exam and cooldown dates to the start of the day for consistent calculations.

This commit is contained in:
syntaxbullet
2026-01-05 17:36:53 +01:00
parent 9a32ab298d
commit 278ef4b6b0

View File

@@ -47,6 +47,7 @@ export const exam = createCommand({
// Set exam day to today
const nextExamDate = new Date(now);
nextExamDate.setDate(now.getDate() + 7);
nextExamDate.setHours(0, 0, 0, 0);
const nextExamTimestamp = Math.floor(nextExamDate.getTime() / 1000);
const metadata: ExamMetadata = {
@@ -65,7 +66,7 @@ export const exam = createCommand({
await interaction.editReply({
embeds: [createSuccessEmbed(
`You have registered for the exam! Your exam day is **${DAYS[currentDay]}** (Server Time).\n` +
`Come back on <t:${nextExamTimestamp}:F> (<t:${nextExamTimestamp}:R>) to take your first exam!`,
`Come back on <t:${nextExamTimestamp}:D> (<t:${nextExamTimestamp}:R>) to take your first exam!`,
"Exam Registration Successful"
)]
});
@@ -76,15 +77,17 @@ export const exam = createCommand({
const examDay = metadata.examDay;
// 3. Cooldown Check
if (now < new Date(timer.expiresAt)) {
// Calculate time remaining
const expiresAt = new Date(timer.expiresAt);
expiresAt.setHours(0, 0, 0, 0);
if (now < expiresAt) {
// Calculate time remaining
const timestamp = Math.floor(expiresAt.getTime() / 1000);
await interaction.editReply({
embeds: [createErrorEmbed(
`You have already taken your exam for this week (or are waiting for your first week to pass).\n` +
`Next exam available: <t:${timestamp}:F> (<t:${timestamp}:R>)`
`Next exam available: <t:${timestamp}:D> (<t:${timestamp}:R>)`
)]
});
return;
@@ -98,6 +101,7 @@ export const exam = createCommand({
const nextExamDate = new Date(now);
nextExamDate.setDate(now.getDate() + daysUntil);
nextExamDate.setHours(0, 0, 0, 0);
const nextExamTimestamp = Math.floor(nextExamDate.getTime() / 1000);
const newMetadata: ExamMetadata = {
@@ -120,7 +124,7 @@ export const exam = createCommand({
embeds: [createErrorEmbed(
`You missed your exam day! Your exam day is **${DAYS[examDay]}** (Server Time).\n` +
`You verify your attendance but score a **0**.\n` +
`Your next exam opportunity is: <t:${nextExamTimestamp}:F> (<t:${nextExamTimestamp}:R>)`,
`Your next exam opportunity is: <t:${nextExamTimestamp}:D> (<t:${nextExamTimestamp}:R>)`,
"Exam Failed"
)]
});
@@ -147,6 +151,7 @@ export const exam = createCommand({
// 6. Update State
const nextExamDate = new Date(now);
nextExamDate.setDate(now.getDate() + 7);
nextExamDate.setHours(0, 0, 0, 0);
const nextExamTimestamp = Math.floor(nextExamDate.getTime() / 1000);
const newMetadata: ExamMetadata = {
@@ -182,7 +187,7 @@ export const exam = createCommand({
`**XP Gained:** ${diff.toString()}\n` +
`**Multiplier:** x${multiplier.toFixed(2)}\n` +
`**Reward:** ${reward.toString()} Currency\n\n` +
`See you next week: <t:${nextExamTimestamp}:F>`,
`See you next week: <t:${nextExamTimestamp}:D>`,
"Exam Passed!"
)]
});