Skip to content

Commit

Permalink
check if thest was finished
Browse files Browse the repository at this point in the history
  • Loading branch information
q-Sci committed Oct 14, 2023
1 parent 7e1e35c commit e7dd0fe
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions commands/match/match-command.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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');

Expand Down Expand Up @@ -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!');
}
};

0 comments on commit e7dd0fe

Please sign in to comment.