Moved verify to use hypixel api

This commit is contained in:
2023-07-02 20:27:49 +02:00
parent 6b9add215b
commit 3481aba390

View File

@@ -25,10 +25,11 @@ module.exports = {
const user = interaction.guild.members.cache.get(user1.id); const user = interaction.guild.members.cache.get(user1.id);
const ign = interaction.options.getString("ign"); const ign = interaction.options.getString("ign");
const mojang = "https://api.mojang.com/users/profiles/minecraft/"; const mojang = "https://api.mojang.com/users/profiles/minecraft/";
const slothPixel = "https://api.slothpixel.me/api/players/"; const hypixel = "https://api.hypixel.net/player"
const guildAPI = "https://api.slothpixel.me/api/guilds/"; const guildAPI = "https://api.hypixel.net/guild"
const minotar = "https://minotar.net/helm/"; const minotar = "https://minotar.net/helm/";
const embedColor = Number(color.replace("#", "0x")); 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 });
@@ -52,27 +53,32 @@ module.exports = {
const userCheck = await fetch(mojang + ign); const userCheck = await fetch(mojang + ign);
const userUUID = userCheck.data.id; const userUUID = userCheck.data.id;
try { const player = hypixel + "?key=" + hypixelApiKey + "&uuid=" + userUUID
await fetch(slothPixel + userUUID); const stats = await fetch(player);
} catch (err) {
interaction.editReply("That player doesn't exist. [Hypixel]"); if (!stats.data.player) {
interaction.editReply({
embeds: [{
description: "That player hasn't played Hypixel before.",
color: embedColor
}]
});
return; return;
} }
const hypixelCheck = await fetch(slothPixel + userUUID);
const head = minotar + ign;
if (user1.discriminator === "0") { if (user1.discriminator === "0") {
var username = user1.username var username = user1.username
} else { } else {
var username = user1.username + "#" + user1.discriminator var username = user1.username + "#" + user1.discriminator
} }
if (hypixelCheck.data.links.DISCORD !== username) { const linkedDiscord = stats.data.player.socialMedia.links.DISCORD
if (linkedDiscord !== username) {
interaction.editReply({ interaction.editReply({
embeds: [ embeds: [
{ {
description: "<a:cross_a:1087808606897983539> The discord tag for `" + userCheck.data.name + "` is not `" + username + "`. Please link your discord account to your hypixel account.\n" + description: "<a:cross_a:1087808606897983539> 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 #** ", "**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 color: embedColor
} }
@@ -81,14 +87,16 @@ module.exports = {
return; return;
} }
try { const guild = guildAPI + "?key=" + hypixelApiKey + "&player=" + userUUID
const guildCheck = await fetch(guildAPI + userUUID); const guildCheck = await fetch(guild);
var responseGuildID = guildCheck.data.id;
} catch (err) { if (!guildCheck.data.guild) {
var responseGuildID = null; var guildID = null
} else {
var guildID = guildCheck.data.guild._id
} }
if (responseGuildID !== hypixelGuildID) { if (guildID !== hypixelGuildID) {
await user.roles.add(defaultMember, "Verification"); await user.roles.add(defaultMember, "Verification");
await interaction.editReply({ await interaction.editReply({
@@ -110,39 +118,38 @@ module.exports = {
return; return;
} }
const guildCheck = await fetch(guildAPI + userUUID); const GuildMembers = guildCheck.data.guild.members
const GuildMembers = await guildCheck.data.members; const guildRank = GuildMembers.find((member) => member.uuid === stats.data.player.uuid).rank;
const guildRank = GuildMembers.find((member) => member.uuid === hypixelCheck.data.uuid).rank;
if (guildRank === "Guild Master" && responseGuildID === hypixelGuildID) { if (guildRank === "Guild Master" && guildID === hypixelGuildID) {
await user.roles.add(gm, "Verification"); await user.roles.add(gm, "Verification");
await user.roles.add(guildRole, "Verification"); await user.roles.add(guildRole, "Verification");
await user.roles.add(guildStaff, "Verification"); await user.roles.add(guildStaff, "Verification");
} }
if (guildRank === "Manager" && responseGuildID === hypixelGuildID) { if (guildRank === "Manager" && guildID === hypixelGuildID) {
await user.roles.add(manager, "Verification"); await user.roles.add(manager, "Verification");
await user.roles.add(guildRole, "Verification"); await user.roles.add(guildRole, "Verification");
await user.roles.add(guildStaff, "Verification"); await user.roles.add(guildStaff, "Verification");
} }
if (guildRank === "Moderator" && responseGuildID === hypixelGuildID) { if (guildRank === "Moderator" && guildID === hypixelGuildID) {
await user.roles.add(moderator, "Verification"); await user.roles.add(moderator, "Verification");
await user.roles.add(guildRole, "Verification"); await user.roles.add(guildRole, "Verification");
await user.roles.add(guildStaff, "Verification"); await user.roles.add(guildStaff, "Verification");
} }
if (guildRank === "Beast" && responseGuildID === hypixelGuildID) { if (guildRank === "Beast" && guildID === hypixelGuildID) {
await user.roles.add(beast, "Verification"); await user.roles.add(beast, "Verification");
await user.roles.add(guildRole, "Verification"); await user.roles.add(guildRole, "Verification");
} }
if (guildRank === "Member" && responseGuildID === hypixelGuildID) { if (guildRank === "Member" && guildID === hypixelGuildID) {
await user.roles.add(member, "Verification"); await user.roles.add(member, "Verification");
await user.roles.add(guildRole, "Verification"); await user.roles.add(guildRole, "Verification");
} }
if (guildRank === "Trial Member" && responseGuildID === hypixelGuildID) { if (guildRank === "Trial Member" && guildID === hypixelGuildID) {
await user.roles.add(trialmember, "Verification"); await user.roles.add(trialmember, "Verification");
await user.roles.add(guildRole, "Verification"); await user.roles.add(guildRole, "Verification");
} }
@@ -161,7 +168,7 @@ module.exports = {
embeds: [ embeds: [
{ {
title: interaction.guild.name, title: interaction.guild.name,
description: "You have successfully verified `" + username + "` with the account `" + hypixelCheck.data.username + "`.", description: "You have successfully verified `" + username + "` with the account `" + stats.data.player.displayname + "`.",
color: embedColor, color: embedColor,
thumbnail: { thumbnail: {
url: head url: head