Skip to content

Commit

Permalink
Merge branch 'main' into betterLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Dec 28, 2024
2 parents f618c02 + dcbca75 commit fab1988
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 37 deletions.
10 changes: 2 additions & 8 deletions API/functions/getLatestProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ async function getLatestProfile(uuid, options = { museum: false, garden: false }
}
}

const [{ data: playerRes }, { data: profileRes }] = await Promise.all([
axios.get(`https://api.hypixel.net/v2/player?key=${config.minecraft.API.hypixelAPIkey}&uuid=${uuid}`),
const [{ data: profileRes }] = await Promise.all([
axios.get(`https://api.hypixel.net/v2/skyblock/profiles?key=${config.minecraft.API.hypixelAPIkey}&uuid=${uuid}`),
]).catch((error) => {
throw error?.response?.data?.cause ?? "Request to Hypixel API failed. Please try again!";
});

if (playerRes.success === false || profileRes.success === false) {
if (profileRes.success === false) {
throw "Request to Hypixel API failed. Please try again!";
}

if (playerRes.player == null) {
throw "Player not found. It looks like this player has never joined the Hypixel.";
}

if (profileRes.profiles == null || profileRes.profiles.length == 0) {
throw "Player has no SkyBlock profiles.";
}
Expand All @@ -57,7 +52,6 @@ async function getLatestProfile(uuid, options = { museum: false, garden: false }
profiles: profileRes.profiles,
profile: profile,
profileData: profileData,
playerRes: playerRes.player,
uuid: uuid,
...(options.museum ? await getMuseum(profileData.profile_id, uuid) : {}),
...(options.garden ? await getGarden(profileData.profile_id) : {}),
Expand Down
20 changes: 1 addition & 19 deletions API/stats/hotm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,8 @@ const miningConst = require("../constants/mining.js");
const calcSkill = require("../constants/skills.js");
const moment = require("moment");

module.exports = (player, profile) => {
module.exports = (profile) => {
try {
const commissions = {
total: player?.achievements?.skyblock_hard_working_miner ?? 0,
milestone: 0,
};

// CREDITS: https://github.com/SkyCryptWebsite/SkyCrypt/blob/b9842bea6f1494fa2d2fd005b64f57d84646c188/src/stats/mining.js#L129
if (profile.objectives?.tutorial !== undefined) {
for (const key of profile.objectives.tutorial) {
if (key.startsWith("commission_milestone_reward_mining_xp_tier_") === false) {
continue;
}

const tier = parseInt(key.slice(43));
commissions.milestone = Math.max(commissions.milestone, tier);
}
}

const forgeItems = [];
if (profile.forge?.forge_processes?.forge_1) {
const forge = Object.values(profile.forge.forge_processes.forge_1);
Expand Down Expand Up @@ -80,7 +63,6 @@ module.exports = (player, profile) => {
},
level: calcSkill("hotm", profile?.mining_core?.experience || 0),
ability: titleCase(profile?.mining_core?.selected_pickaxe_ability || "none", true),
commissions: commissions,
forge: forgeItems,
};
} catch (error) {
Expand Down
5 changes: 5 additions & 0 deletions src/discord/commands/blacklistCommand.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const HypixelDiscordChatBridgeError = require("../../contracts/errorHandler.js");
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const { SuccessEmbed } = require("../../contracts/embedHandler.js");

module.exports = {
Expand Down Expand Up @@ -35,13 +36,17 @@ module.exports = {
const name = interaction.options.getString("username");
const arg = interaction.options.getString("arg").toLowerCase();

bot.chat("/lobby megawalls");
await delay(250);
if (arg == "add") {
bot.chat(`/ignore add ${name}`);
} else if (arg == "remove") {
bot.chat(`/ignore remove ${name}`);
} else {
throw new HypixelDiscordChatBridgeError("Invalid Usage: `/ignore [add/remove] [name]`.");
}
await delay(250);
bot.chat("/limbo");

const embed = new SuccessEmbed(
`Successfully ${arg == "add" ? "added" : "removed"} \`${name}\` ${arg == "add" ? "to" : "from"} the blacklist.`,
Expand Down
63 changes: 63 additions & 0 deletions src/minecraft/commands/booCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const minecraftCommand = require("../../contracts/minecraftCommand.js");
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const helperFunctions = require("../../contracts/helperFunctions.js");

class BooCommand extends minecraftCommand {
constructor(minecraft) {
super(minecraft);

this.name = "boo";
this.aliases = [];
this.description = "Boo someone!";
this.options = [
{
name: "username",
description: "User you want to boo!",
required: true,
},
];
this.isOnCooldown = false;
}

async onCommand(username, message) {
try {
if (this.getArgs(message).length === 0) {
// eslint-disable-next-line no-throw-literal
throw "You must provide a user to boo!";
}

if (9 !== new Date().getMonth()) {
// eslint-disable-next-line no-throw-literal
throw "It's not October!";
}

if (this.isOnCooldown) {
return this.send(`/gc ${this.name} Command is on cooldown`);
}

this.send(`/boo ${this.getArgs(message)[0]}`);
await delay(690);
this.send(`/msg ${this.getArgs(message)[0]} ${username} Booed You!`);
await delay(690);
this.send(`/gc Booed ${this.getArgs(message)[0]}!`);
this.isOnCooldown = true;
// CREDITS: @jaxieflaxie for finding this cooldown reset
setTimeout(() => {
bot.chat(
`/w ${
bot.username
} jaxieflaxie is the best wristspasm member! your cool if u see this - ${helperFunctions.generateID(24)}`,
);
setTimeout(() => {
bot.chat(`/w ${bot.username} ${helperFunctions.generateID(48)}`);
this.isOnCooldown = false;
}, 30000);
}, 30000);
this.isOnCooldown = false;
} catch (error) {
this.send(`/gc [ERROR] ${error}`);
}
}
}

module.exports = BooCommand;
2 changes: 1 addition & 1 deletion src/minecraft/commands/forgeCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ForgeCommand extends minecraftCommand {

username = formatUsername(username, data.profileData?.game_mode);

const hotm = getHotm(data.playerRes, data.profile);
const hotm = getHotm(data.profile);

if (hotm == null) {
// eslint-disable-next-line no-throw-literal
Expand Down
6 changes: 2 additions & 4 deletions src/minecraft/commands/hotmCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HotmCommand extends minecraftCommand {

username = formatUsername(username, data.profileData?.game_mode);

const hotm = getHotm(data.playerRes, data.profile);
const hotm = getHotm(data.profile);

if (hotm == null) {
// eslint-disable-next-line no-throw-literal
Expand All @@ -42,9 +42,7 @@ class HotmCommand extends minecraftCommand {
hotm.powder.gemstone.total,
)} | Mithril Powder: ${formatNumber(hotm.powder.mithril.total)} | Glacite Powder: ${formatNumber(
hotm.powder.glacite.total,
)} | Selected Ability: ${hotm.ability} | Commissions Milestone: ${
hotm.commissions.milestone
} (${hotm.commissions.total.toLocaleString()})`,
)} | Selected Ability: ${hotm.ability}`,
);
} catch (error) {
this.send(`/gc [ERROR] ${error}`);
Expand Down
2 changes: 1 addition & 1 deletion src/minecraft/commands/skyblockCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SkyblockCommand extends minecraftCommand {
}),
getDungeons(data.profile),
getTalismans(data.profile),
getHotm(data.player, data.profile),
getHotm(data.profile),
]);

const skillAverage = (
Expand Down
78 changes: 78 additions & 0 deletions src/minecraft/commands/specialMayorCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const minecraftCommand = require("../../contracts/minecraftCommand.js");


/*
Derpy = 368 mod 24 = 8
Jerry = 376 mod 24 = 16
Scorpius = 384 mod 24 = 0
https://hypixel-skyblock.fandom.com/wiki/Mayor_Election#Special_Candidates_Election_Cycle
*/

const hourMs = 50000;
const dayMs = 24 * hourMs;
const monthLength = 31;
const yearLength = 12;

const monthMs = monthLength * dayMs;
const yearMs = yearLength * monthMs;

const yearZero = 1560275700000;

const currentSkyblockYear = timeToSkyblockYear(Date.now());

var yearsUntilSpecial = 0;
var diffSkyblockYear = currentSkyblockYear;
var specialMayor = "";


function timeToSkyblockYear(time) {
return Math.floor((time - yearZero) / yearMs) + 1;
}

function getSpecialMayor(skyblockYear) {
if (diffSkyblockYear % 24 == 8){
specialMayor = "Derpy";
} else if (diffSkyblockYear % 24 == 16){
specialMayor = "Jerry";
} else if (diffSkyblockYear % 24 == 0){
specialMayor = "Scorpius";
} else {
specialMayor = "Error!";
}
return specialMayor;
}

class SpecialMayorCommand extends minecraftCommand {
constructor(minecraft) {
super(minecraft);

this.name = "specialmayor";
this.aliases = ["specmayor"];
this.description = "How many years until next special mayor, along with speculated special mayor.";
this.options = [];
}

async onCommand() {
try {

if (currentSkyblockYear % 8 == 0){
specialMayor = getSpecialMayor(currentSkyblockYear);
this.send(`/gc Special Mayor this year! It is speculated to be ${specialMayor}.`);
} else {
while (diffSkyblockYear % 8 != 0){
yearsUntilSpecial += 1;
diffSkyblockYear += 1;
specialMayor = getSpecialMayor(diffSkyblockYear);
}
this.send(`/gc Not Special Mayor, ${yearsUntilSpecial} years until the next one! It is speculated to be ${specialMayor}.`);
}

} catch (error) {
console.log(error)
this.send(`/gc [ERROR] ${error}`);
}
}
}

module.exports = SpecialMayorCommand;

9 changes: 5 additions & 4 deletions src/minecraft/handlers/ChatHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,17 @@ class StateHandler extends eventHandler {

isAlreadyBlacklistedMessage(message) {
return (
message.includes(`You've already ignored that player! /ignore remove Player to unignore them!`) &&
message.includes(`You've already blocked that player! /block remove <player> to unblock them!`) &&
!message.includes(":")
);
}

isBlacklistRemovedMessage(message) {
return message.startsWith("Removed") && message.includes("from your ignore list.") && !message.includes(":");
return message.startsWith("Unblocked") && message.endsWith(".") && !message.includes(":");
}

isBlacklistMessage(message) {
return message.startsWith("Added") && message.includes("to your ignore list.") && !message.includes(":");
return message.startsWith("Blocked") && message.endsWith(".") && !message.includes(":");
}

isGuildMessage(message) {
Expand Down Expand Up @@ -1082,7 +1083,7 @@ class StateHandler extends eventHandler {
return;
}

const linkedUser = Object.values(linked).find((u) => player)
const linkedUser = Object.values(linked).find((u) => player);
if (linkedUser === undefined) {
return;
}
Expand Down

0 comments on commit fab1988

Please sign in to comment.