Skip to content

Commit

Permalink
Merge pull request #291 from Kathund/requirements
Browse files Browse the repository at this point in the history
Requirements Command
  • Loading branch information
Killermaschine88 authored Dec 28, 2024
2 parents dcbca75 + ee8244f commit 1784de4
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 148 deletions.
4 changes: 0 additions & 4 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@
"autoAccept": false,
"requirements": {
"bedwarsStars": -1,
"bedwarsStarsWithFKDR": -1,
"bedwarsFKDR": -1,

"skywarsStars": -1,
"skywarsStarsWithKDR": -1,
"skywarsKDR": -1,

"duelsWins": -1,
"duelsWinsWithWLR": -1,
"duelsWLR": -1,

"senitherWeight": -1,
"lilyWeight": -1,
"skyblockLevel": -1
}
},
Expand Down
172 changes: 172 additions & 0 deletions src/discord/commands/requirementsCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js");
const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js");
const hypixel = require("../../contracts/API/HypixelRebornAPI.js");
const { getUUID } = require("../../contracts/API/mowojangAPI.js");
const getWeight = require("../../../API/stats/weight.js");
const config = require("../../../config.json");
const { EmbedBuilder } = require("discord.js");

async function checkRequirements(uuid) {
const [player, profile] = await Promise.all([hypixel.getPlayer(uuid), getLatestProfile(uuid)]);
let meetRequirements = false;

const weightData = getWeight(profile.profile, profile.uuid);
const weight = weightData?.senither?.total || 0;
const skyblockLevel = (profile.profile?.leveling?.experience || 0) / 100 ?? 0;

const bwLevel = player.stats.bedwars.level;
const bwFKDR = player.stats.bedwars.finalKDRatio;

const swLevel = player.stats.skywars.level / 5;
const swKDR = player.stats.skywars.KDRatio;

const duelsWins = player.stats.duels.wins;
const dWLR = player.stats.duels.WLRatio;

if (
weight >= config.minecraft.guildRequirements.requirements.senitherWeight &&
config.minecraft.guildRequirements.requirements.senitherWeight > 0
) {
meetRequirements = true;
}

if (
skyblockLevel >= config.minecraft.guildRequirements.requirements.skyblockLevel &&
config.minecraft.guildRequirements.requirements.skyblockLevel > 0
) {
meetRequirements = true;
}

if (
bwLevel >= config.minecraft.guildRequirements.requirements.bedwarsStars &&
config.minecraft.guildRequirements.requirements.bedwarsStars > 0
) {
meetRequirements = true;
}
if (
bwFKDR >= config.minecraft.guildRequirements.requirements.bedwarsFKDR &&
config.minecraft.guildRequirements.requirements.bedwarsFKDR > 0
) {
meetRequirements = true;
}

if (
swLevel >= config.minecraft.guildRequirements.requirements.skywarsStars &&
config.minecraft.guildRequirements.requirements.skywarsStars > 0
) {
meetRequirements = true;
}

if (
swKDR >= config.minecraft.guildRequirements.requirements.skywarsKDR &&
config.minecraft.guildRequirements.requirements.skywarsKDR > 0
) {
meetRequirements = true;
}

if (
duelsWins >= config.minecraft.guildRequirements.requirements.duelsWins &&
config.minecraft.guildRequirements.requirements.duelsWins > 0
) {
meetRequirements = true;
}

if (
dWLR >= config.minecraft.guildRequirements.requirements.duelsWLR &&
config.minecraft.guildRequirements.requirements.duelsWLR > 0
) {
meetRequirements = true;
}

return {
meetRequirements,
level: player.level,
nickname: player.nickname,
weight: weight.toLocaleString(),
skyblockLevel: skyblockLevel.toLocaleString(),
bwLevel: bwLevel.toLocaleString(),
bwFKDR: bwFKDR.toLocaleString(),
swLevel: swLevel.toLocaleString(),
swKDR: swKDR.toLocaleString(),
duelsWins: duelsWins.toLocaleString(),
dWLR: dWLR.toLocaleString(),
};
}

function generateEmbed(data) {
return new EmbedBuilder()
.setColor(data.meetRequirements ? 2067276 : 15548997)
.setTitle(
`${data.nickname} **${data.meetRequirements ? "has" : "hasn't"}** got the requirements to join the Guild!`,
)
.addFields(
{
name: "Bedwars Level",
value: `${data.bwLevel}/${config.minecraft.guildRequirements.requirements.bedwarsStars.toLocaleString()}`,
inline: true,
},
{
name: "Skywars Level",
value: `${data.swLevel}/${config.minecraft.guildRequirements.requirements.skywarsStars.toLocaleString()}`,
inline: true,
},
{
name: "Duels Wins",
value: `${data.duelsWins}/${config.minecraft.guildRequirements.requirements.duelsWins.toLocaleString()}`,
inline: true,
},
{
name: "Bedwars FKDR",
value: `${data.bwFKDR}/${config.minecraft.guildRequirements.requirements.bedwarsFKDR.toLocaleString()}`,
inline: true,
},
{
name: "Skywars KDR",
value: `${data.swKDR}/${config.minecraft.guildRequirements.requirements.skywarsKDR.toLocaleString()}`,
inline: true,
},
{
name: "Duels WLR",
value: `${data.dWLR}/${config.minecraft.guildRequirements.requirements.duelsWLR.toLocaleString()}`,
inline: true,
},
{
name: "Senither Weight",
value: `${data.weight}/${config.minecraft.guildRequirements.requirements.senitherWeight.toLocaleString()}`,
inline: true,
},
{
name: "Skyblock Level",
value: `${data.skyblockLevel}/${config.minecraft.guildRequirements.requirements.skyblockLevel.toLocaleString()}`,
inline: true,
},
)
.setThumbnail(`https://www.mc-heads.net/avatar/${data.nickname}`)
.setFooter({
text: `by @duckysolucky | /help [command] for more information`,
iconURL: "https://imgur.com/tgwQJTX.png",
});
}

module.exports = {
checkRequirements,
generateEmbed,
name: "requirements",
description: "Checks a user's requirements to join the guild.",
options: [
{
name: "username",
description: "minecraft username",
type: 3,
required: false,
},
],

execute: async (interaction) => {
const name = interaction.options.getString("username") || interaction?.member?.nickname || null;
if (name === null) throw new HypixelDiscordChatBridgeError("Please input a username");
const playerInfo = await checkRequirements(await getUUID(name));
const embed = generateEmbed(playerInfo);
await interaction.followUp({ embeds: [embed] });
},
};
13 changes: 11 additions & 2 deletions src/discord/events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js");
const { ErrorEmbed } = require("../../contracts/embedHandler.js");
const { ErrorEmbed, SuccessEmbed } = require("../../contracts/embedHandler.js");
// eslint-disable-next-line no-unused-vars
const { CommandInteraction } = require("discord.js");
const config = require("../../../config.json");
Expand All @@ -23,7 +23,7 @@ module.exports = {
if (command === undefined) {
return;
}

Logger.discordMessage(`${interaction.user.username} - [${interaction.commandName}]`);

if (command.verificationCommand === true && config.verification.enabled === false) {
Expand All @@ -39,6 +39,15 @@ module.exports = {
}

await command.execute(interaction);
} else if (interaction.isButton()) {
await interaction.deferReply({ ephemeral: true }).catch(() => {});
if (interaction.customId !== "joinRequestAccept") return;
const username = interaction?.message?.embeds?.[0]?.title.split(" ")?.[0] || undefined;
if (!username) throw new HypixelDiscordChatBridgeError("Something is missing");
bot.chat(`/g accept ${username}`);
const embed = new SuccessEmbed(`Successfully accepted **${username}** into the guild.`);

await interaction.followUp({ embeds: [embed] });
}
} catch (error) {
console.log(error);
Expand Down
Loading

0 comments on commit 1784de4

Please sign in to comment.