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,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)
)
]
}]
});
}

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) {
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')

View File

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