From 987fb43f5f0a724918c4e6094de08cdfbcb2ddf6 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 13 Feb 2021 17:11:00 -0600 Subject: add inventories --- src/cleaners/skyblock/inventory.ts | 41 ++++++++++++++++++++++++++++++++++++++ src/cleaners/skyblock/member.ts | 12 ++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/cleaners/skyblock/inventory.ts (limited to 'src/cleaners/skyblock') diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts new file mode 100644 index 0000000..ac36d88 --- /dev/null +++ b/src/cleaners/skyblock/inventory.ts @@ -0,0 +1,41 @@ +import * as nbt from 'prismarine-nbt' + +function base64decode(base64: string): Buffer { + return Buffer.from(base64, 'base64') +} + +export function cleanInventory(encodedNbt: string): Promise { + return new Promise(resolve => { + const base64Data = base64decode(encodedNbt) + nbt.parse(base64Data, false, (err, value) => { + const simplifiedNbt = nbt.simplify(value) + // .i because hypixel decided to do that + resolve(simplifiedNbt.i) + }) + }) +} + +export const INVENTORIES = { + armor: 'inv_armor', + inventory: 'inv_contents', + ender_chest: 'ender_chest_contents', + talisman_bag: 'talisman_bag', + potion_bag: 'potion_bag', + fishing_bag: 'fishing_bag', + quiver: 'quiver', + trick_or_treat_bag: 'candy_inventory_contents', + wardrobe: 'wardrobe_contents' +} + +export async function cleanInventories(data: any): Promise { + const cleanInventories: any = {} + for (const cleanInventoryName in INVENTORIES) { + const hypixelInventoryName = INVENTORIES[cleanInventoryName] + const encodedInventoryContents = data[hypixelInventoryName]?.data + let inventoryContents + if (encodedInventoryContents) + inventoryContents = await cleanInventory(encodedInventoryContents) + cleanInventories[cleanInventoryName] = inventoryContents + } + return cleanInventories +} \ No newline at end of file diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 8695b3f..febb9c2 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -1,9 +1,11 @@ import { Included } from '../../hypixel' import * as cached from '../../hypixelCached' import { CleanPlayer } from '../player' -import { Bank, cleanBank } from './bank' +import { Bank } from './bank' import { cleanFairySouls, FairySouls } from './fairysouls' +import { cleanInventories, INVENTORIES } from './inventory' import { CleanMinion, cleanMinions } from './minions' +import { CleanFullProfile } from './profile' import { CleanProfileStats, cleanProfileStats } from './stats' export interface CleanBasicMember { @@ -18,6 +20,7 @@ export interface CleanMember extends CleanBasicMember { minions?: CleanMinion[] bank?: Bank fairy_souls?: FairySouls + inventories: typeof INVENTORIES } @@ -33,7 +36,8 @@ export async function cleanSkyBlockProfileMemberResponse(member, included: Inclu // last_death: ??? idk how this is formatted, stats: statsIncluded ? cleanProfileStats(member?.stats) : undefined, minions: statsIncluded ? cleanMinions(member) : undefined, - fairy_souls: statsIncluded ? cleanFairySouls(member) : undefined + fairy_souls: statsIncluded ? cleanFairySouls(member) : undefined, + inventories: statsIncluded ? await cleanInventories(member) : undefined, } } @@ -48,7 +52,5 @@ export interface CleanMemberProfilePlayer extends CleanPlayer { export interface CleanMemberProfile { member: CleanMemberProfilePlayer - profile: { - - } + profile: CleanFullProfile } -- cgit