Updated check command and button to use util func

This commit is contained in:
2023-11-16 23:28:06 +01:00
parent 79b3216686
commit 2873664324
2 changed files with 59 additions and 84 deletions

View File

@@ -1,9 +1,7 @@
const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require("discord.js"); const { SlashCommandBuilder } = require("discord.js");
const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require("../config/reqs.json"); const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require("../config/reqs.json");
const hypixelApiKey = process.env.HYPIXELAPIKEY;
const { color } = require("../config/options.json"); const { color } = require("../config/options.json");
const fetch = require("axios"); const { hypixelLevel, bedwarsLevel, skywarsLevel, getUUID, getPlayer, getGuild, getHeadURL } = require("../utils/utils.js");
const { hypixelLevel, bedwarsLevel, skywarsLevel } = require("../utils/utils.js");
module.exports = { module.exports = {
name: "check", name: "check",
@@ -25,21 +23,15 @@ module.exports = {
await interaction.deferReply({}); await interaction.deferReply({});
const ign = interaction.options.getString("ign"); 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 embedColor = Number(color.replace("#", "0x"));
const head = minotar + ign;
if (!ign) { if (!ign) {
await interaction.editReply("Please provide a player's IGN."); await interaction.editReply("Please provide a player's IGN.");
return; return;
} }
try { const uuid = await getUUID(ign);
var userCheck = await fetch(mojang + ign); if (!uuid) {
} catch (error) {
interaction.editReply({ interaction.editReply({
embeds: [ embeds: [
{ description: "That player doesn't exist.", color: embedColor } { description: "That player doesn't exist.", color: embedColor }
@@ -48,12 +40,9 @@ module.exports = {
return; return;
} }
const uuid = userCheck.data.id; const head = await getHeadURL(ign);
const player = await getPlayer(uuid)
const player = hypixel + "?key=" + hypixelApiKey + "&uuid=" + uuid if (!player) {
const stats = await fetch(player);
if (!stats.data.player) {
interaction.editReply({ interaction.editReply({
embeds: [{ embeds: [{
description: "That player hasn't played Hypixel before.", description: "That player hasn't played Hypixel before.",
@@ -63,8 +52,8 @@ module.exports = {
return; return;
} }
const rank2 = stats.data.player.newPackageRank; const rank2 = player.newPackageRank;
const monthlyRank = stats.data.player.monthlyPackageRank; const monthlyRank = player.monthlyPackageRank;
if (rank2 === 'VIP') { if (rank2 === 'VIP') {
var rank = "[VIP] " var rank = "[VIP] "
@@ -78,52 +67,50 @@ module.exports = {
var rank = "[MVP++] " var rank = "[MVP++] "
} }
const guild = guildAPI + "?key=" + hypixelApiKey + "&player=" + uuid const guild = await getGuild(uuid)
const guildCheck = await fetch(guild); if (!guild) {
if (!guildCheck.data.guild) {
var guildName = "None"; var guildName = "None";
} else { } else {
var guildName = guildCheck.data.guild.name; var guildName = guild.name;
} }
if (!guildCheck.data.guild) { if (!guild) {
var guildTag = "" var guildTag = ""
} else if (!guildCheck.data.guild.tag) { } else if (!guild.tag) {
var guildTag = "" var guildTag = ""
} else { } else {
var guildTag = " [" + guildCheck.data.guild.tag + "]" var guildTag = " [" + guild.tag + "]"
} }
//bedwars level //bedwars level
const hsbwexp = stats.data.player.stats.Bedwars.Experience; const hsbwexp = player.stats.Bedwars.Experience;
const hsbwstars = bedwarsLevel(hsbwexp); const hsbwstars = bedwarsLevel(hsbwexp);
// bedwars fkdr // bedwars fkdr
const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars; const hsbwfk = player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars; const hsbwfd = player.stats.Bedwars.final_deaths_bedwars;
const hsbwfkdr = hsbwfk / hsbwfd; const hsbwfkdr = hsbwfk / hsbwfd;
// bedwars wins // bedwars wins
const hsbwwins = stats.data.player.stats.Bedwars.wins_bedwars; const hsbwwins = player.stats.Bedwars.wins_bedwars;
// skywars level // skywars level
const hsswexp = stats.data.player.stats.SkyWars.skywars_experience; const hsswexp = player.stats.SkyWars.skywars_experience;
const hsswstars = skywarsLevel(hsswexp); const hsswstars = skywarsLevel(hsswexp);
// skywars kdr // skywars kdr
const hsswkills = stats.data.player.stats.SkyWars.kills; const hsswkills = player.stats.SkyWars.kills;
const hsswdeaths = stats.data.player.stats.SkyWars.deaths; const hsswdeaths = player.stats.SkyWars.deaths;
const hsswkd = hsswkills / hsswdeaths; const hsswkd = hsswkills / hsswdeaths;
//skywars wins //skywars wins
const hsswwins = stats.data.player.stats.SkyWars.wins; const hsswwins = player.stats.SkyWars.wins;
// dueks kdr // dueks kdr
const hsduelskills = stats.data.player.stats.Duels.kills const hsduelskills = player.stats.Duels.kills
const hsduelsdeaths = stats.data.player.stats.Duels.deaths const hsduelsdeaths = player.stats.Duels.deaths
const hsduelskd = hsduelskills / hsduelsdeaths const hsduelskd = hsduelskills / hsduelsdeaths
// duels wins // duels wins
const hsduelswins = stats.data.player.stats.Duels.wins; const hsduelswins = player.stats.Duels.wins;
// duels wlr // duels wlr
const hsduelslosses = stats.data.player.stats.Duels.losses; const hsduelslosses = player.stats.Duels.losses;
const hsduelswlr = hsduelswins / hsduelslosses; const hsduelswlr = hsduelswins / hsduelslosses;
// network level // network level
const hypixelExp = stats.data.player.networkExp; const hypixelExp = player.networkExp;
const level = hypixelLevel(hypixelExp); const level = hypixelLevel(hypixelExp);
if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) { if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) {
@@ -152,12 +139,14 @@ module.exports = {
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
title: rank + stats.data.player.displayname + guildTag, title: rank + player.displayname + guildTag,
description: "**Network Level:** `" + description: "**Network Level:** `" +
level.toFixed(2).toString() + "`\n" + level.toFixed(2).toString() + "`\n" +
"**Current Guild:** `" + guildName + "`", "**Current Guild:** `" + guildName + "`",
color: embedColor, color: embedColor,
thumbnail: { url: head }, thumbnail: {
url: head
},
footer: { footer: {
text: interaction.guild.name + " | Developed by @Taken#0002", text: interaction.guild.name + " | Developed by @Taken#0002",
icon_url: interaction.guild.iconURL() icon_url: interaction.guild.iconURL()

View File

@@ -1,9 +1,7 @@
const { color } = require('../../config/options.json'); const { color } = require('../../config/options.json');
const fetch = require('axios');
const guildapp = require('../../schemas/guildAppSchema.js'); const guildapp = require('../../schemas/guildAppSchema.js');
const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require('../../config/reqs.json'); const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require('../../config/reqs.json');
const hypixelApiKey = process.env.HYPIXELAPIKEY; const { hypixelLevel, bedwarsLevel, skywarsLevel, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js");
const { hypixelLevel, bedwarsLevel, skywarsLevel } = require("../../utils/utils.js");
module.exports = { module.exports = {
name: 'checkstats', name: 'checkstats',
@@ -19,24 +17,12 @@ module.exports = {
const message = interaction.message; const message = interaction.message;
const embed = message.embeds[0]; const embed = message.embeds[0];
const applicantId = embed.footer.text.split(" ")[1] const applicantId = embed.footer.text.split(" ")[1]
const guildappdata = await guildapp.findOne({ userID: applicantId }) const guildappdata = await guildapp.findOne({ userID: applicantId })
const uuid = guildappdata.uuid; const uuid = guildappdata.uuid;
const mojang = "https://api.mojang.com/user/profile/"
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 embedColor = Number(color.replace("#", "0x"));
const userCheck = await fetch(mojang + uuid); const player = await getPlayer(uuid)
const ign = userCheck.data.name; if (!player) {
const head = minotar + ign;
const player = hypixel + "?key=" + hypixelApiKey + "&uuid=" + uuid
const stats = await fetch(player);
if (!stats.data.player) {
interaction.editReply({ interaction.editReply({
embeds: [{ embeds: [{
description: "That player hasn't played Hypixel before.", description: "That player hasn't played Hypixel before.",
@@ -46,8 +32,10 @@ module.exports = {
return; return;
} }
const rank2 = stats.data.player.newPackageRank; const ign = player.playername
const monthlyRank = stats.data.player.monthlyPackageRank; const head = await getHeadURL(ign)
const rank2 = player.newPackageRank;
const monthlyRank = player.monthlyPackageRank;
if (rank2 === 'VIP') { if (rank2 === 'VIP') {
var rank = "[VIP] " var rank = "[VIP] "
@@ -61,52 +49,50 @@ module.exports = {
var rank = "[MVP++] " var rank = "[MVP++] "
} }
const guild = guildAPI + "?key=" + hypixelApiKey + "&player=" + uuid const guild = await getGuild(uuid)
const guildCheck = await fetch(guild); if (!guild) {
if (!guildCheck.data.guild) {
var guildName = "None"; var guildName = "None";
} else { } else {
var guildName = guildCheck.data.guild.name; var guildName = guild.name;
} }
if (!guildCheck.data.guild) { if (!guild) {
var guildTag = "" var guildTag = ""
} else if (!guildCheck.data.guild.tag) { } else if (!guild.tag) {
var guildTag = "" var guildTag = ""
} else { } else {
var guildTag = " [" + guildCheck.data.guild.tag + "]" var guildTag = " [" + guild.tag + "]"
} }
//bedwars level //bedwars level
const hsbwexp = stats.data.player.stats.Bedwars.Experience; const hsbwexp = player.stats.Bedwars.Experience;
const hsbwstars = bedwarsLevel(hsbwexp); const hsbwstars = bedwarsLevel(hsbwexp);
// bedwars fkdr // bedwars fkdr
const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars; const hsbwfk = player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars; const hsbwfd = player.stats.Bedwars.final_deaths_bedwars;
const hsbwfkdr = hsbwfk / hsbwfd; const hsbwfkdr = hsbwfk / hsbwfd;
// bedwars wins // bedwars wins
const hsbwwins = stats.data.player.stats.Bedwars.wins_bedwars; const hsbwwins = player.stats.Bedwars.wins_bedwars;
// skywars level // skywars level
const hsswexp = stats.data.player.stats.SkyWars.skywars_experience; const hsswexp = player.stats.SkyWars.skywars_experience;
const hsswstars = skywarsLevel(hsswexp); const hsswstars = skywarsLevel(hsswexp);
// skywars kdr // skywars kdr
const hsswkills = stats.data.player.stats.SkyWars.kills; const hsswkills = player.stats.SkyWars.kills;
const hsswdeaths = stats.data.player.stats.SkyWars.deaths; const hsswdeaths = player.stats.SkyWars.deaths;
const hsswkd = hsswkills / hsswdeaths; const hsswkd = hsswkills / hsswdeaths;
//skywars wins //skywars wins
const hsswwins = stats.data.player.stats.SkyWars.wins; const hsswwins = player.stats.SkyWars.wins;
// dueks kdr // dueks kdr
const hsduelskills = stats.data.player.stats.Duels.kills const hsduelskills = player.stats.Duels.kills
const hsduelsdeaths = stats.data.player.stats.Duels.deaths const hsduelsdeaths = player.stats.Duels.deaths
const hsduelskd = hsduelskills / hsduelsdeaths const hsduelskd = hsduelskills / hsduelsdeaths
// duels wins // duels wins
const hsduelswins = stats.data.player.stats.Duels.wins; const hsduelswins = player.stats.Duels.wins;
// duels wlr // duels wlr
const hsduelslosses = stats.data.player.stats.Duels.losses; const hsduelslosses = player.stats.Duels.losses;
const hsduelswlr = hsduelswins / hsduelslosses; const hsduelswlr = hsduelswins / hsduelslosses;
// network level // network level
const hypixelExp = stats.data.player.networkExp; const hypixelExp = player.networkExp;
const level = hypixelLevel(hypixelExp); const level = hypixelLevel(hypixelExp);
if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) { if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) {
@@ -129,7 +115,7 @@ module.exports = {
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
title: rank + stats.data.player.displayname + guildTag, title: rank + player.displayname + guildTag,
description: "**Network Level:** `" + description: "**Network Level:** `" +
level.toFixed(2).toString() + "`\n" + level.toFixed(2).toString() + "`\n" +
"**Current Guild:** `" + guildName + "`", "**Current Guild:** `" + guildName + "`",