Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from Mirasaki/dev
Browse files Browse the repository at this point in the history
Add player data limit customization
  • Loading branch information
Mirasaki authored May 15, 2022
2 parents 56e3004 + 474ebc1 commit ed05df2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ TEST_SERVER_GUILD_ID=
CFTOOLS_API_APPLICATION_ID=
CFTOOLS_API_SECRET=
CFTOOLS_SERVER_API_ID=
# Amount of players to display on the leaderboard. 10 min, 25 max
CFTOOLS_API_PLAYER_DATA_COUNT=15

# Debug variables
DEBUG_ENABLED=true
Expand Down
16 changes: 14 additions & 2 deletions src/commands/dayz/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const { parseSnakeCaseArray, colorResolver } = require('../../util');
// Destructure from our process env
const {
DEBUG_LEADERBOARD_API_DATA,
NODE_ENV
NODE_ENV,
CFTOOLS_API_PLAYER_DATA_COUNT
} = process.env;

// Mapping our leaderboard stat options
Expand Down Expand Up @@ -89,14 +90,25 @@ module.exports = {
mappedStat = Statistic.KILLS;
}

// Getting our player data count
let playerLimit = Number(CFTOOLS_API_PLAYER_DATA_COUNT);
if (
isNaN(playerLimit)
|| playerLimit < 10
|| playerLimit > 25
) {
// Overwrite the provided player limit back to default if invalid
playerLimit = 15;
}

let res;
try {
// Fetching our leaderboard data from the CFTools API
res = await cftClient
.getLeaderboard({
order: 'ASC',
statistic: mappedStat,
limit: 15
limit: playerLimit
});
} catch (err) {
// Properly logging the error if it is encountered
Expand Down

0 comments on commit ed05df2

Please sign in to comment.