Finishing staff applications

This commit is contained in:
2023-03-24 18:24:36 +01:00
parent f0e41fb27a
commit ea3fdf72d7
6 changed files with 111 additions and 161 deletions

View File

@@ -1,5 +1,6 @@
{ {
"color": "#eeaadb", "color": "#eeaadb",
"applicationsChannel": "776705352456470550", "applicationsChannel": "776705352456470550",
"staffApplicationsChannel": "1039258641393520700",
"hypixelGuildID": "5a353a170cf2e529044f2935" "hypixelGuildID": "5a353a170cf2e529044f2935"
} }

View File

@@ -1,5 +1,7 @@
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js'); const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const { color } = require('../../config/options.json'); const { color } = require('../../config/options.json');
const mongoose = require('mongoose');
const staffapp = require('../../schemas/staffAppSchema.js');
module.exports = { module.exports = {
name: 'staffapplicationaccept', name: 'staffapplicationaccept',
@@ -13,9 +15,11 @@ module.exports = {
const guild = interaction.guild; const guild = interaction.guild;
const embedColor = Number(color.replace("#", "0x")); 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 applicant = await guild.members.fetch(applicantId)
const applicantUsername = applicant.user.username + "#" + applicant.user.discriminator;
await applicant.send({ await applicant.send({
embeds: [{ embeds: [{
@@ -24,33 +28,27 @@ module.exports = {
}] }]
}); });
// fetcg the message with the buttons staffapplicationaccept and staffapplicationdeny await message.edit({
components: [
const message = await channel.messages.fetch({ limit: 10 }); new ActionRowBuilder().addComponents(
const messageID = message.first().id; new ButtonBuilder()
.setCustomId("staffapplicationaccept")
await channel.messages.fetch(messageID).then(async (message) => { .setLabel("Accept")
.setStyle(ButtonStyle.Primary)
await message.edit({ .setDisabled(true)
components: [ ),
new ActionRowBuilder().addComponents( new ActionRowBuilder().addComponents(
new ButtonBuilder() new ButtonBuilder()
.setCustomId("staffapplicationaccept") .setCustomId("staffapplicationdeny")
.setLabel("Accept") .setLabel("Deny")
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Danger)
.setDisabled(true) .setDisabled(true)
), )
new ActionRowBuilder().addComponents( ]
new ButtonBuilder()
.setCustomId("staffapplicationdeny")
.setLabel("Deny")
.setStyle(ButtonStyle.Danger)
.setDisabled(true)
)
]
});
}); });
await staffapp.findOneAndDelete({ userId: applicantId });
await interaction.reply({ await interaction.reply({
embeds: [{ embeds: [{
title: applicantUsername + " - Staff Application.", title: applicantUsername + " - Staff Application.",
@@ -65,15 +63,7 @@ module.exports = {
iconurl: guild.iconURL(), iconurl: guild.iconURL(),
text: "ID: " + applicantId text: "ID: " + applicantId
} }
}], }]
components: [
new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId("staffapplicationdelete")
.setLabel("Delete channel")
.setStyle(ButtonStyle.Danger)
)
]
}); });
} }

View File

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

View File

@@ -10,13 +10,6 @@ module.exports = {
async execute(interaction) { 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() const modal = new ModalBuilder()
.setTitle('Deny Reason') .setTitle('Deny Reason')
.setCustomId('staffdenyreasonbox') .setCustomId('staffdenyreasonbox')

View File

@@ -1,10 +1,12 @@
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 { 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 { sq1, sq2, sq3, sq4, sq5, sq6 } = require('../../config/questions.json');
const { rsq1, rsq2, rsq3, rsq4, rsq5, rsq6 } = require('../../config/questions.json'); const { rsq1, rsq2, rsq3, rsq4, rsq5, rsq6 } = require('../../config/questions.json');
const { guildRole, guildStaff } = require('../../config/roles.json') const { guildRole, guildStaff } = require('../../config/roles.json')
const mongoose = require('mongoose');
const staffapp = require('../../schemas/staffAppSchema.js');
const path = require('path'); const path = require('path');
const fetch = require('axios'); const fetch = require('axios');
const fs = require('fs'); const fs = require('fs');
@@ -34,10 +36,10 @@ module.exports = {
// await interaction.editReply({content: "You are already a staff member.", ephemeral: true}); // await interaction.editReply({content: "You are already a staff member.", ephemeral: true});
// } // }
const applicationFile = path.join(__dirname, '../../apps/staff/' + user.id); const application = await staffapp.findOne({ userID: user.id });
if (fs.existsSync(applicationFile)) {
if (application) {
await interaction.editReply({ content: "You already have an application in progress.", ephemeral: true }); await interaction.editReply({ content: "You already have an application in progress.", ephemeral: true });
return
} }
const tooLong = new EmbedBuilder() const tooLong = new EmbedBuilder()
@@ -362,83 +364,70 @@ module.exports = {
}] }]
}) })
const userCheck = await fetch(mojangAPI + answer1_1) const newStaffApp = new staffapp({
const uuid = userCheck.data.id _id: new mongoose.Types.ObjectId(),
userID: user.id,
fs.writeFile(`./apps/staff/${user.id}`, uuid, function (err) { })
if (err) throw err; newStaffApp.save()
});
await user.deleteDM(); await user.deleteDM();
await guild.channels.create({ const channel = guild.channels.cache.get(staffApplicationsChannel);
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({ await channel.send({
embeds: [{ embeds: [{
title: user.username + "#" + user.discriminator + " - Staff Application", title: user.username + "#" + user.discriminator + " - Staff Application",
color: embedColor, color: embedColor,
thumbnail: { thumbnail: {
url: user.avatarURL() url: user.avatarURL()
},
fields: [
{
name: rsq1,
value: "```" + answer1_1 + "```"
}, },
fields: [ {
{ name: rsq2,
name: rsq1, value: "```" + answer2_1 + "```"
value: "```" + answer1_1 + "```" },
}, {
{ name: rsq3,
name: rsq2, value: "```" + answer3_1 + "```"
value: "```" + answer2_1 + "```" },
}, {
{ name: rsq4,
name: rsq3, value: "```" + answer4_1 + "```"
value: "```" + answer3_1 + "```" },
}, {
{ name: rsq5,
name: rsq4, value: "```" + answer5_1 + "```"
value: "```" + answer4_1 + "```" },
}, {
{ name: rsq6,
name: rsq5, value: "```" + answer6_1 + "```"
value: "```" + answer5_1 + "```"
},
{
name: rsq6,
value: "```" + answer6_1 + "```"
}
],
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)
)
]
});
}) ],
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)
)
]
}
);
} }
} }
} }

View File

@@ -16,12 +16,14 @@ module.exports = {
interaction.deferReply(); interaction.deferReply();
const channel = interaction.channel; const channel = interaction.channel;
const applicantId = channel.topic;
const guild = interaction.guild; const guild = interaction.guild;
const applicant = await guild.members.fetch(applicantId);
const reason = interaction.fields.fields.get('staffdenyreason').value || "No reason provided"; const reason = interaction.fields.fields.get('staffdenyreason').value || "No reason provided";
const embedColor = Number(color.replace("#", "0x")); 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() const dmMessage = new EmbedBuilder()
.setDescription("Your application for the Illegitimate guild staff has been denied\n" + .setDescription("Your application for the Illegitimate guild staff has been denied\n" +
@@ -32,15 +34,18 @@ module.exports = {
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
description: "Application denied\n" + title: "Application Denied",
"Channel will be deleted in 5 seconds...", description: "The application has been denied by <@" + interaction.user.id + ">.\n" +
color: embedColor "**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);
} }
} }