diff --git a/commands/test/test-command.ts b/commands/test/test-command.ts index d822564..88ea5ae 100644 --- a/commands/test/test-command.ts +++ b/commands/test/test-command.ts @@ -1,4 +1,4 @@ -import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, SlashCommandBuilder, Guild, Role } from 'discord.js'; +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, SlashCommandBuilder, Guild, Role, User } from 'discord.js'; import { client, db } from '../../common'; import cron from 'cron'; @@ -155,13 +155,14 @@ export const sendQuestion = async (interaction: any) => { interaction.user.send(`Dein bester Gesprächspartner ist: **@${bestMatch.username}**.`); interaction.user.send("Als nächstes schreibst du deinem Partner, indem du auf seinen Namen auf dem Contraversum-Server klickst 👆 und ihm eine Nachricht sendest."); interaction.user.send("Dies sind drei Fragen bei denen ihr euch unterscheidet:"); - conversationStarter(interaction, bestMatch.userVector, userResponses); // Send the best match that they have been matched with the user const bestMatchUser = await client.users.fetch(bestMatch.userId); if (bestMatchUser) { bestMatchUser.send(`Hey 👋, du wurdest mit: **@${interaction.user.username}** gematched.`); + bestMatchUser.send("Ihr habt euch bei diesen drei Fragen beispielsweise unterschieden:"); } + conversationStarter(interaction, bestMatch.userVector, userResponses, bestMatchUser) } else { console.warn('No best match found'); @@ -187,7 +188,7 @@ export const sendQuestion = async (interaction: any) => { -async function conversationStarter(interaction: any, bestMatch: number[], user: number[]) { +async function conversationStarter(interaction: any, bestMatch: number[], user: number[], bestMatchUser: User) { // get all contrasting and similar answers let addedToDisagree = false; // Track if any numbers were added to disagree @@ -201,7 +202,7 @@ async function conversationStarter(interaction: any, bestMatch: number[], user: } }); // Only add to disagree if the flag is still false - if (!addedToDisagree) { + if (!addedToDisagree || disagree.length < 6) { user.forEach((value, i) => { const total = value + bestMatch[i]; if (Math.abs(total) === 1) { @@ -210,13 +211,20 @@ async function conversationStarter(interaction: any, bestMatch: number[], user: }); } - // selects 3 random disagreements and prints them - function getRandomDisagreement(arr: number[], num: number) { - return Array.from({ length: Math.min(num, arr.length) }, () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]); + const selectedIndexes = getRandomDisagreement(disagree, 6); + sendDisagreedQuestions(interaction.user, selectedIndexes.slice(0, 3)); + if (bestMatchUser) { + sendDisagreedQuestions(bestMatchUser, selectedIndexes.slice(-3)) } - const selectedIndexes = getRandomDisagreement(disagree, 3) - selectedIndexes.forEach((value) => { - interaction.user.send({ +} + +function getRandomDisagreement(arr: number[], num: number) { + return Array.from({ length: Math.min(num, arr.length) }, () => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]); +} + +function sendDisagreedQuestions(user: User, disagree: number[]) { + disagree.forEach((value) => { + user.send({ embeds: [ new EmbedBuilder() .setTitle(`Frage: ${value + 1}/38`) @@ -227,16 +235,17 @@ async function conversationStarter(interaction: any, bestMatch: number[], user: }); // Make it so that the tags of the questions are printed properly - const selectedTags = selectedIndexes + const selectedTags = disagree .map(index => questions[index].tag) .filter(tag => tag) .slice(0, 3); const topicsMessage = `Als Gesprächsthemen können z.B. ${selectedTags.map(tag => `**${tag}**`).join(", ")} besprochen werden.`; - interaction.user.send(topicsMessage); + user.send(topicsMessage); } + async function findMatchingUser(userId: string, userResponses: number[]): Promise<{ userId: string, username: string, userVector: number[] } | null> { if (!userId || !Array.isArray(userResponses) || userResponses.length === 0) { console.log("Invalid input parameters");