Skip to content

Commit

Permalink
Merge pull request #50 from Contraversum/both-matches-get-questions
Browse files Browse the repository at this point in the history
both matches get questions
  • Loading branch information
johan-t committed Sep 23, 2023
2 parents 37029cf + 58e78fb commit 4bca2ec
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions commands/test/test-command.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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`)
Expand All @@ -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");
Expand Down

0 comments on commit 4bca2ec

Please sign in to comment.