From fc974dbf08c9131733628bfcf44a3aedcef32b97 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 19 Mar 2023 22:11:53 +0100 Subject: [PATCH] Updating applicaitons --- .gitignore | 2 +- events/buttons/applicationdelete.js | 28 ----- events/buttons/checkstats.js | 8 +- events/buttons/guilapply.js | 154 ++++++++++------------- events/buttons/guildapplicationaccept.js | 80 ++++++------ events/buttons/guildapplicationdeny.js | 3 +- events/modals/denyreasonbox.js | 52 ++++++-- 7 files changed, 151 insertions(+), 176 deletions(-) delete mode 100644 events/buttons/applicationdelete.js diff --git a/.gitignore b/.gitignore index 5b21ab0..76bb9c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules/* -applications/* +apps/* config.json \ No newline at end of file diff --git a/events/buttons/applicationdelete.js b/events/buttons/applicationdelete.js deleted file mode 100644 index 03dbd46..0000000 --- a/events/buttons/applicationdelete.js +++ /dev/null @@ -1,28 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -module.exports = { - name: 'applicationdelete', - description: 'Delete an application channel.', - type: 'button', - - async execute(interaction) { - - await interaction.deferReply(); - - const channel = interaction.channel; - const applicantId = await channel.topic; - - await interaction.editReply('Application channel will be deleted in 5 seconds'); - - setTimeout(async () => { - - const filePath = path.join(__dirname, `../../apps/guild/${applicantId}`); - fs.rmSync(filePath, { force: true }); - - await channel.delete(); - - }, 5000); - - } -}; \ No newline at end of file diff --git a/events/buttons/checkstats.js b/events/buttons/checkstats.js index 4f57853..16f27f1 100644 --- a/events/buttons/checkstats.js +++ b/events/buttons/checkstats.js @@ -12,12 +12,12 @@ module.exports = { async execute(interaction) { await interaction.deferReply(); - - const channel = interaction.channel; - const applicantId = await channel.topic + + const message = interaction.message; + const embed = message.embeds[0]; + const applicantId = embed.footer.text.split(" ")[1] const filePath = path.join(__dirname, `../../apps/guild/${applicantId}`); - const uuid = fs.readFileSync(filePath, 'utf8'); const mojang = "https://api.mojang.com/user/profile/" diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js index ef7d8bd..0b99b3d 100644 --- a/events/buttons/guilapply.js +++ b/events/buttons/guilapply.js @@ -1,7 +1,7 @@ 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 { applicationsChannel } = require('../../config/options.json'); const { qu1, qu2, qu3, qu4, qu5, qu6, qu7, qu8 } = require('../../config/questions.json'); const { rq1, rq2, rq3, rq4, rq5, rq6, rq7, rq8 } = require('../../config/questions.json'); const { guildRole } = require('../../config/roles.json') @@ -26,12 +26,12 @@ module.exports = { if (interaction.customId === 'guildapply') { - await interaction.deferReply(); + await interaction.deferReply({ ephemeral: true }); - if (userRoles.includes(guildRole)) { - await interaction.editReply({ content: "You are already a member of the guild.", ephemeral: true }); - return - } + // if (userRoles.includes(guildRole)) { + // await interaction.editReply({ content: "You are already a member of the guild.", ephemeral: true }); + // return + // } const applicationFile = path.join(__dirname, '../../apps/guild/' + user.id); if (fs.existsSync(applicationFile)) { @@ -446,89 +446,73 @@ module.exports = { }); await user.deleteDM(); + + const channel = guild.channels.cache.get(applicationsChannel); - await guild.channels.create({ - name: `guild-app-${user.username}`, - type: ChannelType.GuildText, - topic: user.id, - permissionOverwrites: [ - { - id: guild.roles.everyone, - deny: [PermissionFlagsBits.ViewChannel] - } - ] - }).then(async channel => { - - await channel.send({ - embeds: [{ - title: user.username + "#" + user.discriminator + " - Guild Application", - color: embedColor, - thumbnail: { - url: user.avatarURL() + await channel.send({ + embeds: [{ + title: user.username + "#" + user.discriminator + " - Guild Application", + color: embedColor, + thumbnail: { + url: user.avatarURL() + }, + fields: [ + { + name: rq1, + value: "```" + answer1_1 + "```" }, - fields: [ - { - name: rq1, - value: "```" + answer1_1 + "```" - }, - { - name: rq2, - value: "```" + answer2_1 + "```" - }, - { - name: rq3, - value: "```" + answer3_1 + "```" - }, - { - name: rq4, - value: "```" + answer4_1 + "```" - }, - { - name: rq5, - value: "```" + answer5_1 + "```" - }, - { - name: rq6, - value: "```" + answer6_1 + "```" - }, - { - name: rq7, - value: "```" + answer7_1 + "```" - }, - { - name: rq8, - value: "```" + answer8_1 + "```" - } - - ], - footer: { - iconURL: guild.iconURL(), - text: "ID: " + user.id + { + name: rq2, + value: "```" + answer2_1 + "```" + }, + { + name: rq3, + value: "```" + answer3_1 + "```" + }, + { + name: rq4, + value: "```" + answer4_1 + "```" + }, + { + name: rq5, + value: "```" + answer5_1 + "```" + }, + { + name: rq6, + value: "```" + answer6_1 + "```" + }, + { + name: rq7, + value: "```" + answer7_1 + "```" + }, + { + name: rq8, + value: "```" + answer8_1 + "```" } - }], - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("guildapplicationaccept") - .setLabel("Accept") - .setStyle(ButtonStyle.Primary) - ), - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("guildapplicationdeny") - .setLabel("Deny") - .setStyle(ButtonStyle.Danger) - ), - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("checkstats") - .setLabel("Check Stats") - .setStyle(ButtonStyle.Secondary) - ) - ] - }); + ], + footer: { + iconURL: guild.iconURL(), + text: "ID: " + user.id + } + }], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("guildapplicationaccept") + .setLabel("Accept") + .setStyle(ButtonStyle.Primary), + new ButtonBuilder() + .setCustomId("guildapplicationdeny") + .setLabel("Deny") + .setStyle(ButtonStyle.Danger), + new ButtonBuilder() + .setCustomId("checkstats") + .setLabel("Check Stats") + .setStyle(ButtonStyle.Secondary) + ) + ] + }); - }) } } } \ No newline at end of file diff --git a/events/buttons/guildapplicationaccept.js b/events/buttons/guildapplicationaccept.js index 3740e02..58cdf71 100644 --- a/events/buttons/guildapplicationaccept.js +++ b/events/buttons/guildapplicationaccept.js @@ -1,5 +1,7 @@ const { ActionRowBuilder, ButtonStyle, ButtonBuilder } = require('discord.js'); const { color } = require('../../config/options.json'); +const fs = require('fs'); +const path = require('path'); module.exports = { name: 'guildapplicationaccept', @@ -8,14 +10,41 @@ module.exports = { async execute(interaction) { + await interaction.deferReply(); + const user = interaction.user; - const channel = interaction.channel; const guild = interaction.guild; const embedColor = Number(color.replace("#", "0x")); - const applicantId = await channel.topic + const message = interaction.message; + const embed = message.embeds[0]; + const applicantId = embed.footer.text.split(" ")[1] + const applicant = await guild.members.fetch(applicantId) const applicantUsername = applicant.user.username + "#" + applicant.user.discriminator; + const applicationFile = require(`../../apps/guild/${applicantId}`); + + await message.edit({ + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("guildapplicationaccept") + .setLabel("Accept") + .setStyle(ButtonStyle.Primary) + .setDisabled(true), + new ButtonBuilder() + .setCustomId("guildapplicationdeny") + .setLabel("Deny") + .setStyle(ButtonStyle.Danger) + .setDisabled(true), + new ButtonBuilder() + .setCustomId("checkstats") + .setLabel("Check Stats") + .setStyle(ButtonStyle.Secondary) + .setDisabled(true) + ) + ] + }); await applicant.send({ embeds: [{ @@ -24,43 +53,12 @@ module.exports = { }] }); - const message = await channel.messages.fetch({ limit: 1 }); - const messageID = message.first().id; + fs.rmSync(applicationFile) - await channel.messages.fetch(messageID).then(async (message) => { - - await message.edit({ - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("guildapplicationaccept") - .setLabel("Accept") - .setStyle(ButtonStyle.Primary) - .setDisabled(true) - ), - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("guildapplicationdeny") - .setLabel("Deny") - .setStyle(ButtonStyle.Danger) - .setDisabled(true) - ), - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("checkstats") - .setLabel("Check Stats") - .setStyle(ButtonStyle.Secondary) - .setDisabled(true) - ) - ] - }); - - }); - - await interaction.reply({ + await interaction.editReply({ embeds: [{ title: applicantUsername + " - Guild Application", - description: "Application accepted by <@" + user.id + ">.\n\nPress the button below to delete this channel.\n**When the user is added to the guild.**", + description: "Application has been accepted by <@" + user.id + ">.", color: embedColor, thumbnail: { url: applicant.avatarURL() @@ -69,15 +67,7 @@ module.exports = { iconURL: guild.iconURL(), text: "ID: " + applicant.id } - }], - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("applicationdelete") - .setLabel("Delete channel") - .setStyle(ButtonStyle.Danger) - ) - ] + }] }); } diff --git a/events/buttons/guildapplicationdeny.js b/events/buttons/guildapplicationdeny.js index 285b37a..6a82606 100644 --- a/events/buttons/guildapplicationdeny.js +++ b/events/buttons/guildapplicationdeny.js @@ -14,8 +14,7 @@ module.exports = { const guild = interaction.guild; const embedColor = Number(color.replace("#", "0x")); - const applicantId = await channel.topic - const applicant = await guild.members.fetch(applicantId) + const message = interaction.message; const modal = new ModalBuilder() .setTitle('Deny Reason') diff --git a/events/modals/denyreasonbox.js b/events/modals/denyreasonbox.js index c7258c0..afe82fc 100644 --- a/events/modals/denyreasonbox.js +++ b/events/modals/denyreasonbox.js @@ -1,4 +1,4 @@ -const { InteractionType, EmbedBuilder } = require('discord.js'); +const { InteractionType, EmbedBuilder, ActionRowBuilder, ButtonBuilder } = require('discord.js'); const { color } = require('../../config/options.json'); const fs = require('fs'); const path = require('path'); @@ -15,14 +15,39 @@ module.exports = { interaction.deferReply(); - const channel = interaction.channel; - const applicantId = channel.topic; const guild = interaction.guild; + + const message = interaction.message; + const embed = message.embeds[0]; + const applicantId = embed.footer.text.split(" ")[1]; + const applicant = await guild.members.fetch(applicantId); const reason = interaction.fields.fields.get('denyreason').value || "No reason provided"; const embedColor = Number(color.replace("#", "0x")); const filePath = path.join(__dirname, `../../apps/guild/${applicantId}`); + await message.edit({ + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("guildapplicationaccept") + .setLabel("Accept") + .setStyle(ButtonStyle.Primary) + .setDisabled(true), + new ButtonBuilder() + .setCustomId("guildapplicationdeny") + .setLabel("Deny") + .setStyle(ButtonStyle.Danger) + .setDisabled(true), + new ButtonBuilder() + .setCustomId("checkstats") + .setLabel("Check Stats") + .setStyle(ButtonStyle.Secondary) + .setDisabled(true) + ) + ] + }); + const dmMessage = new EmbedBuilder() .setDescription("Your application for the Illegitimate guild has been denied\n" + "**Reason:** `" + reason + "`") @@ -30,17 +55,22 @@ module.exports = { await applicant.send({ embeds: [dmMessage] }); + fs.rmSync(filePath); + await interaction.editReply({ embeds: [{ - description: "Application denied\n" + - "Channel will be deleted in 5 seconds...", - color: embedColor + title: "Application Denied", + description: "The application has been denied by <@" + interaction.user.id + ">.\n" + + "**Reason:** `" + reason + "`", + color: embedColor, + thumbnail: { + url: applicant.avatarURL() + }, + footer: { + iconURL: guild.iconURL(), + text: "ID: " + applicant.id + } }], }); - - setTimeout(() => { - fs.rmSync(filePath, { force: true }); - channel.delete(); - }, 5000); } } \ No newline at end of file