Updating application system

This commit is contained in:
2023-03-16 15:14:11 +01:00
parent d2ecbd2f9c
commit b60b5a63dd
3 changed files with 173 additions and 45 deletions

View File

@@ -1,7 +1,10 @@
const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder } = require('discord.js'); const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder } = require('discord.js');
const { color } = require('../../config/options.json'); 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 { 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 path = require('path');
const fetch = require('axios'); const fetch = require('axios');
const fs = require('fs'); const fs = require('fs');
@@ -21,7 +24,7 @@ module.exports = {
const userRoles = guild.members.cache.get(user.id).roles.cache.map(role => role.id); 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 }); await interaction.reply({ content: "You are already a member of the guild.", ephemeral: true });
return return
} }
@@ -85,8 +88,8 @@ module.exports = {
// first question // first question
const question1 = await user.send({ const question1 = await user.send({
embeds: [{ embeds: [{
title : "**1. " + qu1 + "**", title : "**Question 1**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu1 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + ignM + "`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 5 minutes to respond to this message." text: "You have 5 minutes to respond to this message."
@@ -102,6 +105,28 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return 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) { if (answer1.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -115,8 +140,8 @@ module.exports = {
// second question // second question
const question2 = await user.send({ const question2 = await user.send({
embeds: [{ embeds: [{
title : "**2. " + qu2 + "**", title : "**Question 2**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu2 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n" + "`(8 characters max)`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -132,6 +157,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer2.first().content > 8) {
await user.send({
embeds: [{
description: "Max character limit is 8.",
color: embedColor
}]
})
}
if (answer2.size === 0) { if (answer2.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -145,8 +178,8 @@ module.exports = {
// third question // third question
const question3 = await user.send({ const question3 = await user.send({
embeds: [{ embeds: [{
title : "**3. " + qu3 + "**", title : "**Question 3**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu3 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + smallM + "`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -162,6 +195,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer3.first().content > 128) {
await user.send({
embeds: [{
description: "Max character limit is 128.",
color: embedColor
}]
})
}
if (answer3.size === 0) { if (answer3.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -175,8 +216,9 @@ module.exports = {
// fourth question // fourth question
const question4 = await user.send({ const question4 = await user.send({
embeds: [{ embeds: [{
title : "**4. " + qu4 + "**", title : "**Question 4**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu4 + "\n\nPlease type your answer below or type `cancel` to cancel your application." +
" `(We expect a longer answer.)`\n`" + largeM + "`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -192,6 +234,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer4.first().content > 256) {
await user.send({
embeds: [{
description: "Max character limit is 256.",
color: embedColor
}]
})
}
if (answer4.size === 0) { if (answer4.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -205,8 +255,8 @@ module.exports = {
// fifth question // fifth question
const question5 = await user.send({ const question5 = await user.send({
embeds: [{ embeds: [{
title : "**5. " + qu5 + "**", title : "**Question 5**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu5 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + smallM + "`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -222,6 +272,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer5.first().content > 128) {
await user.send({
embeds: [{
description: "Max character limit is 128.",
color: embedColor
}]
})
}
if (answer5.size === 0) { if (answer5.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -235,8 +293,8 @@ module.exports = {
// sixth question // sixth question
const question6 = await user.send({ const question6 = await user.send({
embeds: [{ embeds: [{
title : "**6. " + qu6 + "**", title : "**Question 6**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu6 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + largeM + "`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -252,6 +310,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer6.first().content > 256) {
await user.send({
embeds: [{
description: "Max character limit is 256.",
color: embedColor
}]
})
}
if (answer6.size === 0) { if (answer6.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -265,8 +331,8 @@ module.exports = {
// seventh question // seventh question
const question7 = await user.send({ const question7 = await user.send({
embeds: [{ embeds: [{
title : "**7. " + qu7 + "**", title : "**Question 7**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu7 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n`" + smallM + "`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -282,6 +348,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer7.first().content > 128) {
await user.send({
embeds: [{
description: "Max character limit is 128.",
color: embedColor
}]
})
}
if (answer7.size === 0) { if (answer7.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -295,8 +369,8 @@ module.exports = {
// eighth question // eighth question
const question8 = await user.send({ const question8 = await user.send({
embeds: [{ embeds: [{
title : "**8. " + qu8 + "**", title : "**Question 8**",
description: "Please type your answer below or type `cancel` to cancel your application.", description: qu8 + "\n\nPlease type your answer below or type `cancel` to cancel your application.\n" + "`(64 characters max)`",
color: embedColor, color: embedColor,
footer:{ footer:{
text: "You have 15 minutes to respond to this message." text: "You have 15 minutes to respond to this message."
@@ -312,6 +386,14 @@ module.exports = {
await user.send({ embeds: [attachments] }); await user.send({ embeds: [attachments] });
return return
} }
if (answer8.first().content > 64) {
await user.send({
embeds: [{
description: "Max character limit is 64.",
color: embedColor
}]
})
}
if (answer8.size === 0) { if (answer8.size === 0) {
await user.send({ embeds: [tooLong] }) await user.send({ embeds: [tooLong] })
return return
@@ -384,36 +466,36 @@ module.exports = {
}, },
fields: [ fields: [
{ {
name: qu1, name: rq1,
value: answer1_1 value: "```" + answer1_1 + "```"
}, },
{ {
name: qu2, name: rq2,
value: answer2_1 value: "```" + answer2_1 + "```"
}, },
{ {
name: qu3, name: rq3,
value: answer3_1 value: "```" + answer3_1 + "```"
}, },
{ {
name: qu4, name: rq4,
value: answer4_1 value: "```" + answer4_1 + "```"
}, },
{ {
name: qu5, name: rq5,
value: answer5_1 value: "```" + answer5_1 + "```"
}, },
{ {
name: qu6, name: rq6,
value: answer6_1 value: "```" + answer6_1 + "```"
}, },
{ {
name: qu7, name: rq7,
value: answer7_1 value: "```" + answer7_1 + "```"
}, },
{ {
name: qu8, name: rq8,
value: answer8_1 value: "```" + answer8_1 + "```"
} }
], ],

View File

@@ -1,6 +1,7 @@
const { ModalBuilder, ActionRowBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const { color } = require('../../config/options.json');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const { color } = require('../../config/options.json');
module.exports = { module.exports = {
name: 'guildapplicationdeny', name: 'guildapplicationdeny',
@@ -16,16 +17,18 @@ module.exports = {
const applicantId = await channel.topic const applicantId = await channel.topic
const applicant = await guild.members.fetch(applicantId) const applicant = await guild.members.fetch(applicantId)
await applicant.send({ const modal = new ModalBuilder()
embeds: [{ .setTitle('Deny Reason')
description: `Your application for the Illegitimate guild has been denied.`, .setCustomId('denyreasonbox')
color: embedColor .setComponents(
}] new ActionRowBuilder().setComponents(
}); new TextInputBuilder()
.setLabel('Deny Reason')
const filePath = path.join(__dirname, `../../applications/${applicantId}`); .setCustomId('denyreason')
fs.rmSync(filePath, { force: true }); .setStyle(TextInputStyle.Paragraph)
)
)
await channel.delete(); await interaction.showModal(modal);
} }
}; };

View File

@@ -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);
}
}