From b60b5a63ddc1a09f93265562f6dea902fbf7cf24 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 16 Mar 2023 15:14:11 +0100 Subject: [PATCH] Updating application system --- events/buttons/guilapply.js | 150 +++++++++++++++++++------ events/buttons/guildapplicationdeny.js | 25 +++-- events/modals/denyreasonbox.js | 43 +++++++ 3 files changed, 173 insertions(+), 45 deletions(-) create mode 100644 events/modals/denyreasonbox.js diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js index c12d288..7b82404 100644 --- a/events/buttons/guilapply.js +++ b/events/buttons/guilapply.js @@ -1,7 +1,10 @@ const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder } = require('discord.js'); const { color } = require('../../config/options.json'); +const { largeM, smallM, ignM } = require('../../config/limitmessages.json') +const { applicationsCategory } = require('../../config/options.json'); const { qu1, qu2, qu3, qu4, qu5, qu6, qu7, qu8 } = require('../../config/questions.json'); -const { gm, manager, moderator, beast, member, trialmember } = require('../../config/roles.json') +const { rq1, rq2, rq3, rq4, rq5, rq6, rq7, rq8 } = require('../../config/questions.json'); +const { guildRole } = require('../../config/roles.json') const path = require('path'); const fetch = require('axios'); const fs = require('fs'); @@ -21,7 +24,7 @@ module.exports = { const userRoles = guild.members.cache.get(user.id).roles.cache.map(role => role.id); - if (userRoles.includes ( gm || manager || moderator || beast || member || trialmember )) { + if (userRoles.includes(guildRole)) { await interaction.reply({ content: "You are already a member of the guild.", ephemeral: true }); return } @@ -85,8 +88,8 @@ module.exports = { // first question const question1 = await user.send({ embeds: [{ - title : "**1. " + qu1 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 1**", + description: qu1 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + ignM + "`", color: embedColor, footer:{ text: "You have 5 minutes to respond to this message." @@ -102,6 +105,28 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer1.first().content > 16) { + await user.send({ + embeds: [{ + description: "That is not a valid Minecraft username.\n" + + "Application cancelled.", + color: embedColor + }] + }) + return + } + try { + await fetch(mojangAPI + answer1.first().content) + } catch (error) { + await user.send({ + embeds: [{ + description: "That is not a valid Minecraft username.\n" + + "Application cancelled.", + color: embedColor + }] + }) + return + } if (answer1.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -115,8 +140,8 @@ module.exports = { // second question const question2 = await user.send({ embeds: [{ - title : "**2. " + qu2 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 2**", + description: qu2 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n" + "`(8 characters max)`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -132,6 +157,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer2.first().content > 8) { + await user.send({ + embeds: [{ + description: "Max character limit is 8.", + color: embedColor + }] + }) + } if (answer2.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -145,8 +178,8 @@ module.exports = { // third question const question3 = await user.send({ embeds: [{ - title : "**3. " + qu3 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 3**", + description: qu3 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + smallM + "`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -162,6 +195,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer3.first().content > 128) { + await user.send({ + embeds: [{ + description: "Max character limit is 128.", + color: embedColor + }] + }) + } if (answer3.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -175,8 +216,9 @@ module.exports = { // fourth question const question4 = await user.send({ embeds: [{ - title : "**4. " + qu4 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 4**", + description: qu4 + "\n\nPlease type your answer below or type `cancel` to cancel your application." + + " `(We expect a longer answer.)`\n`" + largeM + "`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -192,6 +234,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer4.first().content > 256) { + await user.send({ + embeds: [{ + description: "Max character limit is 256.", + color: embedColor + }] + }) + } if (answer4.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -205,8 +255,8 @@ module.exports = { // fifth question const question5 = await user.send({ embeds: [{ - title : "**5. " + qu5 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 5**", + description: qu5 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + smallM + "`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -222,6 +272,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer5.first().content > 128) { + await user.send({ + embeds: [{ + description: "Max character limit is 128.", + color: embedColor + }] + }) + } if (answer5.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -235,8 +293,8 @@ module.exports = { // sixth question const question6 = await user.send({ embeds: [{ - title : "**6. " + qu6 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 6**", + description: qu6 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + largeM + "`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -252,6 +310,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer6.first().content > 256) { + await user.send({ + embeds: [{ + description: "Max character limit is 256.", + color: embedColor + }] + }) + } if (answer6.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -265,8 +331,8 @@ module.exports = { // seventh question const question7 = await user.send({ embeds: [{ - title : "**7. " + qu7 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 7**", + description: qu7 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + smallM + "`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -282,6 +348,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer7.first().content > 128) { + await user.send({ + embeds: [{ + description: "Max character limit is 128.", + color: embedColor + }] + }) + } if (answer7.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -295,8 +369,8 @@ module.exports = { // eighth question const question8 = await user.send({ embeds: [{ - title : "**8. " + qu8 + "**", - description: "Please type your answer below or type `cancel` to cancel your application.", + title : "**Question 8**", + description: qu8 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n" + "`(64 characters max)`", color: embedColor, footer:{ text: "You have 15 minutes to respond to this message." @@ -312,6 +386,14 @@ module.exports = { await user.send({ embeds: [attachments] }); return } + if (answer8.first().content > 64) { + await user.send({ + embeds: [{ + description: "Max character limit is 64.", + color: embedColor + }] + }) + } if (answer8.size === 0) { await user.send({ embeds: [tooLong] }) return @@ -384,36 +466,36 @@ module.exports = { }, fields: [ { - name: qu1, - value: answer1_1 + name: rq1, + value: "```" + answer1_1 + "```" }, { - name: qu2, - value: answer2_1 + name: rq2, + value: "```" + answer2_1 + "```" }, { - name: qu3, - value: answer3_1 + name: rq3, + value: "```" + answer3_1 + "```" }, { - name: qu4, - value: answer4_1 + name: rq4, + value: "```" + answer4_1 + "```" }, { - name: qu5, - value: answer5_1 + name: rq5, + value: "```" + answer5_1 + "```" }, { - name: qu6, - value: answer6_1 + name: rq6, + value: "```" + answer6_1 + "```" }, { - name: qu7, - value: answer7_1 + name: rq7, + value: "```" + answer7_1 + "```" }, { - name: qu8, - value: answer8_1 + name: rq8, + value: "```" + answer8_1 + "```" } ], diff --git a/events/buttons/guildapplicationdeny.js b/events/buttons/guildapplicationdeny.js index 2b3e852..6e1d331 100644 --- a/events/buttons/guildapplicationdeny.js +++ b/events/buttons/guildapplicationdeny.js @@ -1,6 +1,7 @@ +const { ModalBuilder, ActionRowBuilder, TextInputBuilder, TextInputStyle } = require('discord.js'); +const { color } = require('../../config/options.json'); const fs = require('fs'); const path = require('path'); -const { color } = require('../../config/options.json'); module.exports = { name: 'guildapplicationdeny', @@ -16,16 +17,18 @@ module.exports = { const applicantId = await channel.topic const applicant = await guild.members.fetch(applicantId) - await applicant.send({ - embeds: [{ - description: `Your application for the Illegitimate guild has been denied.`, - color: embedColor - }] - }); - - const filePath = path.join(__dirname, `../../applications/${applicantId}`); - fs.rmSync(filePath, { force: true }); + const modal = new ModalBuilder() + .setTitle('Deny Reason') + .setCustomId('denyreasonbox') + .setComponents( + new ActionRowBuilder().setComponents( + new TextInputBuilder() + .setLabel('Deny Reason') + .setCustomId('denyreason') + .setStyle(TextInputStyle.Paragraph) + ) + ) - await channel.delete(); + await interaction.showModal(modal); } }; \ No newline at end of file diff --git a/events/modals/denyreasonbox.js b/events/modals/denyreasonbox.js new file mode 100644 index 0000000..01321a7 --- /dev/null +++ b/events/modals/denyreasonbox.js @@ -0,0 +1,43 @@ +const { InteractionType, EmbedBuilder } = require('discord.js'); +const { color } = require('../../config/options.json'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'denyreasonbox', + description: 'Deny reason box.', + type: 'modal', + + async execute(interaction) { + + if (interaction.type !== InteractionType.ModalSubmit) return; + if (interaction.customId !== "denyreasonbox") return; + + const channel = interaction.channel; + const applicantId = channel.topic; + const guild = interaction.guild; + const applicant = await guild.members.fetch(applicantId); + const reason = interaction.fields.fields.get('denyreason').value; + const embedColor = Number(color.replace("#", "0x")); + const filePath = path.join(__dirname, `../../applications/${applicantId}`); + + const dmMessage = new EmbedBuilder() + .setDescription("Your application for the Illegitimate guild has been denied\n" + + "**Reason:** `" + reason + "`") + .setColor(embedColor); + + await applicant.send({ embeds: [dmMessage] }); + + await interaction.reply({ + embeds: [{ + description: "Application denied\n" + + "Channel will be deleted in 5 seconds...", + }], + }); + + setTimeout(() => { + fs.rmSync(filePath, { force: true }); + channel.delete(); + }, 5000); + } +} \ No newline at end of file