Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"flowbite": "^1.8.1",
"flowbite-svelte": "^0.39.3",
"mongodb": "^6.3.0",
"prismarine-nbt": "^2.5.0",
"redis": "^4.6.12",
"tailwind-merge": "^1.14.0"
"tailwind-merge": "^1.14.0",
"util": "^0.12.5"
}
}
98 changes: 81 additions & 17 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/api/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function parseProfileMember(
museum: true
},
removed: false,
stats: getStats(profile, player?.data?.unparsed, memberId),
stats: await getStats(profile, player?.data?.unparsed, memberId),
lastUpdated: Math.floor(Date.now() / 1000)
};
}
Expand Down
1 change: 1 addition & 0 deletions src/db/mongo/collections.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface StoredProfileMember {
export interface StoredProfileMemberData {
skills?: SkyblockPlayerSkillStats;
collections?: Record<string, number>;
items?: Record<string, unknown>;
unparsed?: Partial<SkyblockProfileMember>;
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Get Minecraft lore without the color and formatting codes
*
* @param text - The text with color codes
* @returns The text without color codes.
*/
export function getRawLore(text: string): string {
return text.replaceAll(/§[0-9a-fk-or]/g, '');
}
11 changes: 9 additions & 2 deletions src/lib/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import type { StoredProfileMemberData } from '$mongo/collections';
import * as stats from '$stats/index';
import type { HypixelPlayerData, SkyblockProfile } from '$types/hypixel';

export function getStats(profile: SkyblockProfile, player: HypixelPlayerData, uuid: string): StoredProfileMemberData {
export async function getStats(
profile: SkyblockProfile,
player: HypixelPlayerData,
uuid: string
): Promise<StoredProfileMemberData> {
const userProfile = profile.members[uuid];

const items = await stats.getItems(userProfile);

const output = {
skills: stats.getSkills(userProfile, player, profile.members),
slayers: stats.getSlayers(userProfile)
slayers: stats.getSlayers(userProfile),
items: items
// unparsed: userProfile
};

Expand Down
1 change: 1 addition & 0 deletions src/lib/stats/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from '$lib/stats/skills';
export * from '$lib/stats/slayer';
export * from '$lib/stats/items';
47 changes: 47 additions & 0 deletions src/lib/stats/items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { SkyblockProfileMember } from '$types/hypixel';
import { processItems } from './items/items';

function getPath(object: any, path: string[]): unknown {
let output = object;

for (const key of path) {
if (output === undefined) {
return undefined;
}

output = output[key];
}

return output;
}

export async function getItems(userProfile: Partial<SkyblockProfileMember>) {
const output = {
inventory: []
};
console.log(userProfile.inventory);

const inventoryTypes = [
{ name: 'Inventory', path: ['inventory', 'inv_contents'] },
{ name: 'Ender Chest', path: ['inventory', 'ender_chest_contents'] },
{ name: 'Armor', path: ['inventory', 'inv_armor'] },
{ name: 'Equipment', path: ['inventory', 'equipment_contents'] },
{ name: 'Personal Vault', path: ['inventory', 'personal_vault_contents'] },

{ name: 'Potion Bag', path: ['inventory', 'bag_contents', 'potion_bag'] },
{ name: 'Accessory Bag', path: ['inventory', 'bag_contents', 'talisman_bag'] },
{ name: 'Fishing Bag', path: ['inventory', 'bag_contents', 'fishing_bag'] },
{ name: 'Quiver', path: ['inventory', 'bag_contents', 'quiver'] },
{ name: 'Candy Bag', path: ['inventory', 'shared_inventory', 'candy_inventory_contents'] }
];

for (const inventoryType of inventoryTypes) {
const key = inventoryType.name.replace(' ', '_').toLowerCase();

const data = getPath(userProfile, inventoryType.path);

output[key] = await processItems(data);
}

return output;
}
Loading