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