Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Rewrite Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Sep 22, 2024
1 parent 58e5293 commit bc21050
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/API/getSkyblockAuctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ test('getSkyblockAuctions (One Page Include Item Bytes)', async () => {
client.destroy();
});

test.skip('getSkyblockAuctions (All Pages)', async () => {
test('getSkyblockAuctions (All Pages)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Expand Down
54 changes: 28 additions & 26 deletions src/API/getSkyblockMember.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ test('getSkyblockMember (museum)', async () => {
expect(member.garden).toBeNull();
expectTypeOf(member.garden).toEqualTypeOf<SkyblockGarden | null>();
expect(member.museum).toBeDefined();
expect(member.museum).toBeNull();
expectTypeOf(member.museum).toEqualTypeOf<SkyblockMuseum | null>();
expect(member.profileName).toBeDefined();
expectTypeOf(member.profileName).toEqualTypeOf<string>();
Expand Down Expand Up @@ -407,14 +406,14 @@ test('getSkyblockMember (museum)', async () => {
const equipment = await member.getEquipment();
expect(equipment).toBeDefined();
expectTypeOf(equipment).toEqualTypeOf<Equipment>();
expect(data.gauntlet).toBeDefined();
expectTypeOf(data.gauntlet).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.belt).toBeDefined();
expectTypeOf(data.belt).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.cloak).toBeDefined();
expectTypeOf(data.cloak).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.necklace).toBeDefined();
expectTypeOf(data.necklace).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.gauntlet).toBeDefined();
expectTypeOf(equipment.gauntlet).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.belt).toBeDefined();
expectTypeOf(equipment.belt).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.cloak).toBeDefined();
expectTypeOf(equipment.cloak).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.necklace).toBeDefined();
expectTypeOf(equipment.necklace).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(member.getPersonalVault).toBeDefined();
expectTypeOf(member.getPersonalVault).toEqualTypeOf<() => Promise<SkyblockInventoryItem[]>>();
const vault = await member.getPersonalVault();
Expand Down Expand Up @@ -525,7 +524,6 @@ test('getSkyblockMember (garden)', async () => {
expect(member.selected).toBeDefined();
expectTypeOf(member.selected).toEqualTypeOf<boolean>();
expect(member.garden).toBeDefined();
expect(member.garden).toBeNull();
expectTypeOf(member.garden).toEqualTypeOf<SkyblockGarden | null>();
expect(member.museum).toBeDefined();
expect(member.museum).toBeNull();
Expand Down Expand Up @@ -869,14 +867,16 @@ test('getSkyblockMember (garden)', async () => {
const equipment = await member.getEquipment();
expect(equipment).toBeDefined();
expectTypeOf(equipment).toEqualTypeOf<Equipment>();
expect(data.gauntlet).toBeDefined();
expectTypeOf(data.gauntlet).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.belt).toBeDefined();
expectTypeOf(data.belt).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.cloak).toBeDefined();
expectTypeOf(data.cloak).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.necklace).toBeDefined();
expectTypeOf(data.necklace).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment).toBeDefined();
expectTypeOf(equipment).toEqualTypeOf<Equipment>();
expect(equipment.gauntlet).toBeDefined();
expectTypeOf(equipment.gauntlet).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.belt).toBeDefined();
expectTypeOf(equipment.belt).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.cloak).toBeDefined();
expectTypeOf(equipment.cloak).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.necklace).toBeDefined();
expectTypeOf(equipment.necklace).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(member.getPersonalVault).toBeDefined();
expectTypeOf(member.getPersonalVault).toEqualTypeOf<() => Promise<SkyblockInventoryItem[]>>();
const vault = await member.getPersonalVault();
Expand Down Expand Up @@ -1331,14 +1331,16 @@ test('getSkyblockMember', async () => {
const equipment = await member.getEquipment();
expect(equipment).toBeDefined();
expectTypeOf(equipment).toEqualTypeOf<Equipment>();
expect(data.gauntlet).toBeDefined();
expectTypeOf(data.gauntlet).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.belt).toBeDefined();
expectTypeOf(data.belt).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.cloak).toBeDefined();
expectTypeOf(data.cloak).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(data.necklace).toBeDefined();
expectTypeOf(data.necklace).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment).toBeDefined();
expectTypeOf(equipment).toEqualTypeOf<Equipment>();
expect(equipment.gauntlet).toBeDefined();
expectTypeOf(equipment.gauntlet).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.belt).toBeDefined();
expectTypeOf(equipment.belt).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.cloak).toBeDefined();
expectTypeOf(equipment.cloak).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(equipment.necklace).toBeDefined();
expectTypeOf(equipment.necklace).toEqualTypeOf<SkyblockInventoryItem | null>();
expect(member.getPersonalVault).toBeDefined();
expectTypeOf(member.getPersonalVault).toEqualTypeOf<() => Promise<SkyblockInventoryItem[]>>();
const vault = await member.getPersonalVault();
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockMuseum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Client from '../Client';
import SkyblockInventoryItem from '../structures/SkyBlock/SkyblockInventoryItem';
import SkyblockMuseum from '../structures/SkyBlock/SkyblockMuseum';
import SkyblockMuseumItem from '../structures/SkyBlock/SkyblockMuseumItem';
import SkyblockProfile from '../structures/SkyBlock/SkyblockProfile';
import SkyblockProfile from '../structures/SkyBlock/Profile/Profile';
import { expect, expectTypeOf, test } from 'vitest';

test('getSkyblockMuseum (no input)', () => {
Expand Down
41 changes: 28 additions & 13 deletions src/API/getSkyblockProfiles.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Banking from '../structures/SkyBlock/Profile/Banking';
import Client from '../Client';
import CommunityUpgrades from '../structures/SkyBlock/Profile/CommunityUpgrades';
import SkyblockGarden from '../structures/SkyBlock/SkyblockGarden';
import SkyblockMember from '../structures/SkyBlock/Member/Member';
import SkyblockProfile from '../structures/SkyBlock/SkyblockProfile';
import SkyblockProfile from '../structures/SkyBlock/Profile/Profile';
import { SkyblockProfileName } from '../structures/SkyBlock/Profile/Types';
import { expect, expectTypeOf, test } from 'vitest';

test('getSkyblockProfiles (raw)', async () => {
Expand Down Expand Up @@ -47,16 +51,20 @@ test('getSkyblockProfiles', async () => {
expectTypeOf(profile.profileId).toEqualTypeOf<string>();

expect(profile.profileName).toBeDefined();
expectTypeOf(profile.profileName).toEqualTypeOf<string>();
expectTypeOf(profile.profileName).toEqualTypeOf<SkyblockProfileName>();

expect(profile.gameMode).toBeDefined();
expectTypeOf(profile.gameMode).toEqualTypeOf<string | null>();

expect(profile.banking).toBeDefined();
expectTypeOf(profile.banking).toEqualTypeOf<object>();
expectTypeOf(profile.banking).toEqualTypeOf<Banking>();

expect(profile.garden).toBeDefined();
expect(profile.garden).toBeNull();
expectTypeOf(profile.garden).toEqualTypeOf<SkyblockGarden | null>();

expect(profile.communityUpgrades).toBeDefined();
expectTypeOf(profile.communityUpgrades).toEqualTypeOf<object>();
expectTypeOf(profile.communityUpgrades).toEqualTypeOf<CommunityUpgrades>();

expect(profile.selected).toBeDefined();
expectTypeOf(profile.selected).toEqualTypeOf<boolean>();
Expand All @@ -69,7 +77,7 @@ test('getSkyblockProfiles', async () => {

expect(profile.toString()).toBeDefined();
expectTypeOf(profile.toString()).toEqualTypeOf<string>();
expect(profile.toString()).toBe(profile.profileName);
expect(profile.toString()).toBe(profile.profileId);
});

client.destroy();
Expand All @@ -91,16 +99,19 @@ test('getSkyblockProfiles (garden)', async () => {
expectTypeOf(profile.profileId).toEqualTypeOf<string>();

expect(profile.profileName).toBeDefined();
expectTypeOf(profile.profileName).toEqualTypeOf<string>();
expectTypeOf(profile.profileName).toEqualTypeOf<SkyblockProfileName>();

expect(profile.gameMode).toBeDefined();
expectTypeOf(profile.gameMode).toEqualTypeOf<string | null>();

expect(profile.banking).toBeDefined();
expectTypeOf(profile.banking).toEqualTypeOf<object>();
expectTypeOf(profile.banking).toEqualTypeOf<Banking>();

expect(profile.garden).toBeDefined();
expectTypeOf(profile.garden).toEqualTypeOf<SkyblockGarden | null>();

expect(profile.communityUpgrades).toBeDefined();
expectTypeOf(profile.communityUpgrades).toEqualTypeOf<object>();
expectTypeOf(profile.communityUpgrades).toEqualTypeOf<CommunityUpgrades>();

expect(profile.selected).toBeDefined();
expectTypeOf(profile.selected).toEqualTypeOf<boolean>();
Expand All @@ -113,7 +124,7 @@ test('getSkyblockProfiles (garden)', async () => {

expect(profile.toString()).toBeDefined();
expectTypeOf(profile.toString()).toEqualTypeOf<string>();
expect(profile.toString()).toBe(profile.profileName);
expect(profile.toString()).toBe(profile.profileId);
});

client.destroy();
Expand All @@ -135,16 +146,20 @@ test('getSkyblockProfiles (museum)', async () => {
expectTypeOf(profile.profileId).toEqualTypeOf<string>();

expect(profile.profileName).toBeDefined();
expectTypeOf(profile.profileName).toEqualTypeOf<string>();
expectTypeOf(profile.profileName).toEqualTypeOf<SkyblockProfileName>();

expect(profile.gameMode).toBeDefined();
expectTypeOf(profile.gameMode).toEqualTypeOf<string | null>();

expect(profile.banking).toBeDefined();
expectTypeOf(profile.banking).toEqualTypeOf<object>();
expectTypeOf(profile.banking).toEqualTypeOf<Banking>();

expect(profile.garden).toBeDefined();
expect(profile.garden).toBeNull();
expectTypeOf(profile.garden).toEqualTypeOf<SkyblockGarden | null>();

expect(profile.communityUpgrades).toBeDefined();
expectTypeOf(profile.communityUpgrades).toEqualTypeOf<object>();
expectTypeOf(profile.communityUpgrades).toEqualTypeOf<CommunityUpgrades>();

expect(profile.selected).toBeDefined();
expectTypeOf(profile.selected).toEqualTypeOf<boolean>();
Expand All @@ -157,7 +172,7 @@ test('getSkyblockProfiles (museum)', async () => {

expect(profile.toString()).toBeDefined();
expectTypeOf(profile.toString()).toEqualTypeOf<string>();
expect(profile.toString()).toBe(profile.profileName);
expect(profile.toString()).toBe(profile.profileId);
});

client.destroy();
Expand Down
2 changes: 1 addition & 1 deletion src/API/getSkyblockProfiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Client from '../Client';
import Endpoint from '../Private/Endpoint';
import SkyblockProfile from '../structures/SkyBlock/SkyblockProfile';
import SkyblockProfile from '../structures/SkyBlock/Profile/Profile';
import { SkyblockRequestOptions } from './API';

class getSkyblockProfiles extends Endpoint {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export * from './structures/SkyBlock/Member/Member';
export * from './structures/SkyBlock/SkyblockMuseum';
export * from './structures/SkyBlock/SkyblockMuseumItem';
export * from './structures/SkyBlock/SkyblockPet';
export * from './structures/SkyBlock/SkyblockProfile';
export * from './structures/SkyBlock/Profile/Profile';
export * from './structures/SkyBlock/Static/Bingo';
export * from './structures/SkyBlock/Static/BingoData';
export * from './structures/SkyBlock/Static/Candidate';
Expand Down
28 changes: 28 additions & 0 deletions src/structures/SkyBlock/Profile/Banking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { BankingTrasnsactionAction } from './Types';

export class BankingTrasnsaction {
amount: number;
timestamp: number;
action: BankingTrasnsactionAction | 'UNKNOWN';
user: string;
constructor(data: Record<string, any>) {
this.amount = data?.amount || 0;
this.timestamp = data?.timestamp || 0;
this.action = data?.action || 'UNKNONW';
this.user = data?.initiator_name || 'UNKNOWN';
}
}

class Banking {
balance: number;
transactions: BankingTrasnsaction[];
constructor(data: Record<string, any>) {
this.balance = data.balance || 0;
this.transactions = [];
(data.transactions || []).forEach((transaction: Record<string, any>) => {
this.transactions.push(new BankingTrasnsaction(transaction));
});
}
}

export default Banking;
54 changes: 54 additions & 0 deletions src/structures/SkyBlock/Profile/CommunityUpgrades.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { CommunityUpgradesUpgrades } from './Types';

class Upgrade {
upgrade: CommunityUpgradesUpgrades;
startedTimestamp: number;
startedAt: Date;
constructor(data: Record<string, any>) {
this.upgrade = data.upgrade;
this.startedTimestamp = data.started_ms;
this.startedAt = new Date(this.startedTimestamp);
}
}

class Upgraded extends Upgrade {
tier: number;
startedBy: number;
claimedTimestamp: number;
claimedAt: Date;
claimedBy: number;
fasttracked: boolean;
constructor(data: Record<string, any>) {
super(data);
this.tier = data.tier;
this.startedBy = data.started_by;
this.claimedTimestamp = data.claimed_ms;
this.claimedAt = new Date(this.claimedTimestamp);
this.claimedBy = data.claimed_by;
this.fasttracked = data.fasttracked || false;
}
}

class Upgrading extends Upgrade {
tier: number;
startedBy: number;
constructor(data: Record<string, any>) {
super(data);
this.tier = data.new_tier;
this.startedBy = data.who_started;
}
}

class CommunityUpgrades {
currentlyUpgrading: Upgrading | null;
upgrades: Upgraded[];
constructor(data: Record<string, any>) {
this.currentlyUpgrading = data.currently_upgrading ? new Upgrading(data.currently_upgrading) : null;
this.upgrades = [];
data.upgrade_states.forEach((upgrade: Record<string, any>) => {
this.upgrades.push(new Upgraded(upgrade));
});
}
}

export default CommunityUpgrades;
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import SkyblockGarden from './SkyblockGarden';
import SkyblockMember from './Member/Member';
import Banking from './Banking';
import CommunityUpgrades from './CommunityUpgrades';
import SkyblockGarden from '../SkyblockGarden';
import SkyblockMember from '../Member/Member';
import { SkyblockProfileName } from './Types';

class SkyblockProfile {
profileId: string;
profileName: string;
profileName: SkyblockProfileName;
gameMode: string | null;
banking: object;
banking: Banking;
garden: SkyblockGarden | null;
communityUpgrades: object;
communityUpgrades: CommunityUpgrades;
selected: boolean;
members: SkyblockMember[];
me: SkyblockMember | undefined;
constructor(data: Record<string, any>) {
this.profileId = data.profileId || '';
this.profileName = data.profileName || '';
this.gameMode = data.gameMode || null;
this.banking = data.banking || {};
this.banking = new Banking(data.banking || {});
this.garden = data.garden || null;
this.communityUpgrades = data.communityUpgrades || {};
this.communityUpgrades = new CommunityUpgrades(data.communityUpgrades || {});
this.selected = data.selected || false;
this.members = Object.keys(data.members).map(
(uuid) =>
new SkyblockMember({
uuid: uuid,
profileId: this.profileId,
garden: data.garden,
museum: data.museum,
garden: null,
museum: null,
profileName: this.profileName,
gameMode: this.gameMode,
m: data.members[uuid],
Expand All @@ -38,7 +41,7 @@ class SkyblockProfile {
}

toString(): string {
return this.profileName;
return this.profileId;
}
}

Expand Down
Loading

0 comments on commit bc21050

Please sign in to comment.