Skip to content

Commit

Permalink
Merge pull request #43 from Joehoel/quiz
Browse files Browse the repository at this point in the history
fix: 🐛 Fix `quiz` bugs
  • Loading branch information
Joehoel authored Aug 31, 2021
2 parents a33eaad + e9ad1a7 commit cd51f1c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
31 changes: 17 additions & 14 deletions src/_commands/admin/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
},
});
2 changes: 1 addition & 1 deletion src/entity/Brain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Brain extends BaseEntity {
user: string;

@Index()
@Column({ default: 0 })
@Column({ default: 1 })
score: number;

@CreateDateColumn()
Expand Down
7 changes: 4 additions & 3 deletions src/features/check-answers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() } });

Expand All @@ -28,15 +29,15 @@ 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!`,
});
} else {
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!`,
});
Expand Down

0 comments on commit cd51f1c

Please sign in to comment.