From 839b98e5e8f22cd231a9630e1cacc79d60d36d1e Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 19 Mar 2023 14:57:50 +0100 Subject: [PATCH] Adding staff apply --- events/buttons/guilapply.js | 2 +- events/buttons/guildapplicationaccept.js | 8 +-- events/buttons/staffapplicationaccept.js | 80 ++++++++++++++++++++++++ events/buttons/staffapplicationdelete.js | 28 +++++++++ events/buttons/staffapplicationdeny.js | 35 +++++++++++ events/buttons/staffapply.js | 31 ++++----- events/modals/denyreasonbox.js | 10 ++- events/modals/staffdenyreasonbox.js | 46 ++++++++++++++ 8 files changed, 212 insertions(+), 28 deletions(-) create mode 100644 events/buttons/staffapplicationaccept.js create mode 100644 events/buttons/staffapplicationdelete.js create mode 100644 events/buttons/staffapplicationdeny.js create mode 100644 events/modals/staffdenyreasonbox.js diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js index 7b166c1..ef7d8bd 100644 --- a/events/buttons/guilapply.js +++ b/events/buttons/guilapply.js @@ -448,7 +448,7 @@ module.exports = { await user.deleteDM(); await guild.channels.create({ - name: `Application-${user.username}`, + name: `guild-app-${user.username}`, type: ChannelType.GuildText, topic: user.id, permissionOverwrites: [ diff --git a/events/buttons/guildapplicationaccept.js b/events/buttons/guildapplicationaccept.js index dbe292a..3740e02 100644 --- a/events/buttons/guildapplicationaccept.js +++ b/events/buttons/guildapplicationaccept.js @@ -8,8 +8,6 @@ module.exports = { async execute(interaction) { - await interaction.deferReply(); - const user = interaction.user; const channel = interaction.channel; const guild = interaction.guild; @@ -26,8 +24,6 @@ module.exports = { }] }); - // fetch the first message in the channel and disable the buttons on it - const message = await channel.messages.fetch({ limit: 1 }); const messageID = message.first().id; @@ -61,9 +57,9 @@ module.exports = { }); - await interaction.editReply({ + await interaction.reply({ embeds: [{ - title: applicantUsername + " - Application", + 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.**", color: embedColor, thumbnail: { diff --git a/events/buttons/staffapplicationaccept.js b/events/buttons/staffapplicationaccept.js new file mode 100644 index 0000000..a14681a --- /dev/null +++ b/events/buttons/staffapplicationaccept.js @@ -0,0 +1,80 @@ +const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); +const { color } = require('../../config/options.json'); + +module.exports = { + name: 'staffapplicationaccept', + description: 'Accept a staff application.', + type: 'button', + + async execute(interaction) { + + const user = interaction.user; + 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 applicantUsername = applicant.user.username + "#" + applicant.user.discriminator; + + await applicant.send({ + embeds: [{ + description: `Your application for the Illegitimate staff team has been accepted.`, + color: embedColor + }] + }); + + // 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 interaction.reply({ + embeds: [{ + title: applicantUsername + " - Staff Application.", + description: "Application accepted by <@" + user.id + ">.\n\n" + + "Press the button below to delete this channel.\n" + + "**When the user was given their role**", + color: embedColor, + thumbnail: { + url: applicant.avatarURL() + }, + footer: { + iconurl: guild.iconURL(), + text: "ID: " + applicantId + } + }], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("staffapplicationdelete") + .setLabel("Delete channel") + .setStyle(ButtonStyle.Danger) + ) + ] + }); + + } +} \ No newline at end of file diff --git a/events/buttons/staffapplicationdelete.js b/events/buttons/staffapplicationdelete.js new file mode 100644 index 0000000..110bb37 --- /dev/null +++ b/events/buttons/staffapplicationdelete.js @@ -0,0 +1,28 @@ +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 new file mode 100644 index 0000000..1f864fb --- /dev/null +++ b/events/buttons/staffapplicationdeny.js @@ -0,0 +1,35 @@ +const { ModalBuilder, ActionRowBuilder, TextInputBuilder, TextInputStyle } = require('discord.js'); +const { color } = require('../../config/options.json'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'staffapplicationdeny', + description: 'Deny a guild application.', + type: 'button', + + 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') + .setComponents( + new ActionRowBuilder().setComponents( + new TextInputBuilder() + .setLabel('Deny Reason') + .setCustomId('staffdenyreason') + .setStyle(TextInputStyle.Paragraph) + .setPlaceholder('Enter a reason for denying the application') + .setRequired(false) + ) + ) + await interaction.showModal(modal); + } +}; \ No newline at end of file diff --git a/events/buttons/staffapply.js b/events/buttons/staffapply.js index caf49ac..f5a3890 100644 --- a/events/buttons/staffapply.js +++ b/events/buttons/staffapply.js @@ -22,20 +22,21 @@ module.exports = { const userRoles = interaction.member.roles.cache; const mojangAPI = "https://api.mojang.com/users/profiles/minecraft/" - - if (!userRoles.has(guildRole)) { - await interaction.reply({content: "You must be a member of the guild to apply for staff.", ephemeral: true}); - } - - if (userRoles.has(guildStaff)) { - await interaction.reply({content: "You are already a staff member.", ephemeral: true}); - } - if (interaction.customId === "staffapply") { - const applicationFile = path.join(__dirname, '../../staffapplications/' + user.id); + await interaction.deferReply({ ephemeral: true }); + + // if (!userRoles.has(guildRole)) { + // await interaction.editReply({content: "You must be a member of the guild to apply for staff.", ephemeral: true}); + // } +// + // if (userRoles.has(guildStaff)) { + // 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)) { - await interaction.reply({ content: "You already have an application in progress.", ephemeral: true }); + await interaction.editReply({ content: "You already have an application in progress.", ephemeral: true }); return } @@ -62,11 +63,11 @@ module.exports = { }] }) } catch (error) { - await interaction.reply({ content: "Please enable your DMs.", ephemeral: true }); + await interaction.editReply({ content: "Please enable your DMs.", ephemeral: true }); return } - await interaction.reply({ content: "Please check your DMs.", ephemeral: true}) + await interaction.editReply({ content: "Please check your DMs.", ephemeral: true}) const input = await user.dmChannel.awaitMessages({ filter: m => m.author.id === user.id, @@ -364,14 +365,14 @@ module.exports = { const userCheck = await fetch(mojangAPI + answer1_1) const uuid = userCheck.data.id - fs.writeFile(`./applications/${user.id}`, uuid, function (err) { + fs.writeFile(`./apps/staff/${user.id}`, uuid, function (err) { if (err) throw err; }); await user.deleteDM(); await guild.channels.create({ - name: `Application-${user.username}`, + name: `staff-app-${user.username}`, type: ChannelType.GuildText, topic: user.id, permissionOverwrites: [ diff --git a/events/modals/denyreasonbox.js b/events/modals/denyreasonbox.js index 37a298c..c7258c0 100644 --- a/events/modals/denyreasonbox.js +++ b/events/modals/denyreasonbox.js @@ -9,14 +9,12 @@ module.exports = { type: 'modal', async execute(interaction) { - - if (interaction.type === InteractionType.ApplicationCommand) return; - - interaction.deferReply(); - + if (interaction.type !== InteractionType.ModalSubmit) return; if (interaction.customId !== "denyreasonbox") return; - + + interaction.deferReply(); + const channel = interaction.channel; const applicantId = channel.topic; const guild = interaction.guild; diff --git a/events/modals/staffdenyreasonbox.js b/events/modals/staffdenyreasonbox.js new file mode 100644 index 0000000..5f2765d --- /dev/null +++ b/events/modals/staffdenyreasonbox.js @@ -0,0 +1,46 @@ +const { InteractionType, EmbedBuilder } = require('discord.js'); +const { color } = require('../../config/options.json'); +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'staffdenyreasonbox', + description: 'Deny reason box.', + type: 'modal', + + async execute(interaction) { + + if (interaction.type !== InteractionType.ModalSubmit) return; + if (interaction.customId !== "staffdenyreasonbox") return; + + 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 dmMessage = new EmbedBuilder() + .setDescription("Your application for the Illegitimate guild staff has been denied\n" + + "**Reason:** `" + reason + "`") + .setColor(embedColor); + + await applicant.send({ embeds: [dmMessage] }); + + await interaction.editReply({ + embeds: [{ + description: "Application denied\n" + + "Channel will be deleted in 5 seconds...", + color: embedColor + }], + }); + + setTimeout(() => { + fs.rmSync(filePath, { force: true }); + channel.delete(); + }, 5000); + } +} \ No newline at end of file