Skip to content

Commit

Permalink
New Endpoints (#508)
Browse files Browse the repository at this point in the history
* Add Skyblock Government API and related structures

* feat(bingo)

* fix tests

* fix tests

* fix tests

* final fix tests

* final final fix tests

* feat(Quest, Guild & normal Achivements and Challengs)

* styles(Prettier)

* feat(types)

* Update Skyblock Auctions

* styles(prettier)

* Remove Testing Code

* fix(tests)
  • Loading branch information
Kathund authored Mar 24, 2024
1 parent 2d97ba9 commit 1db82d9
Show file tree
Hide file tree
Showing 55 changed files with 1,540 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd-16x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: npm i

- name: es-lint
run: npm run eslint
run: npm run lint

tests:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd-18x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: npm i

- name: es-lint
run: npm run eslint
run: npm run lint

tests:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ testing/
.circleci/
changelog.md
master.json
.env
.env
.vscode/settings.json
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"url": "https://github.com/Hypixel-API-Reborn/hypixel-api-reborn/issues"
},
"scripts": {
"eslint": "npx eslint src/ typings/",
"eslint:fix": "npx eslint src/ typings/ --fix",
"lint": "npx eslint src/ typings/",
"lint:fix": "npx eslint src/ typings/ --fix",
"lint:dev": "npm run eslint && npm run dtslint",
"tests": "npx mocha tests --exit",
"tests": "npx mocha tests --exit --recursive",
"docgen": "npx docgen -s src -o ./master.json",
"dtslint": "npx dtslint typings",
"prettier": "npx prettier --write src/ typings/",
Expand Down
6 changes: 6 additions & 0 deletions src/API/getAchievements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = async function () {
const Achievements = require('../structures/Static/Achievements');
const res = await this._makeRequest('/resources/achievements');
if (res.raw) return res;
return new Achievements(res);
};
6 changes: 6 additions & 0 deletions src/API/getChallenges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = async function () {
const Challenges = require('../structures/Static/Challenges');
const res = await this._makeRequest('/resources/challenges');
if (res.raw) return res;
return new Challenges(res);
};
6 changes: 6 additions & 0 deletions src/API/getGuildAchievements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = async function () {
const GuildAchievements = require('../structures/Static/GuildAchievements');
const res = await this._makeRequest('/resources/guilds/achievements');
if (res.raw) return res;
return new GuildAchievements(res);
};
6 changes: 6 additions & 0 deletions src/API/getQuests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = async function () {
const Quests = require('../structures/Static/Quests');
const res = await this._makeRequest('/resources/quests');
if (res.raw) return res;
return new Quests(res);
};
48 changes: 30 additions & 18 deletions src/API/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
module.exports = {
getAPIStatus: require('./getAPIStatus'),
getBoosters: require('./getBoosters'),
getGameCounts: require('./getGameCounts'),
getGuild: require('./getGuild'),
getLeaderboards: require('./getLeaderboards'),
getPlayer: require('./getPlayer'),
getRecentGames: require('./getRecentGames'),
getServerInfo: require('./getServerInfo'),
getStatus: require('./getStatus'),
getWatchdogStats: require('./getWatchdogStats'),
getEndedSkyblockAuctions: require('./skyblock/getEndedSkyblockAuctions'),
getSkyblockAuctions: require('./skyblock/getSkyblockAuctions'),
getSkyblockAuctionsByPlayer: require('./skyblock/getSkyblockAuctionsByPlayer'),
getSkyblockBazaar: require('./skyblock/getSkyblockBazaar'),
getSkyblockMember: require('./skyblock/getSkyblockMember'),
getSkyblockNews: require('./skyblock/getSkyblockNews'),
getSkyblockProfiles: require('./skyblock/getSkyblockProfiles'),
getSkyblockMuseum: require('./skyblock/getSkyblockMuseum')
getAchievements: require('./getAchievements.js'),
getAPIStatus: require('./getAPIStatus.js'),
getBoosters: require('./getBoosters.js'),
getChallenges: require('./getChallenges.js'),
getGameCounts: require('./getGameCounts.js'),
getGuild: require('./getGuild.js'),
getGuildAchievements: require('./getGuildAchievements.js'),
getLeaderboards: require('./getLeaderboards.js'),
getPlayer: require('./getPlayer.js'),
getQuests: require('./getQuests.js'),
getRecentGames: require('./getRecentGames.js'),
getServerInfo: require('./getServerInfo.js'),
getStatus: require('./getStatus.js'),
getWatchdogStats: require('./getWatchdogStats.js'),

skyblock: {
getAuction: require('./skyblock/getAuction.js'),
getAuctions: require('./skyblock/getAuctions.js'),
getAuctionsByPlayer: require('./skyblock/getAuctionsByPlayer.js'),
getBazaar: require('./skyblock/getBazaar.js'),
getBingo: require('./skyblock/getBingo.js'),
getBingoByPlayer: require('./skyblock/getBingoByPlayer.js'),
getEndedAuctions: require('./skyblock/getEndedAuctions.js'),
getFireSales: require('./skyblock/getFireSales.js'),
getGovernment: require('./skyblock/getGovernment.js'),
getMember: require('./skyblock/getMember.js'),
getMuseum: require('./skyblock/getMuseum.js'),
getNews: require('./skyblock/getNews.js'),
getProfiles: require('./skyblock/getProfiles.js')
}
};
19 changes: 19 additions & 0 deletions src/API/skyblock/getAuction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Errors = require('../../Errors');
const toUuid = require('../../utils/toUuid');
module.exports = async function (type, query, includeItemBytes = false) {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
const Auction = require('../../structures/SkyBlock/Auctions/Auction');
let filter = '';
if (type === 'PROFILE') {
filter = 'profile';
} else if (type === 'PLAYER') {
query = await toUuid(query);
filter = 'player';
} else if (type === 'AUCTION') {
filter = 'uuid';
} else throw new Error(Errors.BAD_AUCTION_FILTER);
const res = await this._makeRequest(`/skyblock/auction?${filter}=${query}`);
if (res.raw) return res;

return res.auctions.length ? res.auctions.map((a) => new Auction(a, includeItemBytes)) : [];
};
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const toUuid = require('../../utils/toUuid');
module.exports = async function (query, includeItemBytes = false) {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
const Auction = require('../../structures/SkyBlock/Auctions/Auction');
query = await toUuid(query, this.options.mojangCacheTime);
query = await toUuid(query);
const res = await this._makeRequest(`/skyblock/auction?player=${query}`);
if (res.raw) return res;

Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions src/API/skyblock/getBingo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = async function () {
const BingoData = require('../../structures/SkyBlock/Static/BingoData');

const res = await this._makeRequest('/resources/skyblock/bingo');
if (res.raw) return res;

return new BingoData(res);
};
14 changes: 14 additions & 0 deletions src/API/skyblock/getBingoByPlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const getBingo = require('./getBingo');
const toUuid = require('../../utils/toUuid');
const Errors = require('../../Errors');
module.exports = async function (query, { fetchBingoData = false }) {
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
const PlayerBingo = require('../../structures/SkyBlock/PlayerBingo');
query = await toUuid(query);
const res = await this._makeRequest(`/skyblock/uuid?player=${query}`);
if (res.raw) return res;
let bingoData = null;
if (fetchBingoData) bingoData = await getBingo.call(this);

return new PlayerBingo(data, bingoData);
};
File renamed without changes.
7 changes: 7 additions & 0 deletions src/API/skyblock/getFireSales.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = async function () {
const FireSale = require('../../structures/SkyBlock/Static/FireSale');
const res = await this._makeRequest('/skyblock/firesales');
if (res.raw) return res;

return res.sales.length ? res.sales.map((a) => new FireSale(a)) : [];
};
8 changes: 8 additions & 0 deletions src/API/skyblock/getGovernment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = async function () {
const GovernmentData = require('../../structures/SkyBlock/Static/Government.js');

const res = await this._makeRequest('/resources/skyblock/election');
if (res.raw) return res;

return new GovernmentData(res);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const toUuid = require('../../utils/toUuid');
const getPlayer = require('../getPlayer');
module.exports = async function (query, options = { fetchPlayer: false, getMuseum: false }) {
const SkyblockMember = require('../../structures/SkyBlock/SkyblockMember');
const getSkyblockMuseum = require('../skyblock/getSkyblockMuseum');
const getSkyblockMuseum = require('../skyblock/getMuseum');
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query, this.options.mojangCacheTime);
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const toUuid = require('../../utils/toUuid');
const getPlayer = require('../getPlayer');
module.exports = async function (query, options = { fetchPlayer: false, getMuseum: false }) {
const SkyblockProfile = require('../../structures/SkyBlock/SkyblockProfile');
const getSkyblockMuseum = require('../skyblock/getSkyblockMuseum');
const getSkyblockMuseum = require('../skyblock/getMuseum');
if (!query) throw new Error(Errors.NO_NICKNAME_UUID);
query = await toUuid(query, this.options.mojangCacheTime);
const res = await this._makeRequest(`/skyblock/profiles?uuid=${query}`);
Expand Down
69 changes: 60 additions & 9 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@ class Client extends EventEmitter {
validate.validateOptions(this.options);
// eslint-disable-next-line guard-for-in
for (const func in API) {
Client.prototype[func] = function (...args) {
if (func === 'skyblock') continue;
Client.prototype[func] = (...args) => {
const lastArg = args[args.length - 1];
return API[func].apply(
{
_makeRequest: this._makeRequest.bind(this, { ...(validate.cacheSuboptions(lastArg) ? lastArg : {}) }),
_makeRequest: this._makeRequest.bind(this, validate.cacheSuboptions(lastArg) ? lastArg : {}),
...this
},
args
);
};
}
Client.prototype.skyblock = {};
// eslint-disable-next-line guard-for-in
for (const func in API.skyblock) {
Client.prototype.skyblock[func] = (...args) => {
const lastArg = args[args.length - 1];
return API.skyblock[func].apply(
{
_makeRequest: this._makeRequest.bind(this, validate.cacheSuboptions(lastArg) ? lastArg : {}),
...this
},
args
Expand Down Expand Up @@ -176,7 +191,7 @@ class Client extends EventEmitter {
/**
* Allows you to get all skyblock profiles of player
* @method
* @name Client#getSkyblockProfiles
* @name Client.skyblock#getProfiles
* @param {string} query Player nickname or UUID
* @param {SkyblockMethodOptions} [options={}] Method options
* @return {Promise<Array<SkyblockProfile>>}
Expand All @@ -190,7 +205,7 @@ class Client extends EventEmitter {
/**
* Allows you to get a player's skyblock member data from all their profiles
* @method
* @name Client#getSkyblockMember
* @name Client.skyblock#getMember
* @param {string} query Player nickname or UUID
* @param {SkyblockMethodOptions} [options={}] Method options
* @return {Promise<Map<string,SkyblockMember>>}
Expand All @@ -205,7 +220,7 @@ class Client extends EventEmitter {
/**
* Allows you to get a player's skyblock profile museum
* @method
* @name Client#getSkyblockMuseum
* @name Client.skyblock#getMuseum
* @param {string} query Player nickname or UUID
* @param {string} profileId Profile ID
* @return {Promise<SkyblockMuseum>}
Expand Down Expand Up @@ -275,7 +290,7 @@ class Client extends EventEmitter {
/**
* Allows you to get skyblock auctions
* @method
* @name Client#getSkyblockAuctions
* @name Client.skyblock#getAuctions
* @param {string|number|number[]} page - "*", a page number, or an array with the start and the end page number ( automatically sorted )
* @param {auctionsOptions} [options={}] Options
* @return {Promise<{info:AuctionInfo,auctions:Auction[]}>}
Expand All @@ -288,7 +303,7 @@ class Client extends EventEmitter {
/**
* Allows you to get player's skyblock auctions
* @method
* @name Client#getSkyblockAuctionsByPlayer
* @name Client.skyblock#getAuctionsByPlayer
* @param {string} query - player nickname or uuid
* @param {boolean} [includeItemBytes=false] - include item bytes (optional)
* @param {MethodOptions} [options={}] Options
Expand All @@ -315,19 +330,47 @@ class Client extends EventEmitter {
/**
* Allows you to get list of products
* @method
* @name Client#getSkyblockBazaar
* @name Client.skyblock#getBazaar
* @param {MethodOptions} [options={}] Options
* @return {Promise<Product[]>}
* @example
* hypixel.getSkyblockBazaar().then(products =>{
* console.log(products[0].productId); // INK_SACK:3
* })
* .catch(console.log);
*/ /**
* Allows you to get bingo data
* @method
* @name Client.skyblock#getBingo
* @param {MethodOptions} [options={}] Options
* @return {Promise<BingoData>}
*/
/**
* Allows you to get bingo data of a player
* @method
* @name Client.skyblock#getBingoByPlayer
* @param {string} query UUID / IGN of player
* @param {PlayerBingoOptions} [options={}] Options
* @return {Promise<PlayerBingo>}
*/
/**
* Allows you to get SB government
* @method
* @name Client.skyblock#getGovernment
* @param {MethodOptions} [options={}] Options
* @return {Promise<GovernmentData>}
*/
/**
* Allows you to get SB government
* @method
* @name Client.skyblock#getFireSale
* @param {MethodOptions} [options={}] Options
* @return {Promise<FireSale[]>}
*/
/**
* Allows you to get skyblock news
* @method
* @name Client#getSkyblockNews
* @name Client.skyblock#getNews
* @param {MethodOptions} [options={}] Options
* @return {Promise<SkyblockNews[]>}
* @example
Expand Down Expand Up @@ -417,4 +460,12 @@ const SkyblockMuseum = require('./structures/SkyBlock/SkyblockMuseum.js');
* @property {boolean} [includeItemBytes=false] Whether to include item bytes in the result
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
*/
/**
* @typedef {object} PlayerBingoOptions
* @property {boolean} [raw=false] Raw data
* @property {boolean} [noCacheCheck=false] Disable/Enable cache checking
* @property {boolean} [noCaching=false] Disable/Enable writing to cache
* @property {boolean} [fetchBingoData=false] Fetches bingo data to give more information
* @prop {object} [headers={}] Extra Headers ( like User-Agent ) to add to request. Overrides the headers globally provided.
*/
module.exports = Client;
3 changes: 2 additions & 1 deletion src/Errors.js

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

9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
Pets: require('./structures/Pets'),
PlayerCosmetics: require('./structures/PlayerCosmetics'),

/* Challenges */
Challenges: require('./structures/Static/Challenges.js'),
GameChallenges: require('./structures/Static/GameChallenges.js'),

/* Watchdog */
WatchdogStats: require('./structures/Watchdog/Stats.js'),

Expand All @@ -27,13 +31,18 @@ module.exports = {
SkyblockMember: require('./structures/SkyBlock/SkyblockMember.js'),
SkyblockInventoryItem: require('./structures/SkyBlock/SkyblockInventoryItem.js'),
SkyblockPet: require('./structures/SkyBlock/SkyblockPet'),
GovernmentData: require('./structures/SkyBlock/Static/Government.js'),
Candidate: require('./structures/SkyBlock/Static/Candidate.js'),
BingoData: require('./structures/SkyBlock/Static/BingoData.js'),
Bingo: require('./structures/SkyBlock/Static/Bingo.js'),

/* Skyblock Auctions */
BaseAuction: require('./structures/SkyBlock/Auctions/BaseAuction.js'),
PartialAuction: require('./structures/SkyBlock/Auctions/PartialAuction.js'),
Auction: require('./structures/SkyBlock/Auctions/Auction.js'),
AuctionInfo: require('./structures/SkyBlock/Auctions/AuctionInfo.js'),
Bid: require('./structures/SkyBlock/Auctions/Bid.js'),
FireSale: require('./structures/SkyBlock/Static/FireSale.js'),

/* Skyblock Bazaar */
Product: require('./structures/SkyBlock/Bazzar/Product.js'),
Expand Down
Loading

0 comments on commit 1db82d9

Please sign in to comment.