From 997e754d1217ad45e5d575e9365721da88dfdd19 Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 14 Aug 2024 12:24:11 +0800 Subject: [PATCH] Request Options --- package.json | 2 +- src/API/API.d.ts | 14 +++++++++++ src/API/getAchievements.ts | 5 ++-- src/API/getActiveHouses.ts | 5 ++-- src/API/getBoosters.ts | 5 ++-- src/API/getChallenges.ts | 5 ++-- src/API/getGameCounts.ts | 5 ++-- src/API/getGuild.ts | 9 +++++-- src/API/getGuildAchievements.ts | 5 ++-- src/API/getHouse.ts | 5 ++-- src/API/getLeaderboards.ts | 5 ++-- src/API/getPlayer.ts | 7 +++--- src/API/getPlayerHouses.ts | 5 ++-- src/API/getQuests.ts | 5 ++-- src/API/getRecentGames.ts | 5 ++-- src/API/getSkyblockAuction.ts | 7 +++--- src/API/getSkyblockAuctions.ts | 34 ++++++++++++++++++++------ src/API/getSkyblockAuctionsByPlayer.ts | 5 ++-- src/API/getSkyblockBazaar.ts | 5 ++-- src/API/getSkyblockBingo.ts | 5 ++-- src/API/getSkyblockBingoByPlayer.ts | 5 ++-- src/API/getSkyblockEndedAuctions.ts | 9 ++++--- src/API/getSkyblockFireSales.ts | 5 ++-- src/API/getSkyblockGarden.ts | 5 ++-- src/API/getSkyblockGovernment.ts | 5 ++-- src/API/getSkyblockMember.ts | 5 ++-- src/API/getSkyblockMuseum.ts | 5 ++-- src/API/getSkyblockNews.ts | 5 ++-- src/API/getSkyblockProfiles.ts | 5 ++-- src/API/getStatus.ts | 5 ++-- src/API/getWatchdogStats.ts | 5 ++-- src/Client.ts | 3 +++ src/Private/Endpoint.ts | 2 +- src/structures/Player.ts | 5 +++- 34 files changed, 142 insertions(+), 70 deletions(-) create mode 100644 src/API/API.d.ts diff --git a/package.json b/package.json index dfd8bfd..2bf64df 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "reborn-ts", + "name": "hypixel-api-reborn", "version": "12.0.0", "description": "Feature-rich Hypixel API wrapper for Node.js", "main": "./src/index.ts", diff --git a/src/API/API.d.ts b/src/API/API.d.ts new file mode 100644 index 0000000..7d6002f --- /dev/null +++ b/src/API/API.d.ts @@ -0,0 +1,14 @@ +import { RequestOptions } from '../Private/Requests'; + +export interface getPlayerRequestOptions extends RequestOptions { + getGuild?: boolean; +} + +export interface AuctionRequestOptions extends RequestOptions { + includeItemBytes?: boolean; +} + +export interface SkyblockRequestyOptions extends RequestOptions { + garden?: boolean; + museum?: boolean; +} diff --git a/src/API/getAchievements.ts b/src/API/getAchievements.ts index 3487ba3..6d95d4d 100644 --- a/src/API/getAchievements.ts +++ b/src/API/getAchievements.ts @@ -1,4 +1,5 @@ import Achievements from '../structures/Static/Achievements'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getAchievements extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/resources/achievements'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/resources/achievements', options); if (res.raw) return res; return new Achievements(res); } diff --git a/src/API/getActiveHouses.ts b/src/API/getActiveHouses.ts index bd467b3..b5c8389 100644 --- a/src/API/getActiveHouses.ts +++ b/src/API/getActiveHouses.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import House from '../structures/House'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getActiveHouses extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/housing/active'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/housing/active', options); if (res.raw) return res; return res.length ? res.map((b: any) => new House(b)) : []; } diff --git a/src/API/getBoosters.ts b/src/API/getBoosters.ts index 2d43f5a..a7c3cd1 100644 --- a/src/API/getBoosters.ts +++ b/src/API/getBoosters.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Booster from '../structures/Boosters/Booster'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getBoosters extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/boosters'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/boosters', options); if (res.raw) return res; return res.boosters.length ? res.boosters.map((b: any) => new Booster(b)).reverse() : []; } diff --git a/src/API/getChallenges.ts b/src/API/getChallenges.ts index ca8c405..cf83798 100644 --- a/src/API/getChallenges.ts +++ b/src/API/getChallenges.ts @@ -1,4 +1,5 @@ import Challenges from '../structures/Static/Challenges'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getChallenges extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/resources/challenges'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/resources/challenges', options); if (res.raw) return res; return new Challenges(res); } diff --git a/src/API/getGameCounts.ts b/src/API/getGameCounts.ts index ac69205..444e977 100644 --- a/src/API/getGameCounts.ts +++ b/src/API/getGameCounts.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import GameCounts from '../structures/GameCounts'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getGameCounts extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/counts'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/counts', options); if (res.raw) return res; return new GameCounts(res); } diff --git a/src/API/getGuild.ts b/src/API/getGuild.ts index 410b01e..fa17890 100644 --- a/src/API/getGuild.ts +++ b/src/API/getGuild.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Guild from '../structures/Guild/Guild'; import isGuildID from '../utils/isGuildID'; import Endpoint from '../Private/Endpoint'; @@ -10,7 +11,11 @@ export default class getGuild extends Endpoint { this.client = client; } - async execute(searchParameter: 'id' | 'name' | 'player', query: string): Promise { + async execute( + searchParameter: 'id' | 'name' | 'player', + query: string, + options?: RequestOptions + ): Promise { if (!query) throw new Error(this.client.errors.NO_GUILD_QUERY); if ('id' === searchParameter && !isGuildID(query)) throw new Error(this.client.errors.INVALID_GUILD_ID); const isPlayerQuery = 'player' === searchParameter; @@ -18,7 +23,7 @@ export default class getGuild extends Endpoint { if (!['id', 'name', 'player'].includes(searchParameter)) { throw new Error(this.client.errors.INVALID_GUILD_SEARCH_PARAMETER); } - const res = await this.client.requests.request(`/guild?${searchParameter}=${encodeURI(query)}`); + const res = await this.client.requests.request(`/guild?${searchParameter}=${encodeURI(query)}`, options); if (res.raw) return res; if (!res.guild && 'player' !== searchParameter) { throw new Error(this.client.errors.GUILD_DOES_NOT_EXIST); diff --git a/src/API/getGuildAchievements.ts b/src/API/getGuildAchievements.ts index 5b4b40e..6cc2af1 100644 --- a/src/API/getGuildAchievements.ts +++ b/src/API/getGuildAchievements.ts @@ -1,4 +1,5 @@ import GuildAchievements from '../structures/Static/GuildAchievements'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getGuildAchievements extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/resources/guilds/achievements'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/resources/guilds/achievements', options); if (res.raw) return res; return new GuildAchievements(res); } diff --git a/src/API/getHouse.ts b/src/API/getHouse.ts index 7830dce..85063a5 100644 --- a/src/API/getHouse.ts +++ b/src/API/getHouse.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import House from '../structures/House'; import Client from '../Client'; @@ -9,9 +10,9 @@ export default class getHouse extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_UUID); - const res = await this.client.requests.request(`/housing/house?house=${query}`); + const res = await this.client.requests.request(`/housing/house?house=${query}`, options); if (res.raw) return res; return new House(res); } diff --git a/src/API/getLeaderboards.ts b/src/API/getLeaderboards.ts index aac8d0e..297bba7 100644 --- a/src/API/getLeaderboards.ts +++ b/src/API/getLeaderboards.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Leaderboard from '../structures/Leaderboard'; import Constants from '../utils/Constants'; import Endpoint from '../Private/Endpoint'; @@ -10,8 +11,8 @@ export default class getLeaderboards extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/leaderboards'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/leaderboards', options); if (res.raw) return res; if (!res.leaderboards) throw new Error(this.client.errors.SOMETHING_WENT_WRONG.replace(/{cause}/, 'Try again.')); const lbnames = Object.create(Constants.leaderboardNames); diff --git a/src/API/getPlayer.ts b/src/API/getPlayer.ts index 70b952e..a2c1c91 100644 --- a/src/API/getPlayer.ts +++ b/src/API/getPlayer.ts @@ -1,3 +1,4 @@ +import { getPlayerRequestOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Player from '../structures/Player'; import Client from '../Client'; @@ -9,12 +10,12 @@ export default class getPlayer extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: getPlayerRequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/player?uuid=${query}`); + const res = await this.client.requests.request(`/player?uuid=${query}`, options); if (res.raw) return res; if (query && !res.player) throw new Error(this.client.errors.PLAYER_HAS_NEVER_LOGGED); - return new Player(res.player); + return new Player(res.player, options?.getGuild ? await this.client.getGuild('player', query) : undefined); } } diff --git a/src/API/getPlayerHouses.ts b/src/API/getPlayerHouses.ts index 0816205..9739a53 100644 --- a/src/API/getPlayerHouses.ts +++ b/src/API/getPlayerHouses.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import House from '../structures/House'; import Client from '../Client'; @@ -9,10 +10,10 @@ export default class getPlayerHouses extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/housing/houses?player=${query}`); + const res = await this.client.requests.request(`/housing/houses?player=${query}`, options); if (res.raw) return res; return res.length ? res.map((h: any) => new House(h)) : []; } diff --git a/src/API/getQuests.ts b/src/API/getQuests.ts index b3a09e1..1c11114 100644 --- a/src/API/getQuests.ts +++ b/src/API/getQuests.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Quests from '../structures/Static/Quests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getQuests extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/resources/quests'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/resources/quests', options); if (res.raw) return res; return new Quests(res); } diff --git a/src/API/getRecentGames.ts b/src/API/getRecentGames.ts index b2cf575..f9e3c1a 100644 --- a/src/API/getRecentGames.ts +++ b/src/API/getRecentGames.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import RecentGame from '../structures/RecentGame'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,10 +10,10 @@ export default class getRecentGames extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/recentgames?uuid=${query}`); + const res = await this.client.requests.request(`/recentgames?uuid=${query}`, options); if (res.raw) return res; if (0 === res.games.length) { return []; diff --git a/src/API/getSkyblockAuction.ts b/src/API/getSkyblockAuction.ts index e4715c3..5bab1e4 100644 --- a/src/API/getSkyblockAuction.ts +++ b/src/API/getSkyblockAuction.ts @@ -1,4 +1,5 @@ import Auction from '../structures/SkyBlock/Auctions/Auction'; +import { AuctionRequestOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -12,7 +13,7 @@ export default class getSkyblockAction extends Endpoint { async execute( query: string, type: 'PROFILE' | 'PLAYER' | 'AUCTION', - includeItemBytes: boolean = false + options?: AuctionRequestOptions ): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); let filter; @@ -26,8 +27,8 @@ export default class getSkyblockAction extends Endpoint { } else { throw new Error(this.client.errors.BAD_AUCTION_FILTER); } - const res = await this.client.requests.request(`/skyblock/auction?${filter}=${query}`); + const res = await this.client.requests.request(`/skyblock/auction?${filter}=${query}`, options); if (res.raw) return res; - return res.auctions.length ? res.auctions.map((a: any) => new Auction(a, includeItemBytes)) : []; + return res.auctions.length ? res.auctions.map((a: any) => new Auction(a, options?.includeItemBytes ?? false)) : []; } } diff --git a/src/API/getSkyblockAuctions.ts b/src/API/getSkyblockAuctions.ts index 8c8cbe8..b5927b9 100644 --- a/src/API/getSkyblockAuctions.ts +++ b/src/API/getSkyblockAuctions.ts @@ -1,27 +1,35 @@ import AuctionInfo from '../structures/SkyBlock/Auctions/AuctionInfo'; import Auction from '../structures/SkyBlock/Auctions/Auction'; +import { AuctionRequestOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; +export interface getSkyblockAuctionsOptions extends AuctionRequestOptions { + retries?: number; + cooldown?: number; + race?: boolean; + noAuctions?: boolean; + noInfo?: boolean; +} + export default class getSkyblockAuctions extends Endpoint { readonly client: Client; - readonly name: string; constructor(client: Client) { super(client); this.client = client; - this.name = 'getSkyblockAuctions'; } - async execute(range: any, options: any) { + async execute(range: any, options?: getSkyblockAuctionsOptions) { + options = this.parasOptions(options); options.retries ||= 3; options.cooldown ||= 100; if (null === range || '*' === range) range = [0, (await this.getPage(0, { noAuctions: true })).info.totalPages]; if (!Array.isArray(range)) range = [parseInt(range), parseInt(range)]; if (isNaN(range[0])) throw new Error(this.client.errors.PAGE_INDEX_ERROR); - if (parseInt(options.retries) !== options.retries || 10 < options.retries || 0 > options.retries) { + if (options.retries || 10 < options.retries || 0 > options.retries) { throw new Error(this.client.errors.INVALID_OPTION_VALUE); } - if (parseInt(options.cooldown) !== options.cooldown || 3000 < options.cooldown || 0 > options.cooldown) { + if (options.cooldown || 3000 < options.cooldown || 0 > options.cooldown) { throw new Error(this.client.errors.INVALID_OPTION_VALUE); } range = range.sort(); @@ -60,13 +68,13 @@ export default class getSkyblockAuctions extends Endpoint { return result; } - async getPage(page: any = 0, options: any = {}): Promise { - const content = await this.client.requests.request(`/skyblock/auctions?page=${page}`); + async getPage(page: number, options: getSkyblockAuctionsOptions): Promise { + const content = await this.client.requests.request(`/skyblock/auctions?page=${page}`, options); const result: any = {}; if (!options.noInfo) result.info = new AuctionInfo(content); if (options.raw) result.auctions = content.auctions; else if (options.noAuctions) result.auctions = []; - else result.auctions = content.auctions.map((x: any) => new Auction(x, options.includeItemBytes)); + else result.auctions = content.auctions.map((x: any) => new Auction(x, options?.includeItemBytes ?? false)); return result; } @@ -82,4 +90,14 @@ export default class getSkyblockAuctions extends Endpoint { return null; } } + + private parasOptions(options?: getSkyblockAuctionsOptions): getSkyblockAuctionsOptions { + return { + retries: options?.retries ?? 3, + cooldown: options?.cooldown ?? 100, + race: options?.race ?? false, + noAuctions: options?.noAuctions ?? false, + noInfo: options?.noInfo ?? false + }; + } } diff --git a/src/API/getSkyblockAuctionsByPlayer.ts b/src/API/getSkyblockAuctionsByPlayer.ts index 6b644b2..d8da4d8 100644 --- a/src/API/getSkyblockAuctionsByPlayer.ts +++ b/src/API/getSkyblockAuctionsByPlayer.ts @@ -1,4 +1,5 @@ import Auction from '../structures/SkyBlock/Auctions/Auction'; +import { AuctionRequestOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,11 +10,11 @@ export default class getSkyblockActionsByPlayer extends Endpoint { this.client = client; } - async execute(query: string, includeItemBytes: boolean): Promise { + async execute(query: string, options?: AuctionRequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); const res = await this.client.requests.request(`/skyblock/auction?player=${query}`); if (res.raw) return res; - return res.auctions.length ? res.auctions.map((a: any) => new Auction(a, includeItemBytes)) : []; + return res.auctions.length ? res.auctions.map((a: any) => new Auction(a, options?.includeItemBytes ?? false)) : []; } } diff --git a/src/API/getSkyblockBazaar.ts b/src/API/getSkyblockBazaar.ts index b360560..44404e5 100644 --- a/src/API/getSkyblockBazaar.ts +++ b/src/API/getSkyblockBazaar.ts @@ -1,4 +1,5 @@ import Product from '../structures/SkyBlock/Bazzar/Product'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getSkyblockBazaar extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/skyblock/bazaar'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/skyblock/bazaar', options); if (res.raw) return res; const productsKeys = Object.keys(res.products); return productsKeys.map((x) => new Product(res.products[x])); diff --git a/src/API/getSkyblockBingo.ts b/src/API/getSkyblockBingo.ts index b52a589..923eb3a 100644 --- a/src/API/getSkyblockBingo.ts +++ b/src/API/getSkyblockBingo.ts @@ -1,4 +1,5 @@ import BingoData from '../structures/SkyBlock/Static/BingoData'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getSkyblockBingo extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/resources/skyblock/bingo'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/resources/skyblock/bingo', options); if (res.raw) return res; return new BingoData(res); } diff --git a/src/API/getSkyblockBingoByPlayer.ts b/src/API/getSkyblockBingoByPlayer.ts index 5f89629..e6d531b 100644 --- a/src/API/getSkyblockBingoByPlayer.ts +++ b/src/API/getSkyblockBingoByPlayer.ts @@ -1,4 +1,5 @@ import PlayerBingo from '../structures/SkyBlock/PlayerBingo'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,10 +10,10 @@ export default class getBingoByPlayer extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/uuid?player=${query}`); + const res = await this.client.requests.request(`/skyblock/uuid?player=${query}`, options); if (res.raw) return res; return new PlayerBingo(res); } diff --git a/src/API/getSkyblockEndedAuctions.ts b/src/API/getSkyblockEndedAuctions.ts index 2916113..4f05e27 100644 --- a/src/API/getSkyblockEndedAuctions.ts +++ b/src/API/getSkyblockEndedAuctions.ts @@ -1,5 +1,6 @@ import PartialAuction from '../structures/SkyBlock/Auctions/PartialAuction'; import AuctionInfo from '../structures/SkyBlock/Auctions/AuctionInfo'; +import { AuctionRequestOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -10,12 +11,14 @@ export default class getSkyblockEndedAuctions extends Endpoint { this.client = client; } - async execute(includeItemBytes: any): Promise<{ info: AuctionInfo; auctions: PartialAuction[] }> { - const res = await this.client.requests.request('/skyblock/auctions_ended'); + async execute(options?: AuctionRequestOptions): Promise<{ info: AuctionInfo; auctions: PartialAuction[] }> { + const res = await this.client.requests.request('/skyblock/auctions_ended', options); if (res.raw) return res; return { info: new AuctionInfo({ ...res, totalAuctions: res.auctions.length, totalPages: 1 }), - auctions: res.auctions.length ? res.auctions.map((a: any) => new PartialAuction(a, includeItemBytes)) : [] + auctions: res.auctions.length + ? res.auctions.map((a: any) => new PartialAuction(a, options?.includeItemBytes ?? false)) + : [] }; } } diff --git a/src/API/getSkyblockFireSales.ts b/src/API/getSkyblockFireSales.ts index d1fe015..3917264 100644 --- a/src/API/getSkyblockFireSales.ts +++ b/src/API/getSkyblockFireSales.ts @@ -1,4 +1,5 @@ import FireSale from '../structures/SkyBlock/Static/FireSale'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getSkyblockFireSales extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/skyblock/firesales'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/skyblock/firesales', options); if (res.raw) return res; return res.sales.length ? res.sales.map((a: any) => new FireSale(a)) : []; } diff --git a/src/API/getSkyblockGarden.ts b/src/API/getSkyblockGarden.ts index 19debbd..ceabc08 100644 --- a/src/API/getSkyblockGarden.ts +++ b/src/API/getSkyblockGarden.ts @@ -1,4 +1,5 @@ import SkyblockGarden from '../structures/SkyBlock/SkyblockGarden'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getSkyblockGarden extends Endpoint { this.client = client; } - async execute(profileId: string): Promise { - const res = await this.client.requests.request(`/skyblock/garden?profile=${profileId}`); + async execute(profileId: string, options?: RequestOptions): Promise { + const res = await this.client.requests.request(`/skyblock/garden?profile=${profileId}`, options); if (res.raw) return res; return new SkyblockGarden(res); } diff --git a/src/API/getSkyblockGovernment.ts b/src/API/getSkyblockGovernment.ts index 2bd2443..f010579 100644 --- a/src/API/getSkyblockGovernment.ts +++ b/src/API/getSkyblockGovernment.ts @@ -1,4 +1,5 @@ import GovernmentData from '../structures/SkyBlock/Static/Government.js'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint.js'; import Client from '../Client.js'; @@ -9,8 +10,8 @@ export default class getSkyblockGovernment extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/resources/skyblock/election'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/resources/skyblock/election', options); if (res.raw) return res; return new GovernmentData(res); } diff --git a/src/API/getSkyblockMember.ts b/src/API/getSkyblockMember.ts index 895a30f..7f270dd 100644 --- a/src/API/getSkyblockMember.ts +++ b/src/API/getSkyblockMember.ts @@ -1,4 +1,5 @@ import SkyblockMember from '../structures/SkyBlock/SkyblockMember'; +import { SkyblockRequestyOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,10 +10,10 @@ export default class getSkyblockMember extends Endpoint { this.client = client; } - async execute(query: string): Promise> { + async execute(query: string, options?: SkyblockRequestyOptions): Promise> { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`); + const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`, options); if (res.raw) return res; if (!res.profiles || !res.profiles.length) throw new Error(this.client.errors.NO_SKYBLOCK_PROFILES); const memberByProfileName = new Map(); diff --git a/src/API/getSkyblockMuseum.ts b/src/API/getSkyblockMuseum.ts index 220375b..bb2ef06 100644 --- a/src/API/getSkyblockMuseum.ts +++ b/src/API/getSkyblockMuseum.ts @@ -1,4 +1,5 @@ import SkyblockMuseum from '../structures/SkyBlock/SkyblockMuseum'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,10 +10,10 @@ export default class getSkyblockMuseum extends Endpoint { this.client = client; } - async execute(query: string, profileId: string): Promise { + async execute(query: string, profileId: string, options?: RequestOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/museum?uuid=${query}&profile=${profileId}`); + const res = await this.client.requests.request(`/skyblock/museum?uuid=${query}&profile=${profileId}`, options); if (res.raw) return res; return new SkyblockMuseum({ uuid: query, diff --git a/src/API/getSkyblockNews.ts b/src/API/getSkyblockNews.ts index 2692ae7..1c746d2 100644 --- a/src/API/getSkyblockNews.ts +++ b/src/API/getSkyblockNews.ts @@ -1,4 +1,5 @@ import SkyblockNews from '../structures/SkyBlock/News/SkyblockNews'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getSkyblockNews extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/skyblock/news'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/skyblock/news', options); if (res.raw) return res; return res.items.map((i: any) => new SkyblockNews(i)); } diff --git a/src/API/getSkyblockProfiles.ts b/src/API/getSkyblockProfiles.ts index 72376db..1cb320d 100644 --- a/src/API/getSkyblockProfiles.ts +++ b/src/API/getSkyblockProfiles.ts @@ -1,4 +1,5 @@ import SkyblockProfile from '../structures/SkyBlock/SkyblockProfile'; +import { SkyblockRequestyOptions } from './API'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; export default class getSkyblockProfiles extends Endpoint { @@ -8,10 +9,10 @@ export default class getSkyblockProfiles extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: SkyblockRequestyOptions): Promise { if (!query) throw new Error(this.client.errors.NO_NICKNAME_UUID); query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`); + const res = await this.client.requests.request(`/skyblock/profiles?uuid=${query}`, options); if (res.raw) return res; if (!res.profiles || !res.profiles.length) throw new Error(this.client.errors.NO_SKYBLOCK_PROFILES); diff --git a/src/API/getStatus.ts b/src/API/getStatus.ts index 331d1a3..bb70fd5 100644 --- a/src/API/getStatus.ts +++ b/src/API/getStatus.ts @@ -1,3 +1,4 @@ +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Status from '../structures/Status'; import Client from '../Client'; @@ -9,9 +10,9 @@ export default class getStatus extends Endpoint { this.client = client; } - async execute(query: string): Promise { + async execute(query: string, options?: RequestOptions): Promise { query = await this.client.requests.toUUID(query); - const res = await this.client.requests.request(`/status?uuid=${query}`); + const res = await this.client.requests.request(`/status?uuid=${query}`, options); if (res.raw) return res; return new Status(res.session); } diff --git a/src/API/getWatchdogStats.ts b/src/API/getWatchdogStats.ts index 2e42c80..9bce466 100644 --- a/src/API/getWatchdogStats.ts +++ b/src/API/getWatchdogStats.ts @@ -1,4 +1,5 @@ import WatchdogStats from '../structures/Watchdog/Stats'; +import { RequestOptions } from '../Private/Requests'; import Endpoint from '../Private/Endpoint'; import Client from '../Client'; @@ -9,8 +10,8 @@ export default class getWatchdogStatsEndpoint extends Endpoint { this.client = client; } - async execute(): Promise { - const res = await this.client.requests.request('/punishmentstats'); + async execute(options?: RequestOptions): Promise { + const res = await this.client.requests.request('/punishmentstats', options); if (res.raw) return res; return new WatchdogStats(res); } diff --git a/src/Client.ts b/src/Client.ts index f630910..0d3bd82 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -8,6 +8,9 @@ import API from './API'; const clients: Client[] = []; class Client { + getGuild(...args: any[]): Promise | any { + throw new Error('Method not implemented.'); + } readonly key: string; declare requests: Requests; diff --git a/src/Private/Endpoint.ts b/src/Private/Endpoint.ts index 5963a9e..cc676f7 100644 --- a/src/Private/Endpoint.ts +++ b/src/Private/Endpoint.ts @@ -6,7 +6,7 @@ class Endpoint { this.client = client; } - execute(query?: string, range?: any, options?: any, includeItemBytes?: any): Promise | any { + execute(...args: any[]): Promise | any { throw new Error('Command execute method is not implemented yet!'); } } diff --git a/src/structures/Player.ts b/src/structures/Player.ts index a5efa38..5a25ada 100644 --- a/src/structures/Player.ts +++ b/src/structures/Player.ts @@ -25,6 +25,7 @@ import UHC from './MiniGames/UHC'; import Pit from './MiniGames/Pit'; import Color from './Color'; import Game from './Game'; +import Guild from './Guild/Guild'; export interface LevelProgress { xpToNext: number; @@ -53,6 +54,7 @@ class Player { nickname: string; uuid: string; rank: PlayerRank; + guild: Guild | null; channel: string | null; firstLoginTimestamp: number | null; firstLogin: Date | null; @@ -87,10 +89,11 @@ class Player { globalCosmetics: PlayerCosmetics | null; ranksPurchaseTime: RanksPurchaseTime; - constructor(data: Record) { + constructor(data: Record, guild?: Guild) { this.nickname = data.displayname; this.uuid = data.uuid; this.rank = getRank(data); + this.guild = guild || null; this.channel = data.channel || null; this.firstLoginTimestamp = data.firstLogin || null; this.firstLogin = data.firstLogin ? new Date(data.firstLogin) : null;