From e612106caaaed244ad4b2462dbb821c50ad22934 Mon Sep 17 00:00:00 2001 From: Taken Date: Tue, 25 Apr 2023 17:30:22 +0200 Subject: [PATCH] Updated and beautied check command --- commands/check.js | 244 ++++++++++++++++++++++------------------------ 1 file changed, 118 insertions(+), 126 deletions(-) diff --git a/commands/check.js b/commands/check.js index 483df83..ff71f87 100644 --- a/commands/check.js +++ b/commands/check.js @@ -1,147 +1,139 @@ -const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require('discord.js'); -const { bwfdkr, bwstars, bwwins, duelswins, swstars } = require('../config/reqs.json') -const getuuid = require('../utils/functions'); -const env = require('dotenv').config(); +const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require("discord.js"); +const { bwfdkr, bwstars, bwwins, duelswins, swstars } = require("../config/reqs.json"); +const getuuid = require("../utils/functions.js"); +const env = require("dotenv").config(); const hypixelApiKey = process.env.HYPIXELAPI; -const { color } = require('../config/options.json'); -const fetch = require('axios'); +const { color } = require("../config/options.json"); +const fetch = require("axios"); module.exports = { - name: 'check', - description: 'Check a player\'s stats.', - type: 'slash', + name: "check", + description: "Check a player's stats.", + type: "slash", - data: new SlashCommandBuilder() - .setName('check') - .setDescription('Check a player\'s stats.') - .addStringOption(option => - option - .setName('ign') - .setDescription('The player\'s IGN.') - .setRequired(true)) - .setDMPermission(false), + data: new SlashCommandBuilder() + .setName("check") + .setDescription("Check a player's stats.") + .addStringOption((option) => option.setName("ign").setDescription("The player's IGN.").setRequired(true)) + .setDMPermission(false), - async execute(interaction) { + async execute(interaction) { + await interaction.deferReply({}); - await interaction.deferReply({}) + 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 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")); - - if (!ign) { - await interaction.editReply('Please provide a player\'s IGN.') - return - } + if (!ign) { + await interaction.editReply("Please provide a player's IGN."); + return; + } - if (await getuuid(ign) === null) { - await interaction.editReply('That player doesn\'t exist. [Mojang]') - return - } + try { + await fetch(mojang + ign); + } catch (error) { + interaction.editReply("That player doesn't exist. [Mojang]"); + return; + } - const userUUID = await getuuid(ign); + const uuid = await fetch(mojang + ign); - try { - await fetch(slothPixel + userUUID); - } catch (error) { - interaction.editReply('That player doesn\'t exist. [Hypixel]') - return - } + try { + await fetch(slothPixel + uuid.data.id); + } catch (error) { + interaction.editReply("That player doesn't exist. [Hypixel]"); + return; + } - const stats = await fetch(slothPixel + userUUID); - const head = minotar + ign; + const stats = await fetch(slothPixel + uuid.data.id); + const head = minotar + ign; - if (!stats.data.uuid) { - interaction.editReply('That player doesn\'t exist. [Hypixel]') - return - } + if (!stats.data.uuid) { + interaction.editReply("That player doesn't exist. [Hypixel]"); + return; + } - const rank_formatted = stats.data.rank_formatted - const rank2 = rank_formatted.replace(/&[0-9a-fk-or]/g, "") + const rank_formatted = stats.data.rank_formatted; + const rank2 = rank_formatted.replace(/&[0-9a-fk-or]/g, ""); - if (rank2 === "") { - var rank = "" - } else { - var rank = rank2 + " " - } + if (rank2 === "") { + var rank = ""; + } else { + var rank = rank2 + " "; + } - try { - const guildCheck = await fetch(guildAPI + userUUID); - var guildName = guildCheck.data.name - } catch (error) { - var guildName = "None" - } + try { + const guildCheck = await fetch(guildAPI + userUUID); + var guildName = guildCheck.data.name; + } catch (error) { + var guildName = "None"; + } - const hsbwstars = stats.data.stats.BedWars.level - const hsbwfkdr = stats.data.stats.BedWars.final_k_d - const hsbwwins = stats.data.stats.BedWars.wins - const hsswstars = stats.data.stats.SkyWars.level - const hsduelswins = stats.data.stats.Duels.general.wins + const hsbwstars = stats.data.stats.BedWars.level; + const hsbwfkdr = stats.data.stats.BedWars.final_k_d; + const hsbwwins = stats.data.stats.BedWars.wins; + const hsswstars = stats.data.stats.SkyWars.level; + const hsduelswins = stats.data.stats.Duels.general.wins; - if (hsbwstars < bwstars || hsbwfkdr < bwfdkr || hsbwwins < bwwins) { - var bwtitle = " This player does not meet the BedWars requirements." - } else { - var bwtitle = " This player meets the BedWars requirements." - } + if (hsbwstars < bwstars || hsbwfkdr < bwfdkr || hsbwwins < bwwins) { + var bwtitle = " This player does not meet the BedWars requirements."; + } else { + var bwtitle = " This player meets the BedWars requirements."; + } - if (hsswstars < swstars) { - var swtitle = " This player does not meet the SkyWars requirements." - } else { - var swtitle = " This player meets the SkyWars requirements." - } + if (hsswstars < swstars) { + var swtitle = " This player does not meet the SkyWars requirements."; + } else { + var swtitle = " This player meets the SkyWars requirements."; + } - if (hsduelswins < duelswins) { - var duelstitle = " This player does not meet the Duels requirements." - } else { - var duelstitle = " This player meets the Duels requirements." - } + if (hsduelswins < duelswins) { + var duelstitle = " This player does not meet the Duels requirements."; + } else { + var duelstitle = " This player meets the Duels requirements."; + } - try { - const guildCheck = await fetch(guildAPI + userUUID); - const tag_formatted = guildCheck.data.tag_formatted - const guildTag2 = tag_formatted.replace(/&[0-9a-fk-or]/g, "") - var guildTag = " " + guildTag2 - } catch (error) { - var guildTag = "" - } + try { + const guildCheck = await fetch(guildAPI + userUUID); + const tag_formatted = guildCheck.data.tag_formatted; + const guildTag2 = tag_formatted.replace(/&[0-9a-fk-or]/g, ""); + var guildTag = " " + guildTag2; + } catch (error) { + var guildTag = ""; + } - await interaction.editReply({ - embeds: [{ - title: rank + stats.data.username + guildTag, - description: "**Network Level:** `" + stats.data.level.toString() + "`\n" + - "**Current Guild:** `" + guildName + "`", - color: embedColor, - thumbnail: { - url: head - }, - footer: { - text: interaction.guild.name + " | Developed by @Taken#0002", - icon_url: interaction.guild.iconURL() - }, - fields: [ - { - name: bwtitle, - value: "**➺ Stars:** `" + stats.data.stats.BedWars.level.toString() + " / " + bwstars.toString() + "`\n" + - "**➺ FKDR:** `" + stats.data.stats.BedWars.final_k_d.toString() + " / " + bwfdkr.toString() + "`\n" + - "**➺ Wins:** `" + stats.data.stats.BedWars.wins.toString() + " / " + bwwins.toString() + "`" - }, - { - name: swtitle, - value: "**➺ Stars:** `" + stats.data.stats.SkyWars.level.toFixed(2).toString() + " / " + swstars.toString() + "`\n" + - "**➺ KDR:** `" + stats.data.stats.SkyWars.kill_death_ratio.toString() + "`\n" + - "**➺ Wins:** `" + stats.data.stats.SkyWars.wins.toString() + "`" - }, - { - name: duelstitle, - value: "**➺ Wins:** `" + stats.data.stats.Duels.general.wins.toString() + " / " + duelswins.toString() + "`\n" + - "**➺ KDR:** `" + stats.data.stats.Duels.general.kd_ratio.toFixed(2).toString() + "`\n" + - "**➺ WLR:** `" + stats.data.stats.Duels.general.win_loss_ratio.toFixed(2).toString() + "`" - } - ] - }] - }) - } -}; \ No newline at end of file + await interaction.editReply({ + embeds: [ + { + title: rank + stats.data.username + guildTag, + description: "**Network Level:** `" + stats.data.level.toString() + "`\n" + "**Current Guild:** `" + guildName + "`", + color: embedColor, + thumbnail: { + url: head + }, + footer: { + text: interaction.guild.name + " | Developed by @Taken#0002", + icon_url: interaction.guild.iconURL() + }, + fields: [ + { + name: bwtitle, + value: "**➺ Stars:** `" + stats.data.stats.BedWars.level.toString() + " / " + bwstars.toString() + "`\n" + "**➺ FKDR:** `" + stats.data.stats.BedWars.final_k_d.toString() + " / " + bwfdkr.toString() + "`\n" + "**➺ Wins:** `" + stats.data.stats.BedWars.wins.toString() + " / " + bwwins.toString() + "`" + }, + { + name: swtitle, + value: "**➺ Stars:** `" + stats.data.stats.SkyWars.level.toFixed(2).toString() + " / " + swstars.toString() + "`\n" + "**➺ KDR:** `" + stats.data.stats.SkyWars.kill_death_ratio.toString() + "`\n" + "**➺ Wins:** `" + stats.data.stats.SkyWars.wins.toString() + "`" + }, + { + name: duelstitle, + value: "**➺ Wins:** `" + stats.data.stats.Duels.general.wins.toString() + " / " + duelswins.toString() + "`\n" + "**➺ KDR:** `" + stats.data.stats.Duels.general.kd_ratio.toFixed(2).toString() + "`\n" + "**➺ WLR:** `" + stats.data.stats.Duels.general.win_loss_ratio.toFixed(2).toString() + "`" + } + ] + } + ] + }); + } +};