From e7dd0feeac6e5c5d6267423e5220d59358ec885c Mon Sep 17 00:00:00 2001 From: q-Sci Date: Sat, 14 Oct 2023 22:15:45 +0200 Subject: [PATCH] check if thest was finished --- commands/match/match-command.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/commands/match/match-command.ts b/commands/match/match-command.ts index 190ae56..7ca4b74 100644 --- a/commands/match/match-command.ts +++ b/commands/match/match-command.ts @@ -1,6 +1,7 @@ import { SlashCommandBuilder, Guild } from 'discord.js'; import { client, db } from '../../common'; import 'dotenv/config'; +import questions from '../../questions'; import findMatchingUser from '../../functions/findMatchingUser'; import conversationStarter from '../../functions/conversationStarter'; @@ -10,10 +11,9 @@ export const sendQuestion = async (interaction: any) => { let userResponses = userContext?.userVector || []; + // Test discussion topics // TODO: check if user has completed the test - console.log(userContext); - const guildId = process.env.GUILD_ID; if (!guildId) throw new Error('GUILD_ID not found'); @@ -77,9 +77,23 @@ export const sendQuestion = async (interaction: any) => { export const data = new SlashCommandBuilder().setName('match').setDescription('Requests new match without retaking the test.'); export const execute = async (interaction: any) => { - await interaction.reply({ - content: 'Neues Match wird ermittelt. Bitte schaue in deinen Direktnachrichten nach :)', - ephemeral: true, - }); - sendQuestion(interaction); + const userContext = await db.db('contrabot').collection("users").findOne({ userId: interaction.user.id }); + + let userResponses = userContext?.userVector || []; + + // checks if the user has answered the test + // if not, an error hint is displayed + if (userResponses.length === questions.length) { + await interaction.reply({ + content: 'Neues Match wird ermittelt. Bitte schaue in deinen Direktnachrichten nach :)', + ephemeral: true, + }); + sendQuestion(interaction); + } else { + await interaction.reply({ + content: 'Bitte beantworte den Meinungstest vollständig, bevor du mit Anderen gematcht werden kannst! Bitte nutze dazu den Befehl `/test`.', + ephemeral: true, + }); + console.log('Invalid userVector: test was not completed!'); + } };