From 3578b5919086c6c196da3d34eb707d8c0f668968 Mon Sep 17 00:00:00 2001 From: Joehoel <31251240+Joehoel@users.noreply.github.com> Date: Tue, 31 Aug 2021 22:09:22 +0200 Subject: [PATCH] fix: :bug: Fix date on question judge --- src/features/check-answers.ts | 7 ++++--- src/lib/helpers.ts | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/features/check-answers.ts b/src/features/check-answers.ts index df680f3..82fbcf1 100644 --- a/src/features/check-answers.ts +++ b/src/features/check-answers.ts @@ -1,7 +1,7 @@ import { Brain } from "../entity/Brain"; import { CHANNELS, EVENTS, GUILD_ID, SCOREBOARD_MESSAGE_ID } from "@/lib/contants"; import { Client, MessageReaction, PartialUser, TextChannel, User } from "discord.js"; -import { scoreboard } from "../lib/helpers"; +import { getQuestion, scoreboard } from "../lib/helpers"; export default async (client: Client, reaction: MessageReaction, user: User | PartialUser, event: EVENTS) => { if (reaction.message.partial) await reaction.message.fetch(); @@ -12,6 +12,7 @@ export default async (client: Client, reaction: MessageReaction, user: User | Pa const member = client.guilds.cache.get(GUILD_ID)!.members.cache.find((m) => m.user.username == author?.name); const score = await Brain.findOne({ where: { user: member?.toString() } }); + const question = await getQuestion(); const answersChannel = (await client.guilds.cache .get(GUILD_ID) @@ -31,7 +32,7 @@ export default async (client: Client, reaction: MessageReaction, user: User | Pa await answersChannel.send({ content: `<@${member?.user.id}> Je antwoord op de vraag van ${Intl.DateTimeFormat("nl-NL", { dateStyle: "medium", - }).format(new Date())} is goedgekeurd!`, + }).format(question?.date)} is goedgekeurd!`, }); } else { const newScore = new Brain({ score: score!.score - 1 }); @@ -39,7 +40,7 @@ export default async (client: Client, reaction: MessageReaction, user: User | Pa await answersChannel.send({ content: `<@${member?.user.id}> Je antwoord op de vraag van ${Intl.DateTimeFormat("nl-NL", { dateStyle: "medium", - }).format(new Date())} is bij nader inzien afgekeurd!`, + }).format(question?.date)} is bij nader inzien afgekeurd!`, }); } diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index a773b38..36736c2 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -262,10 +262,14 @@ const getDate = () => { }; export const sendQuestion = async (client: Client) => { - const question = await Question.findOne({ where: { date: getDate() } }); + const question = await getQuestion(); const channel = (await client.channels.fetch(CHANNELS.VRAGEN, { cache: true, force: true, })) as TextChannel; return channel.send(`<@&${ROLES.CONTESTANT}> ${question!.text}`); }; + +export const getQuestion = async () => { + return await Question.findOne({ where: { date: getDate() } }); +};