diff --git a/src/components/buttons/guildapply.ts b/src/components/buttons/guildapply.ts index 2905df4..6abdd11 100644 --- a/src/components/buttons/guildapply.ts +++ b/src/components/buttons/guildapply.ts @@ -1,12 +1,12 @@ -import { ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder, GuildMember, TextChannel } from "discord.js" +import { ButtonBuilder, ButtonStyle, ActionRowBuilder, GuildMember, TextChannel } from "discord.js" import { embedColor, applicationsChannel } from "config/options" import { largeM, smallM, ignM } from "config/limitmessages" import questions from "config/questions" import { guildRole } from "config/roles" -import { getUUID } from "utils/Hypixel" import mongoose from "mongoose" import guildapp from "schemas/guildAppSchema" import { IButton } from "interfaces" +import applicationQuestions from "utils/functions/applicationquestions" export = { name: "guildapply", @@ -39,16 +39,6 @@ export = { return } - 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) - const attachments = new EmbedBuilder() - .setDescription("You have uploaded an attachment. Please do not upload images, videos, or GIFS.") - .setColor(embedColor) - try { await user.send({ embeds: [{ @@ -71,18 +61,8 @@ export = { max: 1, time: 1000 * 60 }) - if (input.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (input.first()!.content.toLowerCase() !== "yes") { - await user.send({ embeds: [cancelled] }) - return - } - if (input.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } + const confirm1 = await applicationQuestions(input, user, 0, "confirmation") + if (!confirm1) return // first question await user.send({ @@ -95,44 +75,16 @@ export = { } }] }) - const answer1 = await user.dmChannel!.awaitMessages({ + + const useranswer1 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.user.id, max: 1, time: 1000 * 60 * 5 }) - if (answer1.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (answer1.first()!.content.toLowerCase() === "cancel") { - await user.send({ embeds: [cancelled] }) - return - } - if (answer1.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer1.first()!.content.length > 16) { - await user.send({ - embeds: [{ - description: "Max character limit is 16.", - color: embedColor - }] - }) - return - } - const uuid = await getUUID(answer1.first()!.content) - if (!uuid) { - await user.send({ - embeds: [{ - description: "That is not a valid Minecraft username.\n" + - "Application cancelled.", - color: embedColor - }] - }) - return - } - const answer1_1 = answer1.first()!.content + const answer1Obj = await applicationQuestions(useranswer1, user, 16, "ign") as boolean | { answer: string, uuid: string } + if (answer1Obj === false || answer1Obj === true) return + const answer1 = answer1Obj.answer + const uuid = answer1Obj.uuid // second question await user.send({ @@ -145,33 +97,14 @@ export = { } }] }) - const answer2 = await user.dmChannel!.awaitMessages({ + + const useranswer2 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer2.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer2.first()!.content.length > 8) { - await user.send({ - embeds: [{ - description: "Max character limit is 8.", - color: embedColor - }] - }) - return - } - const answer2_1 = answer2.first()!.content + const answer2 = await applicationQuestions(useranswer2, user, 8, "normal") + if (!answer2) return // third question await user.send({ @@ -184,32 +117,14 @@ export = { } }] }) - const answer3 = await user.dmChannel!.awaitMessages({ + + const useranswer3 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer3.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer3.first()!.content.length > 128) { - await user.send({ - embeds: [{ - description: "Max character limit is 128.", - color: embedColor - }] - }) - } - const answer3_1 = answer3.first()!.content + const answer3 = await applicationQuestions(useranswer3, user, 128, "normal") + if (!answer3) return // fourth question await user.send({ @@ -223,32 +138,14 @@ export = { } }] }) - const answer4 = await user.dmChannel!.awaitMessages({ + + const useranswer4 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer4.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer4.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256.", - color: embedColor - }] - }) - } - const answer4_1 = answer4.first()!.content + const answer4 = await applicationQuestions(useranswer4, user, 256, "normal") + if (!answer4) return // fifth question await user.send({ @@ -261,32 +158,14 @@ export = { } }] }) - const answer5 = await user.dmChannel!.awaitMessages({ + + const useranswer5 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer5.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer5.first()!.content.length > 128) { - await user.send({ - embeds: [{ - description: "Max character limit is 128.", - color: embedColor - }] - }) - } - const answer5_1 = answer5.first()!.content + const answer5 = await applicationQuestions(useranswer5, user, 128, "normal") + if (!answer5) return // sixth question await user.send({ @@ -299,32 +178,14 @@ export = { } }] }) - const answer6 = await user.dmChannel!.awaitMessages({ + + const useranswer6 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer6.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer6.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256.", - color: embedColor - }] - }) - } - const answer6_1 = answer6.first()!.content + const answer6 = await applicationQuestions(useranswer6, user, 256, "normal") + if (!answer6) return // seventh question await user.send({ @@ -337,32 +198,14 @@ export = { } }] }) - const answer7 = await user.dmChannel!.awaitMessages({ + + const useranswer7 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer7.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer7.first()!.content.length > 128) { - await user.send({ - embeds: [{ - description: "Max character limit is 128.", - color: embedColor - }] - }) - } - const answer7_1 = answer7!.first()!.content + const answer7 = await applicationQuestions(useranswer7, user, 128, "normal") + if (!answer7) return // eighth question await user.send({ @@ -375,32 +218,14 @@ export = { } }] }) - const answer8 = await user.dmChannel!.awaitMessages({ + + const useranswer8 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer8.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer8.first()!.content.length > 64) { - await user.send({ - embeds: [{ - description: "Max character limit is 64.", - color: embedColor - }] - }) - } - const answer8_1 = answer8.first()!.content + const answer8 = await applicationQuestions(useranswer8, user, 64, "normal") + if (!answer8) return await user.send({ embeds: [{ @@ -414,18 +239,8 @@ export = { 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 - } - if (final.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } + const confirm2 = await applicationQuestions(final, user, 0, "confirmation") + if (!confirm2) return await user.send({ embeds: [{ @@ -453,35 +268,35 @@ export = { fields: [ { name: rq(1), - value: "```" + answer1_1 + "```" + value: "```" + answer1 + "```" }, { name: rq(2), - value: "```" + answer2_1 + "```" + value: "```" + answer2 + "```" }, { name: rq(3), - value: "```" + answer3_1 + "```" + value: "```" + answer3 + "```" }, { name: rq(4), - value: "```" + answer4_1 + "```" + value: "```" + answer4 + "```" }, { name: rq(5), - value: "```" + answer5_1 + "```" + value: "```" + answer5 + "```" }, { name: rq(6), - value: "```" + answer6_1 + "```" + value: "```" + answer6 + "```" }, { name: rq(7), - value: "```" + answer7_1 + "```" + value: "```" + answer7 + "```" }, { name: rq(8), - value: "```" + answer8_1 + "```" + value: "```" + answer8 + "```" } ], footer: { diff --git a/src/components/buttons/guildinactivitylog.ts b/src/components/buttons/guildinactivitylog.ts index 794d7b7..692cc53 100644 --- a/src/components/buttons/guildinactivitylog.ts +++ b/src/components/buttons/guildinactivitylog.ts @@ -1,10 +1,10 @@ -import { ButtonBuilder, ActionRowBuilder, ButtonStyle, EmbedBuilder, GuildMember, TextChannel } from "discord.js" +import { ButtonBuilder, ActionRowBuilder, ButtonStyle, GuildMember, TextChannel } from "discord.js" import { gm, manager, moderator, beast, member, guildStaff, guildRole } from "config/roles" import { ignM, smallM, largeM } from "config/limitmessages" import { inactivity } from "config/questions" import { embedColor, inactivityLogChannel } from "config/options" import { IButton } from "interfaces" -import { getIGN } from "utils/Hypixel" +import applicationQuestions from "utils/functions/applicationquestions" const guildRoles = [gm, manager, moderator, beast, member, guildStaff, guildRole] export = { @@ -31,16 +31,6 @@ export = { return inactivity[n - 1].r } - 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) - const attachments = new EmbedBuilder() - .setDescription("You have uploaded an attachment. Please do not upload images, videos, or GIFS.") - .setColor(embedColor) - try { await user.send({ embeds: [{ @@ -70,18 +60,8 @@ export = { max: 1, time: 1000 * 60 }) - if (input.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (input.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (input.first()!.content.toLowerCase() !== "yes") { - await user.send({ embeds: [cancelled] }) - return - } + const confirm1 = await applicationQuestions(input, user, 0, "confirmation") + if (!confirm1) return await user.send({ embeds: [{ @@ -94,43 +74,14 @@ export = { }] }) - const answer1 = await user.dmChannel!.awaitMessages({ + const useranswer1 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.user.id, max: 1, time: 1000 * 60 * 5 }) - if (answer1.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer1.first()!.content.length > 16) { - await user.send({ - embeds: [{ - description: "Max character limit is 16.", - color: embedColor - }] - }) - return - } - if (answer1.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (answer1.first()!.content.toLowerCase() === "cancel") { - await user.send({ embeds: [cancelled] }) - return - } - if (await getIGN(answer1.first()!.content)) { - await user.send({ - embeds: [{ - description: "That is not a valid Minecraft username.\n" + - "Application cancelled.", - color: embedColor - }] - }) - return - } - const answer1_1 = answer1.first()!.content + const answer1Obj = await applicationQuestions(useranswer1, user, 16, "ign") as boolean | { answer: string, uuid: string } + if (answer1Obj === false || answer1Obj === true) return + const answer1 = answer1Obj.answer await user.send({ embeds: [{ @@ -142,33 +93,13 @@ export = { } }] }) - const answer2 = await user.dmChannel!.awaitMessages({ + const useranswer2 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.user.id, max: 1, time: 1000 * 60 * 5 }) - if (answer2.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer2.first()!.content.length > 128) { - await user.send({ - embeds: [{ - description: "Max character limit is 128.", - color: embedColor - }] - }) - return - } - if (answer1.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (answer1.first()!.content.toLowerCase() === "cancel") { - await user.send({ embeds: [cancelled] }) - return - } - const answer2_1 = answer1.first()!.content + const answer2 = await applicationQuestions(useranswer2, user, 128, "normal") + if (!answer2) return await user.send({ embeds: [{ @@ -180,33 +111,13 @@ export = { } }] }) - const answer3 = await user.dmChannel!.awaitMessages({ + const useranswer3 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.user.id, max: 1, time: 1000 * 60 * 15 }) - if (answer3.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer3.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256", - color: embedColor - }] - }) - return - } - if (answer1.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (answer1.first()!.content.toLowerCase() === "cancel") { - await user.send({ embeds: [cancelled] }) - return - } - const answer3_1 = answer1.first()!.content + const answer3 = await applicationQuestions(useranswer3, user, 256, "normal") + if (!answer3) return await user.send({ embeds: [{ @@ -219,18 +130,8 @@ export = { max: 1, time: 1000 * 60 * 5 }) - if (final.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (final.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (final.first()!.content.toLowerCase() !== "yes") { - await user.send({ embeds: [cancelled] }) - return - } + const confirm2 = await applicationQuestions(final, user, 0, "confirmation") + if (!confirm2) return await user.send({ embeds: [{ @@ -251,15 +152,15 @@ export = { fields: [ { name: rq(1), - value: "`" + answer1_1 + "`" + value: "`" + answer1 + "`" }, { name: rq(2), - value: "`" + answer2_1 + "`" + value: "`" + answer2 + "`" }, { name: rq(3), - value: "`" + answer3_1 + "`" + value: "`" + answer3 + "`" } ], footer: { diff --git a/src/components/buttons/staffapply.ts b/src/components/buttons/staffapply.ts index eed22a4..aa564bf 100644 --- a/src/components/buttons/staffapply.ts +++ b/src/components/buttons/staffapply.ts @@ -1,4 +1,4 @@ -import { ButtonBuilder, ButtonStyle, ActionRowBuilder, EmbedBuilder, GuildMember, TextChannel } from "discord.js" +import { ButtonBuilder, ButtonStyle, ActionRowBuilder, GuildMember, TextChannel } from "discord.js" import { embedColor, staffApplicationsChannel } from "config/options" import { largeM, ignM } from "config/limitmessages" import questions from "config/questions" @@ -6,9 +6,9 @@ import { guildRole, guildStaff } from "config/roles" import mongoose from "mongoose" import staffapp from "schemas/staffAppSchema" import settings from "schemas/settingsSchema" -import { getUUID } from "utils/Hypixel" import { IButton } from "interfaces" import env from "utils/Env" +import applicationQuestions from "utils/functions/applicationquestions" export = { name: "staffapply", @@ -57,16 +57,6 @@ export = { return } - 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) - const attachments = new EmbedBuilder() - .setDescription("You have uploaded an attachment. Please do not upload images, videos, or GIFS.") - .setColor(embedColor) - try { await user.send({ embeds: [{ @@ -89,18 +79,8 @@ export = { max: 1, time: 1000 * 60 }) - if (input.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (input.first()!.content.toLowerCase() !== "yes") { - await user.send({ embeds: [cancelled] }) - return - } - if (input.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } + const confirm1 = await applicationQuestions(input, user, 0, "confirmation") + if (!confirm1) return // first question await user.send({ @@ -113,44 +93,15 @@ export = { } }] }) - const answer1 = await user.dmChannel!.awaitMessages({ + const useranswer1 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.user.id, max: 1, time: 1000 * 60 * 5 }) - if (answer1.size === 0) { - await user.send({ embeds: [tooLong] }) - return - } - if (answer1.first()!.content.toLowerCase() === "cancel") { - await user.send({ embeds: [cancelled] }) - return - } - if (answer1.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer1.first()!.content.length > 16) { - await user.send({ - embeds: [{ - description: "Max character limit is 16.", - color: embedColor - }] - }) - return - } - const uuid = await getUUID(answer1.first()!.content) - if (!uuid) { - await user.send({ - embeds: [{ - description: "That is not a valid Minecraft username.\n" + - "Application cancelled.", - color: embedColor - }] - }) - return - } - const answer1_1 = answer1.first()!.content + const answer1Obj = await applicationQuestions(useranswer1, user, 16, "ign") as boolean | { answer: string, uuid: string } + if (answer1Obj === false || answer1Obj === true) return + const answer1 = answer1Obj.answer + const uuid = answer1Obj.uuid // second question await user.send({ @@ -164,33 +115,13 @@ export = { } }] }) - const answer2 = await user.dmChannel!.awaitMessages({ + const useranswer2 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer2.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer2.first()!.content.length > 64) { - await user.send({ - embeds: [{ - description: "Max character limit is 64.", - color: embedColor - }] - }) - return - } - const answer2_1 = answer2.first()!.content + const answer2 = await applicationQuestions(useranswer2, user, 64, "normal") + if (!answer2) return // third question await user.send({ @@ -203,32 +134,13 @@ export = { } }] }) - const answer3 = await user.dmChannel!.awaitMessages({ + const useranswer3 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer3.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer3.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256.", - color: embedColor - }] - }) - } - const answer3_1 = answer3.first()!.content + const answer3 = await applicationQuestions(useranswer3, user, 256, "normal") + if (!answer3) return // fourth question await user.send({ @@ -241,32 +153,13 @@ export = { } }] }) - const answer4 = await user.dmChannel!.awaitMessages({ + const useranswer4 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer4.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer4.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256.", - color: embedColor - }] - }) - } - const answer4_1 = answer4.first()!.content + const answer4 = await applicationQuestions(useranswer4, user, 256, "normal") + if (!answer4) return // fifth question await user.send({ @@ -279,32 +172,13 @@ export = { } }] }) - const answer5 = await user.dmChannel!.awaitMessages({ + const useranswer5 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer5.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer5.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256.", - color: embedColor - }] - }) - } - const answer5_1 = answer5.first()!.content + const answer5 = await applicationQuestions(useranswer5, user, 256, "normal") + if (!answer5) return // sixth question await user.send({ @@ -318,32 +192,13 @@ export = { } }] }) - const answer6 = await user.dmChannel!.awaitMessages({ + const useranswer6 = await user.dmChannel!.awaitMessages({ filter: m => m.author.id === user.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 - } - if (answer6.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } - if (answer6.first()!.content.length > 256) { - await user.send({ - embeds: [{ - description: "Max character limit is 256.", - color: embedColor - }] - }) - } - const answer6_1 = answer6.first()!.content + const answer6 = await applicationQuestions(useranswer6, user, 256, "normal") + if (!answer6) return await user.send({ embeds: [{ @@ -357,18 +212,8 @@ export = { 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 - } - if (final.first()!.attachments.size > 0) { - await user.send({ embeds: [attachments] }) - return - } + const confirm2 = await applicationQuestions(final, user, 0, "confirmation") + if (!confirm2) return await user.send({ embeds: [{ @@ -398,27 +243,27 @@ export = { fields: [ { name: rq(1), - value: "```" + answer1_1 + "```" + value: "```" + answer1 + "```" }, { name: rq(2), - value: "```" + answer2_1 + "```" + value: "```" + answer2 + "```" }, { name: rq(3), - value: "```" + answer3_1 + "```" + value: "```" + answer3 + "```" }, { name: rq(4), - value: "```" + answer4_1 + "```" + value: "```" + answer4 + "```" }, { name: rq(5), - value: "```" + answer5_1 + "```" + value: "```" + answer5 + "```" }, { name: rq(6), - value: "```" + answer6_1 + "```" + value: "```" + answer6 + "```" } ], footer: { diff --git a/src/utils/functions/applicationquestions.ts b/src/utils/functions/applicationquestions.ts new file mode 100644 index 0000000..ca10d29 --- /dev/null +++ b/src/utils/functions/applicationquestions.ts @@ -0,0 +1,74 @@ +import { embedColor } from "config/options" +import { Collection, EmbedBuilder, GuildMember, Message } from "discord.js" +import { getUUID } from "utils/Hypixel" + +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) +const attachments = new EmbedBuilder() + .setDescription("You have uploaded an attachment. Please do not upload images, videos, or GIFS.") + .setColor(embedColor) + + +export default async function applicationQuestions( + input: Collection>, + user: GuildMember, + length: number, + questiontype: "ign" | "confirmation" | "normal" +) { + if (questiontype === "confirmation") { + if (input.size === 0) { + await user.send({ embeds: [tooLong] }) + return false + } + if (input.first()!.content.toLowerCase() !== "yes") { + await user.send({ embeds: [cancelled] }) + return false + } + if (input.first()!.attachments.size > 0) { + await user.send({ embeds: [attachments] }) + return false + } + return true + } else { + if (input.size === 0) { + await user.send({ embeds: [tooLong] }) + return false + } + if (input.first()!.content.toLowerCase() === "cancel") { + await user.send({ embeds: [cancelled] }) + return false + } + if (input.first()!.attachments.size > 0) { + await user.send({ embeds: [attachments] }) + return false + } + if (input.first()!.content.length > length) { + await user.send({ + embeds: [{ + description: `Max character limit is ${length}.`, + color: embedColor + }] + }) + return false + } + if (questiontype === "ign") { + const uuid = await getUUID(input.first()!.content) + if (!uuid) { + await user.send({ + embeds: [{ + description: "That is not a valid Minecraft username.\n" + + "Application cancelled.", + color: embedColor + }] + }) + return false + } + return { answer: input.first()!.content, uuid: uuid } + } + return input!.first()!.content + } +} \ No newline at end of file