From 3481aba390af4967234b6602e80bff308dd65855 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 2 Jul 2023 20:27:49 +0200 Subject: [PATCH] Moved verify to use hypixel api --- commands/verify.js | 287 +++++++++++++++++++++++---------------------- 1 file changed, 147 insertions(+), 140 deletions(-) diff --git a/commands/verify.js b/commands/verify.js index 19604f7..cb2d9fe 100644 --- a/commands/verify.js +++ b/commands/verify.js @@ -8,170 +8,177 @@ const mongoose = require("mongoose"); const { gm, manager, moderator, beast, member, trialmember, guildRole, guildStaff, defaultMember } = require("../config/roles.json"); module.exports = { - name: "verify", - description: "Verify yourself as a member of the server.", - type: "slash", + name: "verify", + description: "Verify yourself as a member of the server.", + type: "slash", - data: new SlashCommandBuilder() - .setName("verify") - .setDescription("Verify yourself as a member of the server.") - .addStringOption((option) => option.setName("ign").setDescription("Your in-game name.")) - .setDMPermission(false), + data: new SlashCommandBuilder() + .setName("verify") + .setDescription("Verify yourself as a member of the server.") + .addStringOption((option) => option.setName("ign").setDescription("Your in-game name.")) + .setDMPermission(false), - async execute(interaction) { - await interaction.deferReply(); + async execute(interaction) { + await interaction.deferReply(); - const user1 = interaction.user - const user = interaction.guild.members.cache.get(user1.id); - const ign = interaction.options.getString("ign"); - const mojang = "https://api.mojang.com/users/profiles/minecraft/"; - const slothPixel = "https://api.slothpixel.me/api/players/"; - const guildAPI = "https://api.slothpixel.me/api/guilds/"; - const minotar = "https://minotar.net/helm/"; - const embedColor = Number(color.replace("#", "0x")); + const user1 = interaction.user + const user = interaction.guild.members.cache.get(user1.id); + const ign = interaction.options.getString("ign"); + const mojang = "https://api.mojang.com/users/profiles/minecraft/"; + const hypixel = "https://api.hypixel.net/player" + const guildAPI = "https://api.hypixel.net/guild" + const minotar = "https://minotar.net/helm/"; + const embedColor = Number(color.replace("#", "0x")); + const head = minotar + ign; - const verifyData = await verify.findOne({ userID: user.id }); + const verifyData = await verify.findOne({ userID: user.id }); - if (verifyData) { - interaction.editReply("You are already verified."); - return; - } + if (verifyData) { + interaction.editReply("You are already verified."); + return; + } - if (!ign) { - interaction.editReply("Please provide a player's IGN."); - return; - } + if (!ign) { + interaction.editReply("Please provide a player's IGN."); + return; + } - try { - await fetch(mojang + ign); - } catch (err) { - interaction.editReply("That player doesn't exist. [Mojang]"); - return; - } + try { + await fetch(mojang + ign); + } catch (err) { + interaction.editReply("That player doesn't exist. [Mojang]"); + return; + } - const userCheck = await fetch(mojang + ign); - const userUUID = userCheck.data.id; + const userCheck = await fetch(mojang + ign); + const userUUID = userCheck.data.id; - try { - await fetch(slothPixel + userUUID); - } catch (err) { - interaction.editReply("That player doesn't exist. [Hypixel]"); - return; - } + const player = hypixel + "?key=" + hypixelApiKey + "&uuid=" + userUUID + const stats = await fetch(player); - const hypixelCheck = await fetch(slothPixel + userUUID); - const head = minotar + ign; + if (!stats.data.player) { + interaction.editReply({ + embeds: [{ + description: "That player hasn't played Hypixel before.", + color: embedColor + }] + }); + return; + } - if (user1.discriminator === "0") { - var username = user1.username - } else { - var username = user1.username + "#" + user1.discriminator - } + if (user1.discriminator === "0") { + var username = user1.username + } else { + var username = user1.username + "#" + user1.discriminator + } - if (hypixelCheck.data.links.DISCORD !== username) { - interaction.editReply({ - embeds: [ - { - description: " The discord tag for `" + userCheck.data.name + "` is not `" + username + "`. Please link your discord account to your hypixel account.\n" + - "**If you are are using a new username then you will have to set your discord on hypixel to the new username without the #** ", - color: embedColor - } - ] - }); - return; - } + const linkedDiscord = stats.data.player.socialMedia.links.DISCORD - try { - const guildCheck = await fetch(guildAPI + userUUID); - var responseGuildID = guildCheck.data.id; - } catch (err) { - var responseGuildID = null; - } + if (linkedDiscord !== username) { + interaction.editReply({ + embeds: [ + { + description: " The discord tag for `" + userCheck.data.name + "` is not `" + username + "`. Please link your discord account `" + username + "` to your hypixel account.\n" + + "**If you are are using a new username then you will have to set your discord on hypixel to the new username without the #** ", + color: embedColor + } + ] + }); + return; + } - if (responseGuildID !== hypixelGuildID) { - await user.roles.add(defaultMember, "Verification"); + const guild = guildAPI + "?key=" + hypixelApiKey + "&player=" + userUUID + const guildCheck = await fetch(guild); - await interaction.editReply({ - embeds: [ - { - title: interaction.guild.name, - description: " You have successfully verified `" + username + "` with the account `" + hypixelCheck.data.username + "`.", - color: embedColor, - thumbnail: { - url: head - }, - footer: { - icon_url: interaction.guild.iconURL(), - text: interaction.guild.name + " | Developed by Taken#0002" - } - } - ] - }); - return; - } + if (!guildCheck.data.guild) { + var guildID = null + } else { + var guildID = guildCheck.data.guild._id + } - const guildCheck = await fetch(guildAPI + userUUID); - const GuildMembers = await guildCheck.data.members; - const guildRank = GuildMembers.find((member) => member.uuid === hypixelCheck.data.uuid).rank; + if (guildID !== hypixelGuildID) { + await user.roles.add(defaultMember, "Verification"); - if (guildRank === "Guild Master" && responseGuildID === hypixelGuildID) { - await user.roles.add(gm, "Verification"); - await user.roles.add(guildRole, "Verification"); - await user.roles.add(guildStaff, "Verification"); - } + await interaction.editReply({ + embeds: [ + { + title: interaction.guild.name, + description: " You have successfully verified `" + username + "` with the account `" + hypixelCheck.data.username + "`.", + color: embedColor, + thumbnail: { + url: head + }, + footer: { + icon_url: interaction.guild.iconURL(), + text: interaction.guild.name + " | Developed by Taken#0002" + } + } + ] + }); + return; + } - if (guildRank === "Manager" && responseGuildID === hypixelGuildID) { - await user.roles.add(manager, "Verification"); - await user.roles.add(guildRole, "Verification"); - await user.roles.add(guildStaff, "Verification"); - } + const GuildMembers = guildCheck.data.guild.members + const guildRank = GuildMembers.find((member) => member.uuid === stats.data.player.uuid).rank; - if (guildRank === "Moderator" && responseGuildID === hypixelGuildID) { - await user.roles.add(moderator, "Verification"); - await user.roles.add(guildRole, "Verification"); - await user.roles.add(guildStaff, "Verification"); - } + if (guildRank === "Guild Master" && guildID === hypixelGuildID) { + await user.roles.add(gm, "Verification"); + await user.roles.add(guildRole, "Verification"); + await user.roles.add(guildStaff, "Verification"); + } - if (guildRank === "Beast" && responseGuildID === hypixelGuildID) { - await user.roles.add(beast, "Verification"); - await user.roles.add(guildRole, "Verification"); - } + if (guildRank === "Manager" && guildID === hypixelGuildID) { + await user.roles.add(manager, "Verification"); + await user.roles.add(guildRole, "Verification"); + await user.roles.add(guildStaff, "Verification"); + } - if (guildRank === "Member" && responseGuildID === hypixelGuildID) { - await user.roles.add(member, "Verification"); - await user.roles.add(guildRole, "Verification"); - } + if (guildRank === "Moderator" && guildID === hypixelGuildID) { + await user.roles.add(moderator, "Verification"); + await user.roles.add(guildRole, "Verification"); + await user.roles.add(guildStaff, "Verification"); + } - if (guildRank === "Trial Member" && responseGuildID === hypixelGuildID) { - await user.roles.add(trialmember, "Verification"); - await user.roles.add(guildRole, "Verification"); - } + if (guildRank === "Beast" && guildID === hypixelGuildID) { + await user.roles.add(beast, "Verification"); + await user.roles.add(guildRole, "Verification"); + } - await user.roles.add(defaultMember, "Verification"); + if (guildRank === "Member" && guildID === hypixelGuildID) { + await user.roles.add(member, "Verification"); + await user.roles.add(guildRole, "Verification"); + } - const newVerify = new verify({ - _id: new mongoose.Types.ObjectId(), - userID: user.id, - uuid: userUUID - }); + if (guildRank === "Trial Member" && guildID === hypixelGuildID) { + await user.roles.add(trialmember, "Verification"); + await user.roles.add(guildRole, "Verification"); + } - await newVerify.save(); + await user.roles.add(defaultMember, "Verification"); - await interaction.editReply({ - embeds: [ - { - title: interaction.guild.name, - description: "You have successfully verified `" + username + "` with the account `" + hypixelCheck.data.username + "`.", - color: embedColor, - thumbnail: { - url: head - }, - footer: { - icon_url: interaction.guild.iconURL(), - text: interaction.guild.name + " | Developed by Taken#0002" - } - } - ] - }); - } + const newVerify = new verify({ + _id: new mongoose.Types.ObjectId(), + userID: user.id, + uuid: userUUID + }); + + await newVerify.save(); + + await interaction.editReply({ + embeds: [ + { + title: interaction.guild.name, + description: "You have successfully verified `" + username + "` with the account `" + stats.data.player.displayname + "`.", + color: embedColor, + thumbnail: { + url: head + }, + footer: { + icon_url: interaction.guild.iconURL(), + text: interaction.guild.name + " | Developed by Taken#0002" + } + } + ] + }); + } };