forked from syntaxbullet/AuroraBot-discord
fix: timestamp rendering issues
This commit is contained in:
@@ -41,8 +41,9 @@ export const exam = createCommand({
|
|||||||
// 2. First Run Logic
|
// 2. First Run Logic
|
||||||
if (!timer) {
|
if (!timer) {
|
||||||
// Set exam day to today
|
// Set exam day to today
|
||||||
const nextWeek = new Date(now);
|
const nextExamDate = new Date(now);
|
||||||
nextWeek.setDate(now.getDate() + 7);
|
nextExamDate.setDate(now.getDate() + 7);
|
||||||
|
const nextExamTimestamp = Math.floor(nextExamDate.getTime() / 1000);
|
||||||
|
|
||||||
const metadata: ExamMetadata = {
|
const metadata: ExamMetadata = {
|
||||||
examDay: currentDay,
|
examDay: currentDay,
|
||||||
@@ -53,14 +54,14 @@ export const exam = createCommand({
|
|||||||
userId: user.id,
|
userId: user.id,
|
||||||
type: EXAM_TIMER_TYPE,
|
type: EXAM_TIMER_TYPE,
|
||||||
key: EXAM_TIMER_KEY,
|
key: EXAM_TIMER_KEY,
|
||||||
expiresAt: nextWeek,
|
expiresAt: nextExamDate,
|
||||||
metadata: metadata
|
metadata: metadata
|
||||||
});
|
});
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [createSuccessEmbed(
|
embeds: [createSuccessEmbed(
|
||||||
`You have registered for the exam! Your exam day is **${DAYS[currentDay]}**.\n` +
|
`You have registered for the exam! Your exam day is **${DAYS[currentDay]}** (Server Time).\n` +
|
||||||
`Come back next week on **${DAYS[currentDay]}** to take your first exam and earn rewards based on your XP gain!`,
|
`Come back on <t:${nextExamTimestamp}:F> (<t:${nextExamTimestamp}:R>) to take your first exam!`,
|
||||||
"Exam Registration Successful"
|
"Exam Registration Successful"
|
||||||
)]
|
)]
|
||||||
});
|
});
|
||||||
@@ -74,13 +75,12 @@ export const exam = createCommand({
|
|||||||
if (now < new Date(timer.expiresAt)) {
|
if (now < new Date(timer.expiresAt)) {
|
||||||
// Calculate time remaining
|
// Calculate time remaining
|
||||||
const expiresAt = new Date(timer.expiresAt);
|
const expiresAt = new Date(timer.expiresAt);
|
||||||
// Simple formatting
|
|
||||||
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}:R> (${DAYS[examDay]})`
|
`Next exam available: <t:${timestamp}:F> (<t:${timestamp}:R>)`
|
||||||
)]
|
)]
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -88,11 +88,13 @@ export const exam = createCommand({
|
|||||||
|
|
||||||
// 4. Day Check
|
// 4. Day Check
|
||||||
if (currentDay !== examDay) {
|
if (currentDay !== examDay) {
|
||||||
// "If not executed on same weekday... we do not reward"
|
// Calculate next correct exam day to correct the schedule
|
||||||
// Consume the attempt (reset timer) but give 0 reward.
|
let daysUntil = (examDay - currentDay + 7) % 7;
|
||||||
|
if (daysUntil === 0) daysUntil = 7;
|
||||||
|
|
||||||
const nextWeek = new Date(now);
|
const nextExamDate = new Date(now);
|
||||||
nextWeek.setDate(now.getDate() + 7);
|
nextExamDate.setDate(now.getDate() + daysUntil);
|
||||||
|
const nextExamTimestamp = Math.floor(nextExamDate.getTime() / 1000);
|
||||||
|
|
||||||
const newMetadata: ExamMetadata = {
|
const newMetadata: ExamMetadata = {
|
||||||
examDay: examDay,
|
examDay: examDay,
|
||||||
@@ -101,7 +103,7 @@ export const exam = createCommand({
|
|||||||
|
|
||||||
await DrizzleClient.update(userTimers)
|
await DrizzleClient.update(userTimers)
|
||||||
.set({
|
.set({
|
||||||
expiresAt: nextWeek,
|
expiresAt: nextExamDate,
|
||||||
metadata: newMetadata
|
metadata: newMetadata
|
||||||
})
|
})
|
||||||
.where(and(
|
.where(and(
|
||||||
@@ -112,8 +114,9 @@ export const exam = createCommand({
|
|||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [createErrorEmbed(
|
embeds: [createErrorEmbed(
|
||||||
`You missed your exam day! Your exam is on **${DAYS[examDay]}**, but today is ${DAYS[currentDay]}.\n` +
|
`You missed your exam day! Your exam day is **${DAYS[examDay]}** (Server Time).\n` +
|
||||||
`You verify your attendance but score a **0**. Come back next **${DAYS[examDay]}**!`,
|
`You verify your attendance but score a **0**.\n` +
|
||||||
|
`Your next exam opportunity is: <t:${nextExamTimestamp}:F> (<t:${nextExamTimestamp}:R>)`,
|
||||||
"Exam Failed"
|
"Exam Failed"
|
||||||
)]
|
)]
|
||||||
});
|
});
|
||||||
@@ -138,8 +141,9 @@ export const exam = createCommand({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 6. Update State
|
// 6. Update State
|
||||||
const nextWeek = new Date(now);
|
const nextExamDate = new Date(now);
|
||||||
nextWeek.setDate(now.getDate() + 7);
|
nextExamDate.setDate(now.getDate() + 7);
|
||||||
|
const nextExamTimestamp = Math.floor(nextExamDate.getTime() / 1000);
|
||||||
|
|
||||||
const newMetadata: ExamMetadata = {
|
const newMetadata: ExamMetadata = {
|
||||||
examDay: examDay,
|
examDay: examDay,
|
||||||
@@ -150,7 +154,7 @@ export const exam = createCommand({
|
|||||||
// Update Timer
|
// Update Timer
|
||||||
await tx.update(userTimers)
|
await tx.update(userTimers)
|
||||||
.set({
|
.set({
|
||||||
expiresAt: nextWeek,
|
expiresAt: nextExamDate,
|
||||||
metadata: newMetadata
|
metadata: newMetadata
|
||||||
})
|
})
|
||||||
.where(and(
|
.where(and(
|
||||||
@@ -174,7 +178,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 on **${DAYS[examDay]}**!`,
|
`See you next week: <t:${nextExamTimestamp}:F>`,
|
||||||
"Exam Passed!"
|
"Exam Passed!"
|
||||||
)]
|
)]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export const pay = createCommand({
|
|||||||
.setColor("Green")
|
.setColor("Green")
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed], content: `<@${receiverId}>` });
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error instanceof UserError) {
|
if (error instanceof UserError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user