From ad37b8f9604d79c7264f7e93fa2eca3694d296bd Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 12 Mar 2023 23:45:13 +0100 Subject: [PATCH] Finishing applications --- events/buttons/applicationdelete.js | 17 ++ events/buttons/guilapply.js | 356 +++++++++++++++++------ events/buttons/guildapplicationaccept.js | 51 ++++ events/buttons/guildapplicationdeny.js | 27 ++ events/buttons/guildapply-dm.js | 83 ------ index.js | 4 +- 6 files changed, 360 insertions(+), 178 deletions(-) create mode 100644 events/buttons/applicationdelete.js create mode 100644 events/buttons/guildapplicationaccept.js create mode 100644 events/buttons/guildapplicationdeny.js delete mode 100644 events/buttons/guildapply-dm.js diff --git a/events/buttons/applicationdelete.js b/events/buttons/applicationdelete.js new file mode 100644 index 0000000..33ed001 --- /dev/null +++ b/events/buttons/applicationdelete.js @@ -0,0 +1,17 @@ +module.exports = { + name: 'applicationdelete', + description: 'Delete an application channel.', + type: 'button', + + async execute(interaction) { + + const channel = interaction.channel; + + await interaction.reply('Application channel will be deleted in 5 seconds'); + + setTimeout(async () => { + await channel.delete(); + }, 5000); + + } +}; \ No newline at end of file diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js index aa8e6fd..3a4819c 100644 --- a/events/buttons/guilapply.js +++ b/events/buttons/guilapply.js @@ -1,10 +1,10 @@ -const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js'); +const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder } = require('discord.js'); const { color } = require('../../options.json'); module.exports = { - // name: 'guildapply', - // description: 'Guild application button.', - // type: 'button', + name: 'guildapply', + description: 'Guild application button.', + type: 'button', async execute(interaction) { @@ -14,115 +14,283 @@ module.exports = { if (interaction.customId === 'guildapply') { - interaction.guild.channels.create({ - name: `application-${user.username}`, + const tooLong = new EmbedBuilder() + .setDescription("You took too long to respond.") + .setColor(embedColor) + + const cancelled = new EmbedBuilder() + .setDescription("You have cancelled your application.") + .setColor(embedColor) + + await interaction.reply({ content: "Please check your DMs.", ephemeral: true}) + + if (!user.dmChannel) { + await user.createDM(); + } + + await user.send({ + embeds: [{ + title: 'Guild Application', + description: "Please answer the following questions to apply for the guild.\n" + + "If you wish to cancel your application, please press the button below or type `cancel`.", + color: embedColor, + }] + }); + + const input = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 5 + }); + if (input.size === 0) { + await user.send({ embeds: [tooLong] }); + return + } + if (input.first().content.toLowerCase() !== 'yes') { + await user.send({ embeds: [cancelled]} ); + return + } + + // first question + const question1 = await user.send("1st") + const answer1 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer1.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer1.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer1_1 = answer1.first().content + + // second question + const question2 = await user.send("2nd") + const answer2 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer2.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer2.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer2_1 = answer2.first().content + + // third question + const question3 = await user.send("3rd") + const answer3 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer3.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer3.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer3_1 = answer3.first().content + + // fourth question + const question4 = await user.send("4th") + const answer4 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer4.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer4.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer4_1 = answer4.first().content + + // fifth question + const question5 = await user.send("5th") + const answer5 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer5.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer5.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer5_1 = answer5.first().content + + // sixth question + const question6 = await user.send("6th") + const answer6 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer6.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer6.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer6_1 = answer6.first().content + + // seventh question + const question7 = await user.send("7th") + const answer7 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer7.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer7.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer7_1 = answer7.first().content + + // eighth question + const question8 = await user.send("8th") + const answer8 = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 15 + }); + if (answer8.size === 0) { + await user.send({ embeds: [tooLong] }) + return + } + if (answer8.first().content.toLowerCase() === 'cancel') { + await user.send({ embeds: [cancelled] }) + return + } + const answer8_1 = answer8.first().content + + await user.send({ + embeds: [{ + description: "If you want to submit your application, type `yes` if not, type `no`", + color: embedColor + }] + }) + + const final = await user.dmChannel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 5 + }); + if (final.size === 0) { + await user.send({ embeds: [tooLong] }); + return + } + if (final.first().content.toLowerCase() !== 'yes') { + await user.send({ embeds: [cancelled]} ); + return + } + + await user.send({ + embeds: [{ + description: "Your application has been submitted!", + color: embedColor + }] + }) + + await guild.channels.create({ + name: `Application-${user.username}`, type: ChannelType.GuildText, + topic: user.id, permissionOverwrites: [ - { - id: user.id, - allow: [PermissionFlagsBits.ViewChannel] - }, { id: guild.roles.everyone, deny: [PermissionFlagsBits.ViewChannel] } ] - }).then(async channel => { - + await channel.send({ - embeds: [{ - title: 'Guild Application', - description: "Please answer the following questions to apply for the guild.\n" + - "If you wish to cancel your application, please press the button below or type `cancel`.", + embeds: [{ + title: user.username + "#" + user.discriminator + " - Application", color: embedColor, - }], + thumbnail: { + url: user.avatarURL() + }, + fields: [ + { + name: "1st", + value: answer1_1 + }, + { + name: "2nd", + value: answer2_1 + }, + { + name: "3rd", + value: answer3_1 + }, + { + name: "4th", + value: answer4_1 + }, + { + name: "5th", + value: answer5_1 + }, + { + name: "6th", + value: answer6_1 + }, + { + name: "7th", + value: answer7_1 + }, + { + name: "8th", + value: answer8_1 + } + ], + footer: { + iconURL: guild.iconURL(), + text: "ID: " + user.id + } + }], components: [ new ActionRowBuilder().addComponents( new ButtonBuilder() - .setCustomId('guildapplycancel') - .setLabel('Cancel') + .setCustomId("guildapplicationaccept") + .setLabel("Accept") + .setStyle(ButtonStyle.Primary) + ), + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("guildapplicationdeny") + .setLabel("Deny") .setStyle(ButtonStyle.Danger) - .setEmoji({ name: '❌' }) ) ] - }); - // confiraaamtion message - const input = await channel.awaitMessages({ - filter: m => m.author.id === user.id, - max: 1, - time: 1000 * 60 - }); - if (input.size === 0) { - await channel.delete(); - return - } - if (input.first().content.toLowerCase() !== 'yes') { - await channel.delete(); - return - } - - // question 1 - const question1 = await channel.send("1st") - const answer1 = await channel.awaitMessages({ - filter: m => m.author.id === user.id, - max: 1, - time: 1000 * 60 * 5 - }); - if (answer1.size === 0) { - await channel.delete(); - return - } - if (answer1.first().content.toLowerCase() === 'cancel') { - await channel.delete(); - return - } - const answer1_1 = answer1.first().content - - // question 2 - const question2 = await channel.send("2nd") - const answer2 = await channel.awaitMessages({ - filter: m => m.author.id === user.id, - max: 1, - time: 1000 * 60 * 15 - }); - if (answer2.size === 0) { - await channel.delete(); - return - } - if (answer2.first().content.toLowerCase() === 'cancel') { - await channel.delete(); - return - } - const answer2_1 = answer2.first().content - - // question 3 - const question3 = await channel.send("3rd") - const answer3 = await channel.awaitMessages({ - filter: m => m.author.id === user.id, - max: 1, - time: 1000 * 60 * 15 - }); - if (answer3.size === 0) { - await channel.delete(); - return - } - if (answer3.first().content.toLowerCase() === 'cancel') { - await channel.delete(); - return - } - const answer3_1 = answer3.first().content - - // output message - await channel.bulkDelete(100); - await channel.send("Answer 1: " + answer1_1 + "\n" + "Answer 2: " + answer2_1 + "\n" + "Answer 3: " + answer3_1); - }); - - await interaction.reply({ content: 'Application channel created', ephemeral: true }); - + }) } } } \ No newline at end of file diff --git a/events/buttons/guildapplicationaccept.js b/events/buttons/guildapplicationaccept.js new file mode 100644 index 0000000..8360df4 --- /dev/null +++ b/events/buttons/guildapplicationaccept.js @@ -0,0 +1,51 @@ +const { ActionRowBuilder, ButtonStyle, ButtonBuilder } = require('discord.js'); +const { color } = require('../../options.json'); + +module.exports = { + name: 'guildapplicationaccept', + description: 'Accept a guild 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 guild has been accepted.`, + color: embedColor + }] + }); + + await interaction.reply({ + embeds: [{ + title: applicantUsername + " - 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: { + url: applicant.avatarURL() + }, + footer: { + iconURL: guild.iconURL(), + text: "ID: " + applicant.id + } + }], + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId("applicationdelete") + .setLabel("Delete Channel") + .setStyle(ButtonStyle.Danger) + ) + ] + }); + + } +}; \ No newline at end of file diff --git a/events/buttons/guildapplicationdeny.js b/events/buttons/guildapplicationdeny.js new file mode 100644 index 0000000..412b237 --- /dev/null +++ b/events/buttons/guildapplicationdeny.js @@ -0,0 +1,27 @@ +const { color } = require('../../options.json'); + +module.exports = { + name: 'guildapplicationdeny', + 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) + + await applicant.send({ + embeds: [{ + description: `Your application for the Illegitimate guild has been denied.`, + color: embedColor + }] + }); + + await channel.delete(); + + } +}; \ No newline at end of file diff --git a/events/buttons/guildapply-dm.js b/events/buttons/guildapply-dm.js deleted file mode 100644 index 70f55f1..0000000 --- a/events/buttons/guildapply-dm.js +++ /dev/null @@ -1,83 +0,0 @@ -const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js'); -const { color } = require('../../options.json'); - -module.exports = { - name: 'guildapply', - description: 'Guild application button.', - type: 'button', - - async execute(interaction) { - - const user = interaction.user; - const guild = interaction.guild; - const embedColor = Number(color.replace("#", "0x")); - - if (interaction.customId === 'guildapply') { - - interaction.guild.channels.create({ - name: `application-${user.username}`, - type: ChannelType.GuildText, - permissionOverwrites: [ - { - id: user.id, - allow: [PermissionFlagsBits.ViewChannel] - }, - { - id: guild.roles.everyone, - deny: [PermissionFlagsBits.ViewChannel] - } - ] - - }).then(async channel => { - - await interaction.user.send({ - embeds: [{ - title: 'Guild Application', - description: "Please answer the following questions to apply for the guild.\n" + - "If you wish to cancel your application, please press the button below or type `cancel`.", - color: embedColor, - }] - }); - - const input = await interaction.user.awaitMessages({ - filter: m => m.author.id === user.id, - max: 1, - time: 1000 * 60 - }); - - if (input.size === 0) { - return - } - - if (input.first().content.toLowerCase() !== 'yes') { - await interaction.user.send('Application cancelled.'); - return - } - - const question1 = await interaction.user.send("1st") - const answer1 = await interaction.user.awaitMessages({ - filter: m => m.author.id === user.id, - max: 1, - time: 1000 * 60 * 5 - }); - - if (answer1.size === 0) { - return - } - - if (answer1.first().content.toLowerCase() === 'cancel') { - await interaction.user.send('Application cancelled.'); - return - } - - const answer1_1 = answer1.first().content - - console.log(answer1_1) - - }); - - await interaction.reply({ content: 'Application channel created', ephemeral: true }); - - } - } -} \ No newline at end of file diff --git a/index.js b/index.js index 7ead872..eae3bcc 100644 --- a/index.js +++ b/index.js @@ -9,11 +9,13 @@ const client = new Client({ GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, + GatewayIntentBits.DirectMessages ], partials: [ Partials.GuildMember, Partials.User, - Partials.Message + Partials.Message, + Partials.Channel ] });