From 3deec40feb33c56d1552052d2b3c882a05e4240c Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 13 Mar 2023 00:11:59 +0100 Subject: [PATCH] Finalizing applications --- .gitignore | 1 + events/buttons/applicationdelete.js | 9 +++++++++ events/buttons/checkstats.js | 0 events/buttons/guilapply.js | 20 ++++++++++++++++++++ events/buttons/guildapplicationdeny.js | 6 +++++- 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 events/buttons/checkstats.js diff --git a/.gitignore b/.gitignore index d077eaa..5b21ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/* +applications/* config.json \ No newline at end of file diff --git a/events/buttons/applicationdelete.js b/events/buttons/applicationdelete.js index 33ed001..78967b8 100644 --- a/events/buttons/applicationdelete.js +++ b/events/buttons/applicationdelete.js @@ -1,3 +1,6 @@ +const fs = require('fs'); +const path = require('path'); + module.exports = { name: 'applicationdelete', description: 'Delete an application channel.', @@ -6,11 +9,17 @@ module.exports = { async execute(interaction) { const channel = interaction.channel; + const applicantId = await channel.topic; await interaction.reply('Application channel will be deleted in 5 seconds'); setTimeout(async () => { + + const filePath = path.join(__dirname, `../../applications/${applicantId}`); + fs.rmSync(filePath, { force: true }); + await channel.delete(); + }, 5000); } diff --git a/events/buttons/checkstats.js b/events/buttons/checkstats.js new file mode 100644 index 0000000..e69de29 diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js index 3a4819c..2b7c797 100644 --- a/events/buttons/guilapply.js +++ b/events/buttons/guilapply.js @@ -1,5 +1,7 @@ const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder } = require('discord.js'); const { color } = require('../../options.json'); +const path = require('path'); +const fs = require('fs'); module.exports = { name: 'guildapply', @@ -14,6 +16,14 @@ module.exports = { if (interaction.customId === 'guildapply') { + // check if there is a file in the applications folder with the user's id as the name + const applicationFile = path.join(__dirname, '../../applications/' + user.id); + + if (fs.existsSync(applicationFile)) { + await interaction.reply({ content: "You already have an application in progress.", ephemeral: true }); + return + } + const tooLong = new EmbedBuilder() .setDescription("You took too long to respond.") .setColor(embedColor) @@ -214,6 +224,10 @@ module.exports = { color: embedColor }] }) + + fs.writeFile(`./applications/${user.id}`, answer1_1, function (err) { + if (err) throw err; + }); await guild.channels.create({ name: `Application-${user.username}`, @@ -286,6 +300,12 @@ module.exports = { .setCustomId("guildapplicationdeny") .setLabel("Deny") .setStyle(ButtonStyle.Danger) + ), + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("checkstats") + .setLabel("Check Stats") + .setStyle(ButtonStyle.Secondary) ) ] }); diff --git a/events/buttons/guildapplicationdeny.js b/events/buttons/guildapplicationdeny.js index 412b237..9fcc390 100644 --- a/events/buttons/guildapplicationdeny.js +++ b/events/buttons/guildapplicationdeny.js @@ -1,3 +1,5 @@ +const fs = require('fs'); +const path = require('path'); const { color } = require('../../options.json'); module.exports = { @@ -21,7 +23,9 @@ module.exports = { }] }); + const filePath = path.join(__dirname, `../../applications/${applicantId}`); + fs.rmSync(filePath, { force: true }); + await channel.delete(); - } }; \ No newline at end of file