Skip to content

Commit

Permalink
Merge pull request #44 from Joehoel/quiz
Browse files Browse the repository at this point in the history
fix: 🐛 Fix date on question judge
  • Loading branch information
Joehoel authored Aug 31, 2021
2 parents cd51f1c + 3578b59 commit 02d1542
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/features/check-answers.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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)
Expand All @@ -31,15 +32,15 @@ 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 });
await Brain.update({ user: member?.toString() }, newScore);
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!`,
});
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() } });
};

0 comments on commit 02d1542

Please sign in to comment.