Skip to content

Commit

Permalink
SkyStats Nightly 1.4.6
Browse files Browse the repository at this point in the history
SkyStats Nightly
1.4.6 Weight command beta
+farmingWeight()
+senitherWeight()
+Sanitization for both
+weightCommand.js
Note that weight command is not finished and this is only the framework
TODO Buttons and switching
  • Loading branch information
axlecoffee committed Jan 6, 2024
1 parent 6e51339 commit 488c564
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 40 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"discord": {
"default": "🌹 SkyStats 🌹 ~ Hypixel And SkyBlock Bot",
"farming_weight": "🌹 SkyStats 🌹 ~ Elite Farmers Weight Calculation",
"support": "🌹 SkyStats 🌹 ~ Support",
"defaultbetter": "🌹 SkyStats 🌹 ~ run [/help] for help",
"owner": "🌹 Axle#9171 🌹",
Expand Down
1 change: 1 addition & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
name: "SkyStats-Production",
script: "./start/production_start.js",
instances: 1,
mode: "fork",
autorestart: true,
watch: true,
max_memory_restart: "4G",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "skystats",
"version": "1.4.5",
"version": "1.4.6",
"description": "A Hypixel Skyblock Metrics Bot For Discord.",
"changelog": "SkyStats Nightly Build minor changes to how getNetworth() is called, and backend changes to getSkyHelper(), networthEmbed(), networthCommand",
"changelog": "SkyStats Nightly\n1.4.6 Weight command beta\n+farmingWeight()\n+senitherWeight()\n+Sanitization for both\n+weightCommand.js\nNote that weight command is not finished and this is only the framework\n**TODO** Buttons and switching",
"main": "index.js",
"scripts": {
"start": "pm2 start --only SkyStats-Production",
Expand Down Expand Up @@ -49,6 +49,7 @@
"prettier": "3.0.3",
"prismarine-nbt": "^2.4.0",
"rss-parser": "^3.13.0",
"senitherweight": "^1.0.8",
"skyhelper-networth": "^1.18.0",
"util": "^0.12.5"
}
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions src/contracts/weight/senitherWeight.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/discord/CommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class CommandHandler {
}
}

module.exports = CommandHandler
module.exports = CommandHandler
2 changes: 1 addition & 1 deletion src/discord/commands/embeds/networthEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const EMOJIS = {
PERSONAL_VAULT_ICON: `<:item_2654:1061455349338615859>`,
MISC_ICON: `<:wheat:1059664236038590584>`,
}
async function networthEmbed(embed_ID, uuid, profileid, username, profilename, networth) {
async function networthEmbed(embed_ID, uuid, username, profilename, networth) {
if (embed_ID === `totals_embed`) {
return {
color: 0xffa600,
Expand Down
56 changes: 56 additions & 0 deletions src/discord/commands/embeds/weightEmbed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const config = require(`../../../../config.json`);
const { addNotation, addCommas } = require(`../../../contracts/helperFunctions`);
const messages = config.messages.discord;
const { farmingWeight } = require("../../../functions/get/getWeight")
const EMOJIS = {
PURSE_ICON: `<:Purse:1059997956784279562>`,
BOOSTER_COOKIE_ICON: `<:BOOSTER_COOKIE:1070126116846710865>`,
SOULBOUND_ICON: `<:IRON_INGOT:1070126498616455328>`,
BANK_ICON: `<:Bank:1059664677606531173>`,
SACK_ICON: `<:sacks:1059664698095710388>`,
ARMOR_ICON: `<:DIAMOND_CHESTPLATE:1061454753357377586>`,
EQUIPMENT_ICON: `<:Iron_Chestplate:1061454825839144970>`,
WARDROBE_ICON: `<:ARMOR_STAND:1061454861071298620>`,
INVENTORY_ICON: `<:CHEST:1061454902049656993>`,
ENDER_CHEST_ICON: `<:ENDER_CHEST:1061454947931140106>`,
SWORD_ICON: "<:sword:1060045450897539122>",
STORAGE_ICON: `<:storage:1059664802701656224>`,
MUSEUM_ICON: `<:LEATHER_CHESTPLATE:1134874048048935012>`,
PET_ICON: `<:Spawn_Null:1061455273224577024>`,
BONUS_ICON: "<:carrot:1072129687427498012>",
ACCESSORY_BAG_ICON: `<:HEGEMONY_ARTIFACT:1061455309983461486>`,
PERSONAL_VAULT_ICON: `<:item_2654:1061455349338615859>`,
MISC_ICON: `<:wheat:1059664236038590584>`,
}

async function farmingWeight_Embed(uuid, username, profilename) {
const weight = await farmingWeight(uuid)
return {
color: 0xffa600,
title: `Farming Weight for ${username} on ${profilename}`,
URL: `https://sky.shiiyu.moe/stats/${uuid}`,
description: `${EMOJIS.SWORD_ICON} Total Weight: **${weight.total_weight}**`,
fields: [
{
name: `${EMOJIS.MISC_ICON} Crops`,
value: weight.items.crop_weight,
inline: false,
},
{
name: `${EMOJIS.BONUS_ICON} Bonuses`,
value: weight.items.bonus_weight,
inline: false,
},
],
thumbnail: {
url: `https://api.mineatar.io/body/full/${uuid}`
},
footer: {
text: `${messages.farming_weight}`,
iconURL: `${messages.icon}`,
},
}
}


module.exports = { farmingWeight_Embed };
2 changes: 1 addition & 1 deletion src/discord/commands/publishCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
execute: async (interaction, client) => {
const oldVersion = packageJson.version;
const guild = await client.guilds.fetch('1058272411247714425');
const changelogValue = interaction.options.getString('changelog');
const changelogValue = interaction.options.getString('changelog').replaceAll('\\n', '\n');
const versionValue = interaction.options.getString('version');
if (guild.members.cache.get(interaction.user.id)?.roles.cache.has(config.discord.developmentRole)) {

Expand Down
41 changes: 25 additions & 16 deletions src/discord/commands/testCommand.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
const { ActionRowBuilder, StringSelectMenuBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

const { handleError } = require("../../functions/handle/handleError");
const { farmingWeight } = require("../../functions/get/getWeight")
const { senitherWeight } = require("../../functions/get/getWeight")
const { farmingWeight_Embed } = require('./embeds/weightEmbed')
const { calculateTotalSenitherWeight } = require('../../functions/constants/senitherWeight')
const { getPlayer } = require("../../functions/get/getPlayer")
module.exports = {
name: 'test',
description: 'bot credits',
options: [
{
name: 'message',
name: 'name',
description: 'message to send',
type: 3,
required: true
required: false
},


],

execute: async (interaction, client) => {
const message = interaction.options.getString('message').replaceAll('\\n', '\n')
const channel = client.channels.cache.get(`1113587258117861378`);
const embed = {
title: `Wtf`,
color: 0xffa600,
description: (`${message}`),
timestamp: new Date().toISOString(),
};
await channel.send({ embeds: [ embed ] })
await interaction.reply({content: "Your report has been shared with the developers, do not delete this message.", ephemeral: false})
execute: async (interaction, client, InteractionCreate) => {
const id = interaction.user.id;
const { uuid2, username, profilename, profileid, playerData, profileData, profile, error } = await getPlayer(
id,
interaction.options.getString("name")
);
// console.log(await calculateTotalSenitherWeight(profile))
console.log(await senitherWeight(profile))
await interaction.deferReply();

},
};
try {
await interaction.editReply({content: "Success."})
} catch (error) {
const errorEmbed = handleError(error);
await interaction.editReply({ embeds: [errorEmbed] });
}
}
}
13 changes: 11 additions & 2 deletions src/discord/commands/weightCommand.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
const config = require("../../../config.json");
const { handleError } = require("../../functions/handle/handleError");
const { farmingWeight } = require("../../functions/get/getWeight")
const { farmingWeight_Embed } = require('./embeds/weightEmbed')
const { getPlayer } = require("../../functions/get/getPlayer")
const messages = config.messages.discord

module.exports = {
name: 'testing',
description: 'Shows a players weight',
options: [
{
name: "notes",
name: "player",
description: "meow",
type: 3,
required: false,
},
],
execute: async (interaction, client, InteractionCreate) => {
const id = interaction.user.id;
const { uuid2, username, profilename, profileid, error } = await getPlayer(
id,
interaction.options.getString("name")
);
const farming_weight_embed = await farmingWeight_Embed(uuid2, username, profilename)
await interaction.deferReply();
try {
await interaction.editReply({ content: `dont test me :anger:` })
await interaction.editReply({ embeds: [farming_weight_embed ] })
} catch (error) {
const errorEmbed = handleError(error);
await interaction.editReply({ embeds: [errorEmbed] });
Expand Down
13 changes: 6 additions & 7 deletions src/functions/constants/senitherWeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,12 @@ async function calculateTotalSenitherWeight(profile) {
},
dungeons: {
catacombs: await calculateSenitherWeight('catacombs', (calcSkill('dungeoneering', profile.dungeons?.dungeon_types?.catacombs?.experience || 0)).levelWithProgress, profile.dungeons?.dungeon_types?.catacombs?.experience || 0),
classes: {
healer: await calculateSenitherWeight('healer', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.healer?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.healer?.experience || 0),
mage: await calculateSenitherWeight('mage', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.mage?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.mage?.experience || 0),
berserk: await calculateSenitherWeight('berserk', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.berserk?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.berserk?.experience || 0),
archer: await calculateSenitherWeight('archer', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.archer?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.archer?.experience || 0),
tank: await calculateSenitherWeight('tank', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.tank?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.tank?.experience || 0),
}
healer: await calculateSenitherWeight('healer', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.healer?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.healer?.experience || 0),
mage: await calculateSenitherWeight('mage', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.mage?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.mage?.experience || 0),
berserk: await calculateSenitherWeight('berserk', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.berserk?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.berserk?.experience || 0),
archer: await calculateSenitherWeight('archer', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.archer?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.archer?.experience || 0),
tank: await calculateSenitherWeight('tank', (calcSkill('dungeoneering', profile.dungeons?.player_classes?.tank?.experience || 0)).levelWithProgress, profile.dungeons?.player_classes?.tank?.experience || 0),

}
}
return weight
Expand Down
98 changes: 98 additions & 0 deletions src/functions/get/getWeight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
const axios = require('axios');
require("dotenv").config();
const apiKey = process.env.KEY;
const fs = require('fs');
const { addCommas, addNotation } = require("../../contracts/helperFunctions");
const { calculateTotalSenitherWeight } = require('../../functions/constants/senitherWeight')

async function farmingWeight(uuid) {
const response = await axios.get(`https://api.elitebot.dev/Weight/${uuid}/selected`);
function sanitizeCropWeight(obj) {
let sanitized = '';
let crops = [];
for (let crop in obj.cropWeight) {
let weight = obj.cropWeight[crop];
weight = weight.toFixed(1);
crops.push({ name: crop, weight: weight });
}
crops.sort((a, b) => b.weight - a.weight);
for (let crop of crops) {
sanitized += `→ ${crop.name}: **${addCommas(crop.weight)}**\n`;
}
return sanitized;
}
function sanitizeBonusWeight(obj) {
let sanitized = '';

for (let crop in obj.bonusWeight) {
let weight = obj.bonusWeight[crop];
weight = weight.toFixed(1);
sanitized += `→ ${crop}: **${addCommas(weight)}**\n`;
}

return sanitized;
}
return {
total_weight: addCommas(response.data.totalWeight.toFixed(1)),
items: {
crop_weight: sanitizeCropWeight(response.data),
bonus_weight: sanitizeBonusWeight(response.data),
}
}
}

async function senitherWeight(profile) {
const weight = await calculateTotalSenitherWeight(profile);
function sanitizeData(obj) {
let totalWeight = 0;
let totalOverflow = 0;
let skills = obj.skills;
let slayers = obj.slayer;
let dungeons = obj.dungeons;
// Extract and sum skill, slayer, and dungeon weights and overflows
for (let skill in skills) {
totalWeight += skills[skill].weight;
totalOverflow += skills[skill].weight_overflow;
}

for (let slayer in slayers) {
totalWeight += slayers[slayer].weight;
totalOverflow += slayers[slayer].weight_overflow;
}

for (let dungeon in dungeons) {
totalWeight += dungeons[dungeon].weight;
totalOverflow += dungeons[dungeon].weight_overflow;
}

// Sanitize data
let sanitizedObj = {
totalWeight: totalWeight.toFixed(1),
totalOverflow: totalOverflow.toFixed(1),
skills: formatData(skills),
slayers: formatData(slayers),
dungeons: formatData(dungeons)
};
return sanitizedObj;
}
function formatData(data) {
let formattedData = '';
for (let key in data) {
if (data[key].weight !== undefined && data[key].weight_overflow !== undefined) {
let weight = data[key].weight.toFixed(1);
let overflow = data[key].weight_overflow.toFixed(1);
if (overflow !== '0.0') {
formattedData += `→ ${key}: **${addCommas(weight)}** (+${addCommas(overflow)})\n`;
} else {
formattedData += `→ ${key}: **${addCommas(weight)}**\n`;
}
}
}
return formattedData;
}
const data = sanitizeData(weight)

return data;
}

module.exports = { farmingWeight, senitherWeight }
2 changes: 1 addition & 1 deletion src/functions/handle/handleDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ module.exports = {
connect,
getDb,
disconnect
};
};

0 comments on commit 488c564

Please sign in to comment.