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/Commands/partnership.js b/Commands/partnership.js index 5b3ff51..7626310 100644 --- a/Commands/partnership.js +++ b/Commands/partnership.js @@ -378,10 +378,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/Modals/partnershipQuestionsModal.js b/Modals/partnershipQuestionsModal.js index 432ed81..eb22110 100644 --- a/Modals/partnershipQuestionsModal.js +++ b/Modals/partnershipQuestionsModal.js @@ -21,19 +21,60 @@ 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++; } - 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 83ec483..22e5243 100644 --- a/embeds.js +++ b/embeds.js @@ -370,7 +370,7 @@ const embedPartnership = { .setDescription(`This Partnership Request has already been accepted.\n\u200B`) .setFooter(footerPartnership), CustomQuestions: async function CustomQuestions(questions){ - questions = questions.map((question) => `\`•\` ${question}`).join('\n'); + questions = questions.map((question, index) => `**${index+1}**: ${question[0]} (${question[1]})`).join('\n'); let newLine = ''; if (questions && questions.length > 0) { @@ -387,7 +387,7 @@ const embedPartnership = { return embed; }, removeEmbed: async function removeEmbed(questions){ - questions = questions.map((question) => `\`•\` ${question}`).join('\n'); + questions = questions.map((question, index) => `**${index+1}**: ${question[0]} (${question[1]})`).join('\n'); const embed = new EmbedBuilder(embedInfo.Info) .setTitle('CUSTOM QUESTIONS') @@ -396,6 +396,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 14cfb8f..e65418a 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,11 @@ 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); + 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); @@ -70,8 +74,8 @@ async function selectMenu(interaction, inputs, limit, question, removeEmbeds, ad { label: `${inputs.length > 0 ? 'Add more' : 'Add'}`, description: 'Select to add more information', - value: 'add_more', - } + value: 'add_more_short', + }, ) } @@ -136,10 +140,19 @@ async function selectInteractione(collecter, interaction, removeEmbeds, addRemov return; } 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(); @@ -148,7 +161,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 7288277..67dd21a 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]