Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 RecentGame from './Structures/RecentGame.js';
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 Down Expand Up @@ -231,6 +232,10 @@ class Client {
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
38 changes: 38 additions & 0 deletions src/Structures/SkyBlock/SkyblockItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { parseRarity } from '../../Utils/SkyblockUtils.js';

class SkyblockItem {
color: string | null;
material: string;
name: string;
tier: string;
id: string;
category: string;
npc_sell_price: number;
stats: Record<string, number>;
rarity_salvageable: boolean;
salvages: Record<string, number>;
soulbound: string | null;
is_soulbound: boolean;
skin: Record<string, number>;
constructor(data: Record<string, any>) {
this.color = data.color || null;
this.material = data.material;
this.name = data.name;
this.tier = parseRarity(data.tier || '');
this.id = data.id;
this.category = data.category;
this.npc_sell_price = data.npc_sell_price || 0;
this.stats = data.stats || {};
this.rarity_salvageable = data.rarity_salvageable || false;
this.salvages = data.salvages || {};
this.soulbound = data.soulbound || null;
this.is_soulbound = Boolean(this.soulbound);
this.skin = data.skin || {};
}

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