From ea3fdf72d70015cca4b59abc2e4525b92a12c8e4 Mon Sep 17 00:00:00 2001 From: Taken Date: Fri, 24 Mar 2023 18:24:36 +0100 Subject: [PATCH] Finishing staff applications --- config/options.json | 1 + events/buttons/staffapplicationaccept.js | 62 ++++------ events/buttons/staffapplicationdelete.js | 28 ----- events/buttons/staffapplicationdeny.js | 7 -- events/buttons/staffapply.js | 145 +++++++++++------------ events/modals/staffdenyreasonbox.js | 29 +++-- 6 files changed, 111 insertions(+), 161 deletions(-) delete mode 100644 events/buttons/staffapplicationdelete.js diff --git a/config/options.json b/config/options.json index 7879f18..b073e04 100644 --- a/config/options.json +++ b/config/options.json @@ -1,5 +1,6 @@ { "color": "#eeaadb", "applicationsChannel": "776705352456470550", + "staffApplicationsChannel": "1039258641393520700", "hypixelGuildID": "5a353a170cf2e529044f2935" } \ No newline at end of file diff --git a/events/buttons/staffapplicationaccept.js b/events/buttons/staffapplicationaccept.js index a14681a..a8cc829 100644 --- a/events/buttons/staffapplicationaccept.js +++ b/events/buttons/staffapplicationaccept.js @@ -1,5 +1,7 @@ const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); const { color } = require('../../config/options.json'); +const mongoose = require('mongoose'); +const staffapp = require('../../schemas/staffAppSchema.js'); module.exports = { name: 'staffapplicationaccept', @@ -13,9 +15,11 @@ module.exports = { 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; await applicant.send({ embeds: [{ @@ -24,33 +28,27 @@ module.exports = { }] }); - // fetcg the message with the buttons staffapplicationaccept and staffapplicationdeny - - const message = await channel.messages.fetch({ limit: 10 }); - const messageID = message.first().id; - - await channel.messages.fetch(messageID).then(async (message) => { - - await message.edit({ - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("staffapplicationaccept") - .setLabel("Accept") - .setStyle(ButtonStyle.Primary) - .setDisabled(true) - ), - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("staffapplicationdeny") - .setLabel("Deny") - .setStyle(ButtonStyle.Danger) - .setDisabled(true) - ) - ] - }); + await message.edit({ + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("staffapplicationaccept") + .setLabel("Accept") + .setStyle(ButtonStyle.Primary) + .setDisabled(true) + ), + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("staffapplicationdeny") + .setLabel("Deny") + .setStyle(ButtonStyle.Danger) + .setDisabled(true) + ) + ] }); + await staffapp.findOneAndDelete({ userId: applicantId }); + await interaction.reply({ embeds: [{ title: applicantUsername + " - Staff Application.", @@ -65,15 +63,7 @@ module.exports = { iconurl: guild.iconURL(), text: "ID: " + applicantId } - }], - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("staffapplicationdelete") - .setLabel("Delete channel") - .setStyle(ButtonStyle.Danger) - ) - ] + }] }); } diff --git a/events/buttons/staffapplicationdelete.js b/events/buttons/staffapplicationdelete.js deleted file mode 100644 index 110bb37..0000000 --- a/events/buttons/staffapplicationdelete.js +++ /dev/null @@ -1,28 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -module.exports = { - name: 'staffapplicationdelete', - 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/staff/${applicantId}`); - fs.rmSync(filePath, { force: true }); - - await channel.delete(); - - }, 5000); - - } -}; \ No newline at end of file diff --git a/events/buttons/staffapplicationdeny.js b/events/buttons/staffapplicationdeny.js index 1f864fb..cfe34b1 100644 --- a/events/buttons/staffapplicationdeny.js +++ b/events/buttons/staffapplicationdeny.js @@ -10,13 +10,6 @@ module.exports = { async execute(interaction) { - const channel = interaction.channel; - const guild = interaction.guild; - const embedColor = Number(color.replace("#", "0x")); - - const applicantId = await channel.topic - const applicant = await guild.members.fetch(applicantId) - const modal = new ModalBuilder() .setTitle('Deny Reason') .setCustomId('staffdenyreasonbox') diff --git a/events/buttons/staffapply.js b/events/buttons/staffapply.js index f5a3890..6bee3a5 100644 --- a/events/buttons/staffapply.js +++ b/events/buttons/staffapply.js @@ -1,10 +1,12 @@ 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 { staffApplicationsChannel } = require('../../config/options.json'); const { sq1, sq2, sq3, sq4, sq5, sq6 } = require('../../config/questions.json'); const { rsq1, rsq2, rsq3, rsq4, rsq5, rsq6 } = require('../../config/questions.json'); const { guildRole, guildStaff } = require('../../config/roles.json') +const mongoose = require('mongoose'); +const staffapp = require('../../schemas/staffAppSchema.js'); const path = require('path'); const fetch = require('axios'); const fs = require('fs'); @@ -34,10 +36,10 @@ module.exports = { // await interaction.editReply({content: "You are already a staff member.", ephemeral: true}); // } - const applicationFile = path.join(__dirname, '../../apps/staff/' + user.id); - if (fs.existsSync(applicationFile)) { + const application = await staffapp.findOne({ userID: user.id }); + + if (application) { await interaction.editReply({ content: "You already have an application in progress.", ephemeral: true }); - return } const tooLong = new EmbedBuilder() @@ -361,84 +363,71 @@ module.exports = { color: embedColor }] }) - - const userCheck = await fetch(mojangAPI + answer1_1) - const uuid = userCheck.data.id - - fs.writeFile(`./apps/staff/${user.id}`, uuid, function (err) { - if (err) throw err; - }); - + + const newStaffApp = new staffapp({ + _id: new mongoose.Types.ObjectId(), + userID: user.id, + }) + newStaffApp.save() await user.deleteDM(); - await guild.channels.create({ - name: `staff-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 + " - Staff Application", - color: embedColor, - thumbnail: { - url: user.avatarURL() + const channel = guild.channels.cache.get(staffApplicationsChannel); + + await channel.send({ + embeds: [{ + title: user.username + "#" + user.discriminator + " - Staff Application", + color: embedColor, + thumbnail: { + url: user.avatarURL() + }, + fields: [ + { + name: rsq1, + value: "```" + answer1_1 + "```" }, - fields: [ - { - name: rsq1, - value: "```" + answer1_1 + "```" - }, - { - name: rsq2, - value: "```" + answer2_1 + "```" - }, - { - name: rsq3, - value: "```" + answer3_1 + "```" - }, - { - name: rsq4, - value: "```" + answer4_1 + "```" - }, - { - name: rsq5, - value: "```" + answer5_1 + "```" - }, - { - name: rsq6, - value: "```" + answer6_1 + "```" - } - - ], - footer: { - iconURL: guild.iconURL(), - text: "ID: " + user.id + { + name: rsq2, + value: "```" + answer2_1 + "```" + }, + { + name: rsq3, + value: "```" + answer3_1 + "```" + }, + { + name: rsq4, + value: "```" + answer4_1 + "```" + }, + { + name: rsq5, + value: "```" + answer5_1 + "```" + }, + { + name: rsq6, + value: "```" + answer6_1 + "```" } - }], - components: [ - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("staffapplicationaccept") - .setLabel("Accept") - .setStyle(ButtonStyle.Primary) - ), - new ActionRowBuilder().addComponents( - new ButtonBuilder() - .setCustomId("staffapplicationdeny") - .setLabel("Deny") - .setStyle(ButtonStyle.Danger) - ) - ] - }); - - }) + + ], + footer: { + iconURL: guild.iconURL(), + text: "ID: " + user.id + } + }], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("staffapplicationaccept") + .setLabel("Accept") + .setStyle(ButtonStyle.Primary) + ), + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("staffapplicationdeny") + .setLabel("Deny") + .setStyle(ButtonStyle.Danger) + ) + ] + } + ); } } } \ No newline at end of file diff --git a/events/modals/staffdenyreasonbox.js b/events/modals/staffdenyreasonbox.js index 5f2765d..814f747 100644 --- a/events/modals/staffdenyreasonbox.js +++ b/events/modals/staffdenyreasonbox.js @@ -16,12 +16,14 @@ module.exports = { interaction.deferReply(); 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('staffdenyreason').value || "No reason provided"; const embedColor = Number(color.replace("#", "0x")); - const filePath = path.join(__dirname, `../../apps/staff/${applicantId}`); + + const message = interaction.message; + const embed = message.embeds[0]; + const applicantId = embed.footer.text.split(" ")[1] + const applicant = await guild.members.fetch(applicantId) const dmMessage = new EmbedBuilder() .setDescription("Your application for the Illegitimate guild staff has been denied\n" + @@ -32,15 +34,18 @@ module.exports = { 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