From 25ba9ec33519eb37a8fa5c0acad20272d57b97fc Mon Sep 17 00:00:00 2001 From: Kezza2k7 Date: Thu, 11 Jul 2024 21:38:50 +0100 Subject: [PATCH 1/4] Added Types --- Buttons/partnershiprequest.js | 16 ++++++--- Modals/partnershipQuestionsModal.js | 55 +++++++++++++++++++++++++---- embeds.js | 7 ++-- utils/askQuestion.js | 47 ++++++++++++++++++++---- utils/sendMenuBuilders.js | 4 +++ 5 files changed, 109 insertions(+), 20 deletions(-) diff --git a/Buttons/partnershiprequest.js b/Buttons/partnershiprequest.js index f62cb38..3b837f5 100644 --- a/Buttons/partnershiprequest.js +++ b/Buttons/partnershiprequest.js @@ -106,10 +106,18 @@ async function createAndShowModal(interaction, questions) { // For each question, create a text input and add it to the modal questions.forEach((question, index) => { - const textInput = new TextInputBuilder() - .setCustomId(`question${index}`) - .setLabel(question) - .setStyle(TextInputStyle.Short); // Use TextInputStyle.Paragraph for longer inputs + let textInput; + if(question[1] === 'long'){ + textInput = new TextInputBuilder() + .setCustomId(`question${index}`) + .setLabel(question[0]) + .setStyle(TextInputStyle.Paragraph) + } else { + textInput = new TextInputBuilder() + .setCustomId(`question${index}`) + .setLabel(question[0]) + .setStyle(TextInputStyle.Short); + } const actionRow = new ActionRowBuilder().addComponents(textInput); diff --git a/Modals/partnershipQuestionsModal.js b/Modals/partnershipQuestionsModal.js index 732c1e0..bb1a7d0 100644 --- a/Modals/partnershipQuestionsModal.js +++ b/Modals/partnershipQuestionsModal.js @@ -16,7 +16,7 @@ module.exports = { let index = 0; for (const question of JSON.parse(server.server.PartnerShipQuestions)) { const answer = await interaction.fields.getTextInputValue(`question${index}`); - questionsAnswers.push({ "question": question, "answer": answer }); + questionsAnswers.push({ "question": question[0], "answer": answer }); index++; } @@ -25,13 +25,54 @@ module.exports = { return; } - const description = interaction.message.embeds[0].data.description; - - // Split the description at ": " - const parts = description.split(": "); let role = null; - if(parts[parts.length - 1].startsWith("<@")) { - role = parts[parts.length - 1]; + let memberRequirement = 0; + + if(interaction.message.embeds[0].data.fields.length !== 0) { + const parts = interaction.message.embeds[0].data.fields[0].value.split("\n"); + + parts.forEach(part => { + if (part.includes("**MINIMUM MEMBERS**:")) { + // Extracting memberRequirement directly + let tempRequirement = part.split("**MINIMUM MEMBERS**:")[1].trim(); + if(tempRequirement) { + const matches = tempRequirement.match(/\d+/); + if (matches) { + memberRequirement = matches[0]; // This will be '100' if the string is '100+ Members' + } + } + } else if (part.includes("**PARTNERSHIP HANDLER**:")) { + // Extracting roleMention directly + let tempRoleMention = part.split("**PARTNERSHIP HANDLER**:")[1].trim(); + if(tempRoleMention.startsWith("<@")) { + role = tempRoleMention; + } + } + }); + + let memberQuestion = false; + let memberQuestionID = 0 + for ( const question of JSON.parse(server.server.PartnerShipQuestions)) { + if (question[1] == 'member') { + memberQuestion = memberQuestionID + break; + } + memberQuestionID++; + } + + + if (memberQuestion !== false) { + // Use a regular expression to find numbers in the string + const matches = questionsAnswers[memberQuestion].answer.match(/\d+/); + // Check if there was at least one match + if (matches) { + const number = parseInt(matches[0], 10); // Convert the first match to a number + if (number < memberRequirement) { + await interaction.reply({embeds: [embedPartnership.NotEnoughMembers], ephemeral: true}); + return; + } + } + } } const thread = await interaction.channel.threads.create({ diff --git a/embeds.js b/embeds.js index 9422e03..615a0ac 100644 --- a/embeds.js +++ b/embeds.js @@ -360,7 +360,7 @@ const embedPartnership = { .setDescription(`This Partnership Request has already been accepted.\n\u200B`) .setFooter(footerPartnership), addRemoveQuestions: async function addRemoveQuestions(questions){ - questions = questions.map((question, index) => `**${index+1}**: ${question}`).join('\n'); + questions = questions.map((question, index) => `**${index+1}**: ${question[0]} (${question[1]})`).join('\n'); const embed = new EmbedBuilder() .setTitle('Question') @@ -369,7 +369,7 @@ const embedPartnership = { return embed; }, removeEmbed: async function removeEmbed(questions){ - questions = questions.map((question, index) => `**${index+1}**: ${question}`).join('\n'); + questions = questions.map((question, index) => `**${index+1}**: ${question[0]} (${question[1]})`).join('\n'); const embed = new EmbedBuilder() .setTitle('Question') @@ -377,6 +377,9 @@ const embedPartnership = { return embed; }, + NotEnoughMembers: new EmbedBuilder(embedInfo.Error) + .setTitle(`${iconError} NOT ENOUGH MEMBERS`) + .setDescription(`Your community does not meet the minimum member requirements to request a partnership. \n\nPlease make sure you have the required amount of members to request a partnership.\n\u200B`), // ERRORS ErrorServer: new EmbedBuilder(embedInfo.Error) diff --git a/utils/askQuestion.js b/utils/askQuestion.js index 1aa3d35..0fc491e 100644 --- a/utils/askQuestion.js +++ b/utils/askQuestion.js @@ -10,7 +10,7 @@ const { messageButtonTimeout } = require('../embeds.js') */ -async function askQuestion(interaction, question, inputs = [], limit, addRemoveEmbed, removeEmbeds, skip = false) { +async function askQuestion(interaction, question, inputs = [], limit, addRemoveEmbed, removeEmbeds, skip = false, type) { return new Promise(async (resolve, reject) => { try{ if(skip){ @@ -46,7 +46,7 @@ async function askQuestion(interaction, question, inputs = [], limit, addRemoveE // Get the user's input from the modal const userInput = modalInteraction.fields.getTextInputValue('textInputCustomId'); - inputs.push(userInput); + inputs.push([userInput, type]); await selectMenu(modalInteraction, inputs, limit, question, removeEmbeds, addRemoveEmbed, resolve, reject); @@ -68,9 +68,32 @@ async function selectMenu(interaction, inputs, limit, question, removeEmbeds, ad if(!(limit && inputs.length >= limit)){ options.push( { - label: `${inputs.length > 0 ? 'Add more' : 'Add'}`, + label: `${inputs.length > 0 ? 'Add more Short' : 'Add Short'}`, description: 'Select to add more information', - value: 'add_more', + value: 'add_more_short', + }, + { + label: `${inputs.length > 0 ? 'Add more Long' : 'Add Long'}`, + description: 'Select to add more information', + value: 'add_more_long', + } + ) + } + + test = false; + for (const input of inputs) { + if(input[1] === 'member'){ + test = true; + break; + } + } + + if(!test){ + options.push( + { + label: 'Add Member', + description: 'Select to add a member', + value: 'add_member', } ) } @@ -124,11 +147,21 @@ async function selectMenu(interaction, inputs, limit, question, removeEmbeds, ad async function selectInteractione(collecter, interaction, removeEmbeds, addRemoveEmbed, inputs, limit, question, resolve){ + console.log(interaction.values[0]) switch (interaction.values[0]) { - case 'add_more': + case 'add_more_short': + // If the user wants to add more, call askQuestion again + collecter.stop(); + resolve(await askQuestion(interaction, question, inputs, limit, addRemoveEmbed, removeEmbeds, false, 'short')); + break; + case 'add_more_long': // If the user wants to add more, call askQuestion again collecter.stop(); - resolve(await askQuestion(interaction, question, inputs, limit, addRemoveEmbed, removeEmbeds)); + resolve(await askQuestion(interaction, question, inputs, limit, addRemoveEmbed, removeEmbeds, false, 'long')); + break; + case 'add_member': + collecter.stop(); + resolve(await askQuestion(interaction, question, inputs, limit, addRemoveEmbed, removeEmbeds, false, 'member')); break; case 'remove': collecter.stop(); @@ -137,7 +170,7 @@ async function selectInteractione(collecter, interaction, removeEmbeds, addRemov .setPlaceholder('Choose an option') .addOptions( inputs.map((input, index) => ({ - label: input, + label: `${input[0]} (${input[1]})`, value: index.toString(), })) ); diff --git a/utils/sendMenuBuilders.js b/utils/sendMenuBuilders.js index 6f52ee9..ce426fe 100644 --- a/utils/sendMenuBuilders.js +++ b/utils/sendMenuBuilders.js @@ -54,6 +54,10 @@ async function sendMenuBuilders(interaction, component, requiremnet, embed, opti selectedChannel = i.values; await i.update({ components: [row1, row2] }); } else { + if(!i.values){ + reject('Mega Error'); + return; + } selectedChannel = i.values[0] const updatedMemberRequirementOptions = options.map(option => option.data.value === i.values[0] From 0504e6a8d4641a21a8b8bbe20a51a4148384b49c Mon Sep 17 00:00:00 2001 From: Kezza2k7 Date: Fri, 12 Jul 2024 10:11:06 +0100 Subject: [PATCH 2/4] PartnerShip Disable Bug Fixed --- Commands/partnership.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Commands/partnership.js b/Commands/partnership.js index 21c27df..fa5630d 100644 --- a/Commands/partnership.js +++ b/Commands/partnership.js @@ -143,7 +143,7 @@ async function ChangePartnership(status, interaction, old, reply) { PartnerShip: status, }; - await utils.updateServer(data, interaction) + await updateServer(data, interaction) if(reply){ await interaction.update({ From 212685ff1f3f0e7b99fd9561394429b6f32c18b7 Mon Sep 17 00:00:00 2001 From: Kezza2k7 Date: Fri, 12 Jul 2024 16:54:09 +0100 Subject: [PATCH 3/4] Fixed Timout issue --- utils/askQuestion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/askQuestion.js b/utils/askQuestion.js index 0fc491e..cfda631 100644 --- a/utils/askQuestion.js +++ b/utils/askQuestion.js @@ -190,7 +190,7 @@ async function selectInteractione(collecter, interaction, removeEmbeds, addRemov const removeFilter = (i) => i.customId === 'removeSelectMenuCustomId' || i.customId === 'xback'; - const removeCollector = interaction.channel.createMessageComponentCollector({ filter: removeFilter, time: 15000 }); + const removeCollector = interaction.channel.createMessageComponentCollector({ filter: removeFilter, time: 60_000 }); removeCollector.on('collect', async (removeInteraction) => { if(removeInteraction.customId === 'xback'){ From 7bb73a287f6655707afd9dbe792ff52b80e3a5a0 Mon Sep 17 00:00:00 2001 From: Jay - Oreo Date: Thu, 25 Jul 2024 19:07:14 +0100 Subject: [PATCH 4/4] Cool Test --- Commands/partnership.js | 24 +++++++++++++++++++----- utils/askQuestion.js | 30 +++++------------------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Commands/partnership.js b/Commands/partnership.js index fa5630d..accf671 100644 --- a/Commands/partnership.js +++ b/Commands/partnership.js @@ -383,10 +383,24 @@ async function SendEmbededMessage(interaction, channelid, roleMention, memberReq let embed = await embedPartnership.PartnershipRequester(channelid, enable, memberRequirement, roleMention, questions) - await interaction.update({ - embeds: [embed], - ephemeral: true, - components: [], - }); + try { + await interaction.update({ + embeds: [embed], + ephemeral: true, + components: [], + }); + } catch (error) { + try { + await interaction.reply({ + embeds: [embed], + ephemeral: true, + components: [], + }); + + } catch (error) { + console.log(error) + } + } + return; } \ No newline at end of file diff --git a/utils/askQuestion.js b/utils/askQuestion.js index cfda631..ebd850f 100644 --- a/utils/askQuestion.js +++ b/utils/askQuestion.js @@ -46,6 +46,10 @@ async function askQuestion(interaction, question, inputs = [], limit, addRemoveE // Get the user's input from the modal const userInput = modalInteraction.fields.getTextInputValue('textInputCustomId'); + if(userInput.toLowerCase().includes('member') || userInput.toLowerCase().includes('members')){ + type = 'member'; + } + inputs.push([userInput, type]); await selectMenu(modalInteraction, inputs, limit, question, removeEmbeds, addRemoveEmbed, resolve, reject); @@ -68,33 +72,10 @@ async function selectMenu(interaction, inputs, limit, question, removeEmbeds, ad if(!(limit && inputs.length >= limit)){ options.push( { - label: `${inputs.length > 0 ? 'Add more Short' : 'Add Short'}`, + label: `${inputs.length > 0 ? 'Add more' : 'Add'}`, description: 'Select to add more information', value: 'add_more_short', }, - { - label: `${inputs.length > 0 ? 'Add more Long' : 'Add Long'}`, - description: 'Select to add more information', - value: 'add_more_long', - } - ) - } - - test = false; - for (const input of inputs) { - if(input[1] === 'member'){ - test = true; - break; - } - } - - if(!test){ - options.push( - { - label: 'Add Member', - description: 'Select to add a member', - value: 'add_member', - } ) } @@ -147,7 +128,6 @@ async function selectMenu(interaction, inputs, limit, question, removeEmbeds, ad async function selectInteractione(collecter, interaction, removeEmbeds, addRemoveEmbed, inputs, limit, question, resolve){ - console.log(interaction.values[0]) switch (interaction.values[0]) { case 'add_more_short': // If the user wants to add more, call askQuestion again