|
| 1 | +const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); |
| 2 | +const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js"); |
| 3 | +const hypixel = require("../../contracts/API/HypixelRebornAPI.js"); |
| 4 | +const { getUUID } = require("../../contracts/API/mowojangAPI.js"); |
| 5 | +const getWeight = require("../../../API/stats/weight.js"); |
| 6 | +const config = require("../../../config.json"); |
| 7 | + |
| 8 | +async function checkRequirements(uuid) { |
| 9 | + const [player, profile] = await Promise.all([hypixel.getPlayer(uuid), getLatestProfile(uuid)]); |
| 10 | + let meetRequirements = false; |
| 11 | + |
| 12 | + const weightData = getWeight(profile.profile, profile.uuid); |
| 13 | + const weight = weightData?.senither?.total || 0; |
| 14 | + const skyblockLevel = (profile.profile?.leveling?.experience || 0) / 100 ?? 0; |
| 15 | + |
| 16 | + const bwLevel = player.stats.bedwars.level; |
| 17 | + const bwFKDR = player.stats.bedwars.finalKDRatio; |
| 18 | + |
| 19 | + const swLevel = player.stats.skywars.level / 5; |
| 20 | + const swKDR = player.stats.skywars.KDRatio; |
| 21 | + |
| 22 | + const duelsWins = player.stats.duels.wins; |
| 23 | + const dWLR = player.stats.duels.WLRatio; |
| 24 | + |
| 25 | + if ( |
| 26 | + weight >= config.minecraft.guildRequirements.requirements.senitherWeight && |
| 27 | + config.minecraft.guildRequirements.requirements.senitherWeight > 0 |
| 28 | + ) { |
| 29 | + meetRequirements = true; |
| 30 | + } |
| 31 | + |
| 32 | + if ( |
| 33 | + skyblockLevel >= config.minecraft.guildRequirements.requirements.skyblockLevel && |
| 34 | + config.minecraft.guildRequirements.requirements.skyblockLevel > 0 |
| 35 | + ) { |
| 36 | + meetRequirements = true; |
| 37 | + } |
| 38 | + |
| 39 | + if ( |
| 40 | + bwLevel >= config.minecraft.guildRequirements.requirements.bedwarsStars && |
| 41 | + config.minecraft.guildRequirements.requirements.bedwarsStars > 0 |
| 42 | + ) { |
| 43 | + meetRequirements = true; |
| 44 | + } |
| 45 | + if ( |
| 46 | + bwFKDR >= config.minecraft.guildRequirements.requirements.bedwarsFKDR && |
| 47 | + config.minecraft.guildRequirements.requirements.bedwarsFKDR > 0 |
| 48 | + ) { |
| 49 | + meetRequirements = true; |
| 50 | + } |
| 51 | + |
| 52 | + if ( |
| 53 | + swLevel >= config.minecraft.guildRequirements.requirements.skywarsStars && |
| 54 | + config.minecraft.guildRequirements.requirements.skywarsStars > 0 |
| 55 | + ) { |
| 56 | + meetRequirements = true; |
| 57 | + } |
| 58 | + |
| 59 | + if ( |
| 60 | + swKDR >= config.minecraft.guildRequirements.requirements.skywarsKDR && |
| 61 | + config.minecraft.guildRequirements.requirements.skywarsKDR > 0 |
| 62 | + ) { |
| 63 | + meetRequirements = true; |
| 64 | + } |
| 65 | + |
| 66 | + if ( |
| 67 | + duelsWins >= config.minecraft.guildRequirements.requirements.duelsWins && |
| 68 | + config.minecraft.guildRequirements.requirements.duelsWins > 0 |
| 69 | + ) { |
| 70 | + meetRequirements = true; |
| 71 | + } |
| 72 | + |
| 73 | + if ( |
| 74 | + dWLR >= config.minecraft.guildRequirements.requirements.duelsWLR && |
| 75 | + config.minecraft.guildRequirements.requirements.duelsWLR > 0 |
| 76 | + ) { |
| 77 | + meetRequirements = true; |
| 78 | + } |
| 79 | + |
| 80 | + return { |
| 81 | + meetRequirements, |
| 82 | + level: player.level, |
| 83 | + nickname: player.nickname, |
| 84 | + weight: weight.toLocaleString(), |
| 85 | + skyblockLevel: skyblockLevel.toLocaleString(), |
| 86 | + bwLevel: bwLevel.toLocaleString(), |
| 87 | + bwFKDR: bwFKDR.toLocaleString(), |
| 88 | + swLevel: swLevel.toLocaleString(), |
| 89 | + swKDR: swKDR.toLocaleString(), |
| 90 | + duelsWins: duelsWins.toLocaleString(), |
| 91 | + dWLR: dWLR.toLocaleString(), |
| 92 | + }; |
| 93 | +} |
| 94 | + |
| 95 | +function generateEmbed(data) { |
| 96 | + return new EmbedBuilder() |
| 97 | + .setColor(data.meetRequirements ? 2067276 : 15548997) |
| 98 | + .setTitle( |
| 99 | + `${data.nickname} **${data.meetRequirements ? "has" : "hasn't"}** got the requirements to join the Guild!`, |
| 100 | + ) |
| 101 | + .addFields( |
| 102 | + { |
| 103 | + name: "Bedwars Level", |
| 104 | + value: `${data.bwLevel}/${config.minecraft.guildRequirements.requirements.bedwarsStars.toLocaleString()}`, |
| 105 | + inline: true, |
| 106 | + }, |
| 107 | + { |
| 108 | + name: "Skywars Level", |
| 109 | + value: `${data.swLevel}/${config.minecraft.guildRequirements.requirements.skywarsStars.toLocaleString()}`, |
| 110 | + inline: true, |
| 111 | + }, |
| 112 | + { |
| 113 | + name: "Duels Wins", |
| 114 | + value: `${data.duelsWins}/${config.minecraft.guildRequirements.requirements.duelsWins.toLocaleString()}`, |
| 115 | + inline: true, |
| 116 | + }, |
| 117 | + { |
| 118 | + name: "Bedwars FKDR", |
| 119 | + value: `${data.bwFKDR}/${config.minecraft.guildRequirements.requirements.bedwarsFKDR.toLocaleString()}`, |
| 120 | + inline: true, |
| 121 | + }, |
| 122 | + { |
| 123 | + name: "Skywars KDR", |
| 124 | + value: `${data.swKDR}/${config.minecraft.guildRequirements.requirements.skywarsKDR.toLocaleString()}`, |
| 125 | + inline: true, |
| 126 | + }, |
| 127 | + { |
| 128 | + name: "Duels WLR", |
| 129 | + value: `${data.dWLR}/${config.minecraft.guildRequirements.requirements.duelsWLR.toLocaleString()}`, |
| 130 | + inline: true, |
| 131 | + }, |
| 132 | + { |
| 133 | + name: "Senither Weight", |
| 134 | + value: `${data.weight}/${config.minecraft.guildRequirements.requirements.senitherWeight.toLocaleString()}`, |
| 135 | + inline: true, |
| 136 | + }, |
| 137 | + { |
| 138 | + name: "Skyblock Level", |
| 139 | + value: `${data.skyblockLevel}/${config.minecraft.guildRequirements.requirements.skyblockLevel.toLocaleString()}`, |
| 140 | + inline: true, |
| 141 | + }, |
| 142 | + ) |
| 143 | + .setThumbnail(`https://www.mc-heads.net/avatar/${data.nickname}`) |
| 144 | + .setFooter({ |
| 145 | + text: `by @duckysolucky | /help [command] for more information`, |
| 146 | + iconURL: "https://imgur.com/tgwQJTX.png", |
| 147 | + }); |
| 148 | +} |
| 149 | + |
| 150 | +module.exports = { |
| 151 | + checkRequirements, |
| 152 | + generateEmbed, |
| 153 | + name: "requirements", |
| 154 | + description: "Checks a user's requirements to join the guild.", |
| 155 | + options: [ |
| 156 | + { |
| 157 | + name: "username", |
| 158 | + description: "minecraft username", |
| 159 | + type: 3, |
| 160 | + required: false, |
| 161 | + }, |
| 162 | + ], |
| 163 | + |
| 164 | + execute: async (interaction) => { |
| 165 | + const name = interaction.options.getString("username") || interaction?.member?.nickname || null; |
| 166 | + if (name === null) throw new HypixelDiscordChatBridgeError("Please input a username"); |
| 167 | + const playerInfo = await checkRequirements(await getUUID(name)); |
| 168 | + const embed = generateEmbed(playerInfo); |
| 169 | + await interaction.followup({ embeds: [embed] }); |
| 170 | + }, |
| 171 | +}; |
0 commit comments