Skip to content

Commit

Permalink
Support more gamemodes in the /status endpoint (slothpixel#668)
Browse files Browse the repository at this point in the history
* Added new system for sorting through gamemodes in Hypixel Constants

* Update processors/processPlayerStatus.js

Co-authored-by: Richie Bendall <richiebendall@gmail.com>

* Update processors/processPlayerStatus.js

Forgot space (ty)

Co-authored-by: Richie Bendall <richiebendall@gmail.com>

* Reduced amount of Conditional operators used

Trying to see if there is a way to not need any for the `return` part but at current stage they seem required

* Fixed errors

* Update hypixelconstants

* Update package-lock.json

* Update processPlayerStatus.js

* Fixed spacing and Useless conditional

slothpixel#668 (comment)

* Forgot to make changes for Useless conditional

* Spaces being stupid

* Update processors/processPlayerStatus.js

Co-authored-by: Richie Bendall <richiebendall@gmail.com>

* Adding changes

* Update processPlayerStatus.js

Co-authored-by: Richie Bendall <richiebendall@gmail.com>
  • Loading branch information
2 people authored and ChristianDobbie committed Jan 10, 2022
1 parent 8a673dc commit 94b2862
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"filter-obj": "^2.0.1",
"got": "^11.8.1",
"graphql": "^15.5.0",
"hypixelconstants": "^3.3.3",
"hypixelconstants": "^3.3.4",
"ioredis": "^4.27.2",
"moment": "^2.29.1",
"morgan": "^1.10.0",
Expand Down
20 changes: 15 additions & 5 deletions processors/processPlayerStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ const { game_types: gameTypes, modes, maps } = require('hypixelconstants');

const gameTypes_ = new Map(gameTypes
.map(({ type_name: typeName, clean_name: cleanName }) => [typeName, cleanName]));
const modes_ = new Map(modes
.map(({ key, modes }) => [key, modes])
.filter(([_, modes]) => modes)
.map(([key, modes]) => [key, new Map(modes.map(({ key, name }) => [key, name]))]));
const maps_ = new Map(Object.entries(maps)
.map(([game, maps]) => [game, new Map(Object.entries(maps).map((([map, { name }]) => [map, name])))]));

function getMode(type, mode){
const game = modes.find(({key}) => key === type);
if (!game) return mode;
const subGame = game.modes.find(
({key}) => key === "DREAMS" || key === "lab"
);
return game.modes.find(({key, keys}) =>
(keys && keys.includes(mode)) || key == mode
)
|| (subGame && subGame.modes.find(({key, keys}) =>
(keys && keys.includes(mode)) || key == mode
));
}

module.exports = ({
online,
gameType: type,
Expand All @@ -18,7 +28,7 @@ module.exports = ({
online,
game: {
type: gameTypes_.get(type) || null,
mode: mode === 'LOBBY' ? 'Lobby' : (modes_.has(type) ? modes_.get(type).get(mode) || null : null),
mode: mode === 'LOBBY' ? 'Lobby' : (getMode(type, mode) ? getMode(type, mode).name || getMode(type, mode) : null),
map: maps_.has(type) ? maps_.get(type).get(map) || null : map || null,
},
});

0 comments on commit 94b2862

Please sign in to comment.