From e9ad1a767d9cab6b1f40ae8c0c4588f0c146fd67 Mon Sep 17 00:00:00 2001 From: Joehoel <31251240+Joehoel@users.noreply.github.com> Date: Tue, 31 Aug 2021 21:30:46 +0200 Subject: [PATCH] fix: :bug: Fix `quiz` bugs --- src/_commands/admin/score.ts | 31 +++++++++++++++++-------------- src/entity/Brain.ts | 2 +- src/features/check-answers.ts | 7 ++++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/_commands/admin/score.ts b/src/_commands/admin/score.ts index b545b98..0e3b7d9 100644 --- a/src/_commands/admin/score.ts +++ b/src/_commands/admin/score.ts @@ -42,21 +42,24 @@ export default new SlashCommand({ if (brain) { await Brain.update({ user: brain.user }, { score: value }); - // TODO: Functie van maken - // Update scoreboard - const scoreboardChannel = (await client.guilds.cache - .get(GUILD_ID) - ?.channels.cache.get(CHANNELS.REGELS_EN_LEADERBOARD) - ?.fetch()) as TextChannel; + interaction.reply({ content: `Successfully updated score to: ${value}` }); + } else { + await new Brain({ score: value, user: user.toString() }).save(); + interaction.reply({ content: `Successfully created new score for ${user}: ${value}` }); + } - const messages = await scoreboardChannel.messages.fetch({ - around: SCOREBOARD_MESSAGE_ID, - limit: 1, - }); - const message = messages.first(); - await message?.edit({ content: await scoreboard() }); + // TODO: Functie van maken + // Update scoreboard + const scoreboardChannel = (await client.guilds.cache + .get(GUILD_ID) + ?.channels.cache.get(CHANNELS.REGELS_EN_LEADERBOARD) + ?.fetch()) as TextChannel; - return interaction.reply({ content: `Successfully updated score to: ${value}` }); - } + const messages = await scoreboardChannel.messages.fetch({ + around: SCOREBOARD_MESSAGE_ID, + limit: 1, + }); + const message = messages.first(); + await message?.edit({ content: await scoreboard() }); }, }); diff --git a/src/entity/Brain.ts b/src/entity/Brain.ts index 3b94c9c..f2cabbb 100644 --- a/src/entity/Brain.ts +++ b/src/entity/Brain.ts @@ -10,7 +10,7 @@ export class Brain extends BaseEntity { user: string; @Index() - @Column({ default: 0 }) + @Column({ default: 1 }) score: number; @CreateDateColumn() diff --git a/src/features/check-answers.ts b/src/features/check-answers.ts index 48587fa..df680f3 100644 --- a/src/features/check-answers.ts +++ b/src/features/check-answers.ts @@ -8,7 +8,8 @@ export default async (client: Client, reaction: MessageReaction, user: User | Pa if (reaction.partial) await reaction.fetch(); if (user.bot || reaction.message.channel.type != "DM") return; - const member = client.guilds.cache.get(GUILD_ID)!.members.cache.get(user.id); + const author = reaction.message.embeds[0].author; + 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() } }); @@ -28,7 +29,7 @@ export default async (client: Client, reaction: MessageReaction, user: User | Pa } await answersChannel.send({ - content: `${member} Je antwoord op de vraag van ${Intl.DateTimeFormat("nl-NL", { + content: `<@${member?.user.id}> Je antwoord op de vraag van ${Intl.DateTimeFormat("nl-NL", { dateStyle: "medium", }).format(new Date())} is goedgekeurd!`, }); @@ -36,7 +37,7 @@ export default async (client: Client, reaction: MessageReaction, user: User | Pa const newScore = new Brain({ score: score!.score - 1 }); await Brain.update({ user: member?.toString() }, newScore); await answersChannel.send({ - content: `${member} Je antwoord op de vraag van ${Intl.DateTimeFormat("nl-NL", { + content: `<@${member?.user.id}> Je antwoord op de vraag van ${Intl.DateTimeFormat("nl-NL", { dateStyle: "medium", }).format(new Date())} is bij nader inzien afgekeurd!`, });