Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Buttons/partnershiprequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 19 additions & 5 deletions Commands/partnership.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
55 changes: 48 additions & 7 deletions Modals/partnershipQuestionsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 5 additions & 2 deletions embeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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')
Expand All @@ -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)
Expand Down
27 changes: 20 additions & 7 deletions utils/askQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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);

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

Expand Down Expand Up @@ -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();
Expand All @@ -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(),
}))
);
Expand Down
4 changes: 4 additions & 0 deletions utils/sendMenuBuilders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down