Skip to content

feat(skybock): Add Skyblock item class and getSkyblockItems #661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 10, 2025
Merged
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
161 changes: 161 additions & 0 deletions src/API/getSkyblockItems.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import Client from '../Client.js';
import RequestData from '../Private/RequestData.js';
import SkyblockItem from '../Structures/SkyBlock/SkyblockItem.js';
import { expect, expectTypeOf, test } from 'vitest';

test('getSkyblockItems (raw)', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
const data = await client.getSkyblockItems({ raw: true });
expect(data).toBeDefined();
expect(data).toBeInstanceOf(RequestData);
expectTypeOf(data).toEqualTypeOf<SkyblockItem[] | RequestData>();
client.destroy();
});

test('getSkyblockItems', async () => {
const client = new Client(process.env.HYPIXEL_KEY ?? '', { cache: false, checkForUpdates: false, rateLimit: 'NONE' });
let data = await client.getSkyblockItems();
expect(data).toBeDefined();
expectTypeOf(data).toEqualTypeOf<SkyblockItem[] | RequestData>();
data = data as SkyblockItem[];
data.forEach((item: SkyblockItem) => {
expect(item.durability).toBeDefined();
expectTypeOf(item.durability).toEqualTypeOf<number | undefined>();

expect(item.museumData).toBeDefined();
expectTypeOf(item.museumData).toEqualTypeOf<Record<string, any> | undefined>();

expect(item.hasUuid).toBeDefined();
expectTypeOf(item.hasUuid).toEqualTypeOf<boolean | string | undefined>();

expect(item.gemstoneSlots).toBeDefined();
expectTypeOf(item.gemstoneSlots).toEqualTypeOf<Record<string, any>[] | undefined>();

expect(item.glowing).toBeDefined();
expectTypeOf(item.glowing).toEqualTypeOf<boolean | undefined>();

expect(item.canAuction).toBeDefined();
expectTypeOf(item.canAuction).toEqualTypeOf<boolean | undefined>();

expect(item.canTrade).toBeDefined();
expectTypeOf(item.canTrade).toEqualTypeOf<boolean | undefined>();

expect(item.requirements).toBeDefined();
expectTypeOf(item.requirements).toEqualTypeOf<Record<string, any>[] | undefined>();

expect(item.canPlace).toBeDefined();
expectTypeOf(item.canPlace).toEqualTypeOf<boolean | undefined>();

expect(item.museum).toBeDefined();
expectTypeOf(item.museum).toEqualTypeOf<boolean | undefined>();

expect(item.generator).toBeDefined();
expectTypeOf(item.generator).toEqualTypeOf<string | undefined>();

expect(item.generatorTier).toBeDefined();
expectTypeOf(item.generatorTier).toEqualTypeOf<number | undefined>();

expect(item.furniture).toBeDefined();
expectTypeOf(item.furniture).toEqualTypeOf<string | undefined>();

expect(item.itemSpecific).toBeDefined();
expectTypeOf(item.itemSpecific).toEqualTypeOf<Record<string, any> | undefined>();

expect(item.description).toBeDefined();
expectTypeOf(item.description).toEqualTypeOf<string | undefined>();

expect(item.upgradeCosts).toBeDefined();
expectTypeOf(item.upgradeCosts).toEqualTypeOf<Array<Array<Record<string, any>>> | undefined>();

expect(item.gearScore).toBeDefined();
expectTypeOf(item.gearScore).toEqualTypeOf<number | undefined>();

expect(item.dungeonItem).toBeDefined();
expectTypeOf(item.dungeonItem).toEqualTypeOf<boolean | undefined>();

expect(item.dungeonItemConversionCost).toBeDefined();
expectTypeOf(item.dungeonItemConversionCost).toEqualTypeOf<Record<string, any> | undefined>();

expect(item.catacombsRequirements).toBeDefined();
expectTypeOf(item.catacombsRequirements).toEqualTypeOf<Record<string, any>[] | undefined>();

expect(item.canHaveAttributes).toBeDefined();
expectTypeOf(item.canHaveAttributes).toEqualTypeOf<boolean | undefined>();

expect(item.salvageableFromRecipe).toBeDefined();
expectTypeOf(item.salvageableFromRecipe).toEqualTypeOf<boolean | undefined>();

expect(item.canRecombobulate).toBeDefined();
expectTypeOf(item.canRecombobulate).toEqualTypeOf<boolean | undefined>();

expect(item.enchantments).toBeDefined();
expectTypeOf(item.enchantments).toEqualTypeOf<Record<string, any> | undefined>();

expect(item.riftTransferrable).toBeDefined();
expectTypeOf(item.riftTransferrable).toEqualTypeOf<boolean | undefined>();

expect(item.origin).toBeDefined();
expectTypeOf(item.origin).toEqualTypeOf<string | undefined>();

expect(item.doubleTapToDrop).toBeDefined();
expectTypeOf(item.doubleTapToDrop).toEqualTypeOf<boolean | undefined>();

expect(item.hideFromViewRecipeCommand).toBeDefined();
expectTypeOf(item.hideFromViewRecipeCommand).toEqualTypeOf<boolean | undefined>();

expect(item.swordType).toBeDefined();
expectTypeOf(item.swordType).toEqualTypeOf<string | undefined>();

expect(item.abilityDamageScaling).toBeDefined();
expectTypeOf(item.abilityDamageScaling).toEqualTypeOf<number | undefined>();

expect(item.tieredStats).toBeDefined();
expectTypeOf(item.tieredStats).toEqualTypeOf<Record<string, any> | undefined>();

expect(item.motesSellPrice).toBeDefined();
expectTypeOf(item.motesSellPrice).toEqualTypeOf<number | undefined>();

expect(item.crystal).toBeDefined();
expectTypeOf(item.crystal).toEqualTypeOf<string | undefined>();

expect(item.canBurnInFurnace).toBeDefined();
expectTypeOf(item.canBurnInFurnace).toEqualTypeOf<boolean | undefined>();

expect(item.salvage).toBeDefined();
expectTypeOf(item.salvage).toEqualTypeOf<Record<string, any> | undefined>();

expect(item.serializable).toBeDefined();
expectTypeOf(item.serializable).toEqualTypeOf<boolean | undefined>();

expect(item.canInteract).toBeDefined();
expectTypeOf(item.canInteract).toEqualTypeOf<boolean | undefined>();

expect(item.canInteractRightClick).toBeDefined();
expectTypeOf(item.canInteractRightClick).toEqualTypeOf<boolean | undefined>();

expect(item.privateIsland).toBeDefined();
expectTypeOf(item.privateIsland).toEqualTypeOf<string | undefined>();

expect(item.canHavePowerScroll).toBeDefined();
expectTypeOf(item.canHavePowerScroll).toEqualTypeOf<boolean | undefined>();

expect(item.canInteractEntity).toBeDefined();
expectTypeOf(item.canInteractEntity).toEqualTypeOf<boolean | undefined>();

expect(item.miningFortune).toBeDefined();
expectTypeOf(item.miningFortune).toEqualTypeOf<number | undefined>();

expect(item.recipes).toBeDefined();
expectTypeOf(item.recipes).toEqualTypeOf<Record<string, any>[] | undefined>();

expect(item.cannotReforge).toBeDefined();
expectTypeOf(item.cannotReforge).toEqualTypeOf<boolean | undefined>();

expect(item.loseMotesValueOnTransfer).toBeDefined();
expectTypeOf(item.loseMotesValueOnTransfer).toEqualTypeOf<boolean | undefined>();

expect(item.prestige).toBeDefined();
expectTypeOf(item.prestige).toEqualTypeOf<Record<string, any> | undefined>();
});
client.destroy();
});
21 changes: 21 additions & 0 deletions src/API/getSkyblockItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Client from '../Client.js';
import Endpoint from '../Private/Endpoint.js';
import RequestData from '../Private/RequestData.js';
import SkyblockItem from '../Structures/SkyBlock/SkyblockItem.js';
import type { RequestOptions } from '../Types/Requests.js';

class getSkyblockItems extends Endpoint {
override readonly client: Client;
constructor(client: Client) {
super(client);
this.client = client;
}

override async execute(options?: RequestOptions): Promise<SkyblockItem[] | RequestData> {
const res = await this.client.requestHandler.request('/resources/skyblock/items', options);
if (res.options.raw) return res;
return res.data.items.map((i: any) => new SkyblockItem(i));
}
}

export default getSkyblockItems;
2 changes: 2 additions & 0 deletions src/API/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import getSkyblockBingo from './getSkyblockBingo.js';
import getSkyblockFireSales from './getSkyblockFireSales.js';
import getSkyblockGarden from './getSkyblockGarden.js';
import getSkyblockGovernment from './getSkyblockGovernment.js';
import getSkyblockItems from './getSkyblockItems.js';
import getSkyblockMember from './getSkyblockMember.js';
import getSkyblockMuseum from './getSkyblockMuseum.js';
import getSkyblockNews from './getSkyblockNews.js';
Expand Down Expand Up @@ -51,6 +52,7 @@ export default {
getSkyblockMuseum,
getSkyblockNews,
getSkyblockProfiles,
getSkyblockItems,
getStatus,
getWatchdogStats
};
5 changes: 5 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import RequestData from './Private/RequestData.js';
import RequestHandler from './Private/RequestHandler.js';
import SkyblockGarden from './Structures/SkyBlock/SkyblockGarden.js';
import SkyblockItem from './Structures/SkyBlock/SkyblockItem.js';
import SkyblockMember from './Structures/SkyBlock/SkyblockMember.js';
import SkyblockMuseum from './Structures/SkyBlock/SkyblockMuseum.js';
import SkyblockNews from './Structures/SkyBlock/News/SkyblockNews.js';
Expand All @@ -40,7 +41,7 @@
import type { ClientOptions } from './Types/Client.js';
import type { RequestOptions } from './Types/Requests.js';

const clients: Client[] = [];

Check warning on line 44 in src/Client.ts

View workflow job for this annotation

GitHub Actions / check linting (eslint)

'Client' was used before it was defined

class Client {
declare options: ClientOptions;
Expand Down Expand Up @@ -231,6 +232,10 @@
throw new Error(this.errors.ENDPOINT_NOT_LOADED);
}

public getSkyblockItems(options?: RequestOptions): Promise<SkyblockItem[] | RequestData> {
throw new Error(this.errors.ENDPOINT_NOT_LOADED);
}

public getStatus(query: string, options?: RequestOptions): Promise<Status | RequestData> {
throw new Error(this.errors.ENDPOINT_NOT_LOADED);
}
Expand Down
128 changes: 128 additions & 0 deletions src/Structures/SkyBlock/SkyblockItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
class SkyblockItem {
name: string;
material: string;
id: string;
durability?: number;
skin?: Record<string, any>;
category?: string;
tier?: string;
npcSellPrice?: number;
salvages?: Record<string, any>[];
raritySalvageable?: boolean;
stats?: Record<string, any>;
unstackable?: boolean;
museumData?: Record<string, any>;
color?: string;
soulbound?: string;
hasUuid?: boolean | string;
gemstoneSlots?: Record<string, any>[];
glowing?: boolean;
canAuction?: boolean;
canTrade?: boolean;
requirements?: Record<string, any>[];
canPlace?: boolean;
museum?: boolean;
generator?: string;
generatorTier?: number;
furniture?: string;
itemSpecific?: Record<string, any>;
description?: string;
upgradeCosts?: Array<Array<Record<string, any>>>;
gearScore?: number;
dungeonItem?: boolean;
dungeonItemConversionCost?: Record<string, any>;
catacombsRequirements?: Record<string, any>[];
canHaveAttributes?: boolean;
salvageableFromRecipe?: boolean;
canRecombobulate?: boolean;
enchantments?: Record<string, any>;
riftTransferrable?: boolean;
origin?: string;
doubleTapToDrop?: boolean;
hideFromViewRecipeCommand?: boolean;
swordType?: string;
abilityDamageScaling?: number;
tieredStats?: Record<string, any>;
motesSellPrice?: number;
crystal?: string;
canBurnInFurnace?: boolean;
salvage?: Record<string, any>;
serializable?: boolean;
canInteract?: boolean;
canInteractRightClick?: boolean;
privateIsland?: string;
canHavePowerScroll?: boolean;
canInteractEntity?: boolean;
miningFortune?: number;
recipes?: Record<string, any>[];
cannotReforge?: boolean;
loseMotesValueOnTransfer?: boolean;
prestige?: Record<string, any>;
constructor(data: Record<string, any>) {
this.name = data.name;
this.material = data.material;
this.id = data.id;
this.durability = data.durability ?? 0;
this.skin = data.skin ?? {};
this.category = data.category ?? '';
this.tier = data.tier ?? '';
this.npcSellPrice = data.npc_sell_price ?? 0;
this.salvages = data.salvages ?? [];
this.raritySalvageable = data.rarity_salvageable ?? false;
this.stats = data.stats ?? {};
this.unstackable = data.unstackable ?? false;
this.museumData = data.museum_data ?? {};
this.color = data.color ?? '';
this.soulbound = data.soulbound ?? '';
this.hasUuid = data.has_uuid ?? false;
this.gemstoneSlots = data.gemstone_slots ?? [];
this.glowing = data.glowing ?? false;
this.canAuction = data.can_auction ?? false;
this.canTrade = data.can_trade ?? false;
this.requirements = data.requirements ?? [];
this.canPlace = data.can_place ?? false;
this.museum = data.museum ?? false;
this.generator = data.generator ?? '';
this.generatorTier = data.generator_tier ?? 0;
this.furniture = data.furniture ?? '';
this.itemSpecific = data.item_specific ?? {};
this.description = data.description ?? '';
this.upgradeCosts = data.upgrade_costs ?? [];
this.gearScore = data.gear_score ?? 0;
this.dungeonItem = data.dungeon_item ?? false;
this.dungeonItemConversionCost = data.dungeon_item_conversion_cost ?? {};
this.catacombsRequirements = data.catacombs_requirements ?? [];
this.canHaveAttributes = data.can_have_attributes ?? false;
this.salvageableFromRecipe = data.salvageable_from_recipe ?? false;
this.canRecombobulate = data.can_recombobulate ?? false;
this.enchantments = data.enchantments ?? {};
this.riftTransferrable = data.rift_transferrable ?? false;
this.origin = data.origin ?? '';
this.doubleTapToDrop = data.double_tap_to_drop ?? false;
this.hideFromViewRecipeCommand = data.hide_from_viewrecipe_command ?? false;
this.swordType = data.sword_type ?? '';
this.abilityDamageScaling = data.ability_damage_scaling ?? 0;
this.tieredStats = data.tiered_stats ?? {};
this.motesSellPrice = data.motes_sell_price ?? 0;
this.crystal = data.crystal ?? '';
this.canBurnInFurnace = data.can_burn_in_furnace ?? false;
this.salvage = data.salvage ?? {};
this.serializable = data.serializable ?? false;
this.canInteract = data.can_interact ?? false;
this.canInteractRightClick = data.can_interact_right_click ?? false;
this.privateIsland = data.private_island ?? '';
this.canHavePowerScroll = data.can_have_power_scroll ?? false;
this.canInteractEntity = data.can_interact_entity ?? false;
this.miningFortune = data.MINING_FORTUNE ?? 0;
this.recipes = data.recipes ?? [];
this.cannotReforge = data.cannot_reforge ?? false;
this.loseMotesValueOnTransfer = data.lose_motes_value_on_transfer ?? false;
this.prestige = data.prestige ?? {};
}

toString(): string {
return this.name;
}
}

export default SkyblockItem;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ import SkyWarsPackages from './Structures/MiniGames/SkyWars/SkyWarsPackages.js';
import SkyblockGarden from './Structures/SkyBlock/SkyblockGarden.js';
import SkyblockGemstone from './Structures/SkyBlock/SkyblockGemstone.js';
import SkyblockInventoryItem from './Structures/SkyBlock/SkyblockInventoryItem.js';
import SkyblockItem from './Structures/SkyBlock/SkyblockItem.js';
import SkyblockMember from './Structures/SkyBlock/SkyblockMember.js';
import SkyblockMemberMinion from './Structures/SkyBlock/SkyblockMemberMinion.js';
import SkyblockMemberMinions from './Structures/SkyBlock/SkyblockMemberMinions.js';
Expand Down Expand Up @@ -323,6 +324,7 @@ export default {
SkyblockGarden,
SkyblockGemstone,
SkyblockInventoryItem,
SkyblockItem,
SkyblockMember,
SkyblockMemberMinion,
SkyblockMemberMinions,
Expand Down
Loading