From ba22f256d72b02dc1db0a01c9d29f2e8a0029fdd Mon Sep 17 00:00:00 2001 From: Adam Reisenauer Date: Sat, 13 Mar 2021 09:00:12 -0500 Subject: [PATCH 1/3] Added ability to get guild data from ID (guilds/id/{guildID}) --- package-lock.json | 4 +- routes/parameters.js | 9 +++ routes/spec.graphql | 12 ++++ routes/spec.js | 160 ++++++++++++++++++++++++++++++++++++++++++- store/buildGuild.js | 13 +++- test/test.js | 3 +- 6 files changed, 195 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index de0a7e5b..9eab24f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3472,8 +3472,8 @@ } }, "hypixelconstants": { - "version": "github:slothpixel/hypixelconstants#2d92f504b4a8516a1dcc0a690653769569b024a9", - "from": "github:slothpixel/hypixelconstants" + "version": "git+ssh://git@github.com/slothpixel/hypixelconstants.git#2d92f504b4a8516a1dcc0a690653769569b024a9", + "from": "hypixelconstants@slothpixel/hypixelconstants" }, "iconv-lite": { "version": "0.4.24", diff --git a/routes/parameters.js b/routes/parameters.js index 4098664d..15b15824 100644 --- a/routes/parameters.js +++ b/routes/parameters.js @@ -17,6 +17,15 @@ module.exports = { type: 'string', }, }, + guildIDParam: { + name: 'guildID', + in: 'path', + description: 'ID of guild.', + required: true, + schema: { + type: 'string', + }, + }, gameNameParam: { name: 'game', in: 'path', diff --git a/routes/spec.graphql b/routes/spec.graphql index 78190063..17ad1ce7 100644 --- a/routes/spec.graphql +++ b/routes/spec.graphql @@ -50,6 +50,18 @@ type Query { populate_players: String ): Guild + guild_by_id( + """ + ID of guild. + """ + guild_id: String! + + """ + Replace uuid fields with player profiles + """ + populate_players: String + ): Guild + """ Returns player or guild leaderboards diff --git a/routes/spec.js b/routes/spec.js index 72acfee6..52028877 100644 --- a/routes/spec.js +++ b/routes/spec.js @@ -9,7 +9,7 @@ const getUUID = require('../store/getUUID'); const buildBans = require('../store/buildBans'); const buildBoosters = require('../store/buildBoosters'); const { queryAuctionId } = require('../store/queryAuctions'); -const { getGuildFromPlayer, getGuildFromName } = require('../store/buildGuild'); +const { getGuildFromPlayer, getGuildFromName, getGuildFromID } = require('../store/buildGuild'); const { buildProfileList, buildProfile } = require('../store/buildSkyBlockProfiles'); const { playerObject } = require('./objects'); const { populatePlayers, getPlayer, PlayerError } = require('../store/buildPlayer'); @@ -21,7 +21,7 @@ const { playerNameParam, gameNameParam, typeParam, columnParam, filterParam, sortByParam, limitParam, significantParam, populatePlayersParam, templateParam, itemIdParam, bazaarItemIdParam, fromParam, toParam, auctionUUIDParam, itemUUIDParam, activeParam, pageParam, sortOrderParam, - profileIdParam, guildNameParam, + profileIdParam, guildNameParam, guildIDParam, } = require('./parameters'); const packageJson = require('../package.json'); @@ -1003,6 +1003,162 @@ Consider supporting The Slothpixel Project on Patreon to help cover the hosting }, }, }, + '/guilds/id/{guildID}': { + get: { + summary: 'Get guild stats by the name of the guild', + description: 'Look up a guild from the its name', + operationId: 'guild', + tags: [ + 'guild', + ], + parameters: [ + guildIDParam, + ], + responses: { + 200: { + description: 'successful operation', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + name: { + description: 'Guild\'s name', + type: 'string', + }, + id: { + description: 'Guild id used in hypixel backend', + type: 'string', + }, + created: { + description: 'Guild creation date', + type: 'string', + }, + tag: { + description: 'Guild tag', + type: 'string', + }, + tag_color: { + description: 'Formatting code for the guild tag', + type: 'string', + }, + tag_formatted: { + description: 'Formatted tag string e.g. \'&b[TAG]\'', + type: 'string', + }, + legacy_ranking: { + description: 'Ranking in the number of guild coins owned in the legacy guild system', + type: 'integer', + }, + exp: { + description: 'Total guild xp', + type: 'integer', + }, + level: { + description: 'Guild level', + type: 'number', + }, + exp_by_game: { + description: 'Guild EXP earned in each minigame', + type: 'integer', + }, + exp_history: { + description: 'Contains raw guild xp earned in the past week. Uses format YYYY-MM-DD.', + type: 'object', + }, + description: { + description: 'Guild description', + type: 'string', + }, + preferred_games: { + description: 'Array containing the guild\'s preferred games', + type: 'array', + items: { + type: 'string', + }, + }, + ranks: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string', + }, + permissions: { + type: 'array', + items: { + type: 'number', + }, + }, + default: { + type: 'boolean', + }, + tag: { + type: 'string', + }, + created: { + type: 'integer', + }, + priority: { + type: 'integer', + }, + }, + }, + }, + members: { + description: 'Array playerof players on the guild', + type: 'array', + items: { + type: 'object', + properties: { + uuid: { + description: 'Player UUID', + type: 'string', + }, + rank: { + description: 'Player rank in the guild', + type: 'string', + }, + joined: { + description: 'Member join date', + type: 'integer', + }, + quest_participation: { + description: 'How many much the member has contributed to guild quests', + type: 'integer', + }, + exp_history: { + description: 'Contains raw guild xp earned in the past week. Uses format YYYY-MM-DD.', + type: 'object', + }, + muted_till: { + description: 'Date the member is muted until', + type: 'integer', + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + route: () => '/guilds/id/:id', + func: async (request, response, callback) => { + try { + const guild = await getGuildFromID(request.params.id); + if (guild.guild === null) { + return response.status(404).json(guild); + } + return response.json(guild); + } catch (error) { + callback(error); + } + }, + }, + }, /* '/sessions/{playerName}': { get: { diff --git a/store/buildGuild.js b/store/buildGuild.js index 8bd94d58..81c0df84 100644 --- a/store/buildGuild.js +++ b/store/buildGuild.js @@ -119,4 +119,15 @@ async function getGuildFromName(guildName, { shouldPopulatePlayers = false } = { return guild; } -module.exports = { getGuildFromPlayer, getGuildFromName, getGuildData }; +async function getGuildFromID(guildID, { shouldPopulatePlayers = false } = {}) { + const guild = await getGuildData(guildID); + if (shouldPopulatePlayers) { + const players = await populatePlayers(guild.members); + guild.members = players; + } + return guild; +} + +module.exports = { + getGuildFromPlayer, getGuildFromName, getGuildData, getGuildFromID, +}; diff --git a/test/test.js b/test/test.js index 4027367b..c6003a29 100644 --- a/test/test.js +++ b/test/test.js @@ -116,7 +116,8 @@ describe('api', () => { || path.endsWith('/status') || path.endsWith('/friends') || path.includes('/bazaar') - || path.includes('/guilds/name')) { + || path.includes('/guilds/name') + || path.includes('guilds/id')) { return callback__(error); } return supertest(app)[verb](`/api${replacedPath}?q=testsearch`).end((error, response) => { From d2f79916f1488a3427a94eb225f771014b8fa28c Mon Sep 17 00:00:00 2001 From: Adam Reisenauer Date: Sat, 13 Mar 2021 09:28:39 -0500 Subject: [PATCH 2/3] Added populate players --- routes/spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/spec.js b/routes/spec.js index 52028877..739b2926 100644 --- a/routes/spec.js +++ b/routes/spec.js @@ -992,7 +992,7 @@ Consider supporting The Slothpixel Project on Patreon to help cover the hosting route: () => '/guilds/name/:name', func: async (request, response, callback) => { try { - const guild = await getGuildFromName(request.params.name); + const guild = await getGuildFromName(request.params.name, { shouldPopulatePlayers: request.query.populatePlayers }); if (guild.guild === null) { return response.status(404).json(guild); } @@ -1148,7 +1148,7 @@ Consider supporting The Slothpixel Project on Patreon to help cover the hosting route: () => '/guilds/id/:id', func: async (request, response, callback) => { try { - const guild = await getGuildFromID(request.params.id); + const guild = await getGuildFromID(request.params.id, { shouldPopulatePlayers: request.query.populatePlayers }); if (guild.guild === null) { return response.status(404).json(guild); } From 340c338529cec1d7bc45daee79c5b40ea1cfea27 Mon Sep 17 00:00:00 2001 From: builder_247 <14019974+builder-247@users.noreply.github.com> Date: Sun, 14 Mar 2021 19:42:48 +0200 Subject: [PATCH 3/3] Added missing documentation --- routes/spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/spec.js b/routes/spec.js index 739b2926..a371c016 100644 --- a/routes/spec.js +++ b/routes/spec.js @@ -856,7 +856,7 @@ Consider supporting The Slothpixel Project on Patreon to help cover the hosting 'guild', ], parameters: [ - guildNameParam, + guildNameParam, populatePlayersParam, ], responses: { 200: { @@ -1012,7 +1012,7 @@ Consider supporting The Slothpixel Project on Patreon to help cover the hosting 'guild', ], parameters: [ - guildIDParam, + guildIDParam, populatePlayersParam, ], responses: { 200: {