const { CommandInteraction, EmbedBuilder, ButtonStyle, ComponentType, ButtonBuilder } = require("discord.js"); const snekfetch = require('snekfetch'); const firebase = require('firebase'); const config = require('../../config.json'); const noblox = require("noblox.js"); const { ActionRowBuilder } = require("@discordjs/builders"); module.exports = { name: "interactionCreate", async execute(interaction) { if (!interaction.isButton()) return; if (interaction.customId !== "welcomeVerify" && interaction.customId !== "welcomeUpdateRoles") return; const member = interaction.member; const verifiedRole = interaction.guild.roles.cache.find(role => role.name === "Verified"); const collectorTimeout = 60 * 1000; const embed = new EmbedBuilder() .setColor("#3A5874") .setFooter({ text: "Deadzone Reincarnated" }) .setTimestamp(); if (interaction.customId == "welcomeUpdateRoles") { embed.setDescription("System is currently under maintenance. Please try again later."); return interaction.reply({ embeds: [ embed ], ephemeral: true }); } else if (interaction.customId == "welcomeVerify") { const debug = true; // Toggle to disable verification and enable maintenance mode if (interaction.user.id !== "187535538008358912" && debug == true) { embed.setDescription("System is currently under maintenance. Please try again later."); return interaction.reply({ embeds: [ embed ], ephemeral: true }); }; if (member.roles.cache.some(role => role.name === "Verified")) { embed.setColor("#743A3A") .setTitle("Verification Prompt") .setDescription("You are already verified, consider clicking the Update Roles button instead."); return interaction.reply({ embeds: [ embed ], ephemeral: true }); }; embed.setDescription("This prompt will continue in your DMs, please check your messages."); interaction.reply({ embeds: [ embed ], ephemeral: true }); interaction.user.createDM().then(async (channel) => { const verificationEmbed = new EmbedBuilder() .setColor("#3A5874") .setTitle("Verification Prompt") .setDescription("Please write your username below. or reply with `cancel` to cancel the prompt.") .setFooter({ text: "Deadzone Reincarnated | Cancelling in 60 seconds" }) .setTimestamp(); const row = new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId("veri_code_next") .setLabel("Next") .setStyle(ButtonStyle.Primary), new ButtonBuilder() .setCustomId("veri_code_cancel") .setLabel("Cancel") .setStyle(ButtonStyle.Danger) ); const verificationFailedEmbed = new EmbedBuilder() .setColor("#743A3A") .setTitle("Verification Prompt") .setDescription("Prompt cancelled.") .setFooter({ text: "Deadzone Reincarnated | Prompt cancelled" }) .setTimestamp(); const filter = m => !m.author.bot; const collectorA = channel.createMessageCollector({ filter, time: collectorTimeout }); channel.send({ embeds: [ verificationEmbed ] }); collectorA.on("collect", async (m) => { collectorA.stop(); const member = await noblox.getIdFromUsername(m.content); if (m.content.toLowerCase() == "cancel") { interaction.user.send({ embeds: [ verificationFailedEmbed ] }); }; var { body } = await snekfetch.get(`${config.firebaseURL}verified/${member}.json`); if (body) { var { body } = await snekfetch.get(`https://users.roblox.com/v1/users/${body.linked}`); await interaction.member.roles.add(verifiedRole); var displayName; if (body.displayName === body.name) { displayName = body.name; } else { displayName = body.displayName; }; interaction.member.setNickname(`${displayName | body.name} | ${body.id}`); verificationEmbed.setDescription({ content: `Welcome to the server, ${displayName}!`, ephemeral: true }); return interaction.user.send({ embeds: [ verificationEmbed ] }); } else { const userId = await noblox.getIdFromUsername(m.content); var { body } = await snekfetch.get(`${config.firebaseURL}pending/${userId}.json`); if (body) { verificationFailedEmbed.setDescription("You can not have more than one verification prompt active at a time. Cancel your current prompt and try again."); return interaction.user.send({ embeds: [ verificationFailedEmbed ] }); } else { var { body } = await snekfetch.get(`https://users.roblox.com/v1/users/${userId}`).catch(() => { verificationFailedEmbed.setDescription(`The username \`${m.content}\` is not a valid username. Please check your spelling and try again.`); return interaction.user.send({ embeds: [ verificationFailedEmbed ] }); }); if (body == undefined) return; // to prevent unhanded promise rejection errors in console if (!body.name) { verificationFailedEmbed.setDescription(`The username \`${m.content}\` is not a valid username. Please check your spelling and try again.`); return interaction.user.send({ embeds: [ verificationFailedEmbed ] }); }; var displayName; if (body.displayName === body.name) { displayName = body.name; } else { displayName = body.displayName; }; firebase.database().ref(`pending/${userId}`).set(member); verificationEmbed.setDescription(`To verify your account ownership, join the verification game [here](${config.verificationLink}. Once you have joined follow the instructions in the game.)`); interaction.user.send({ embeds: [ verificationEmbed ], components: [ row ] }).then(async (message) => { const filter = i => i.user.id === member.id; const collector = message.channel.createMessageComponentCollector({ filter, componentType: ComponentType.Button, time: collectorTimeout }); collector.on("collect", async (i) => { i.deferUpdate(); if (i.customId == "veri_code_next") { var { body } = await snekfetch.get(`${config.firebaseURL}verified/${member}.json`); if (body) { await interaction.member.roles.add(verifiedRole); interaction.member.setNickname(`${displayName} | ${body.linked}`); verificationEmbed.setDescription(`Account ownership verified, welcome to the server ${displayName}!`); message.edit({ embeds: [ verificationEmbed ] }); } else { verificationFailedEmbed.setDescription(`Sorry, but it appears that you haven't completed the steps in the [verification game](${config.verificationLink}\). Please complete the steps and click Next.`) .setFooter({ text: "Deadzone Reincarnated | Cancelling in 60 seconds" }); message.edit({ embeds: [ verificationFailedEmbed ], components: [ row ] }); } } else if (i.customId == "veri_code_cancel") { var { body } = await snekfetch.get(`$config.firebaseURL}pending/${member}.json`); if (body) { firebase.database.ref(`pending/${member}`).set({}); }; verificationFailedEmbed.setDescription("Prompt cancelled.") .setFooter({ text: "Deadzone Reincarnated | Prompt cancelled" }); return message.edit({ embeds: [ verificationFailedEmbed ], components: [] }); } }); collector.on("end", async (collected) => { var { body } = await snekfetch.get(`${config.firebaseURL}pending/${member}.json`); if (body) { firebase.database().ref(`pending/${member}`).set({}); } verificationFailedEmbed.setDescription("Prompt timed out.") .setFooter({ text: "Deadzone Reincarnated | Prompt timed out" }); return message.edit({ embeds: [ verificationFailedEmbed ], components: [] }); }); }); } } }); collectorA.on("end", collected => { if (collected.size == 0) { verificationFailedEmbed.setDescription("Prompt cancelled."); return interaction.user.send({ embeds: [ verificationFailedEmbed ] }); } }); }); } } };