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 #19 from Mirasaki/blacklist-players
Browse files Browse the repository at this point in the history
Add the ability to blacklist players from being displayed in the leaderboard output
  • Loading branch information
Mirasaki authored May 25, 2022
2 parents 47c757a + 9825496 commit a4ceab9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/blacklist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"6284d7a30873a63f22e34f34",
"CFTools IDs to exclude from the blacklist",
"always use commas (,) at the end of the line EXCEPT THE LAST ONE > like so"
]
14 changes: 10 additions & 4 deletions src/commands/dayz/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const { stripIndents } = require('common-tags/lib');
const cftClient = require('../../modules/cftClient');
const { parseSnakeCaseArray, colorResolver } = require('../../util');

// Include our blacklist file
const leaderboardBlacklist = require('../../../config/blacklist.json');

// Destructure from our process env
const {
DEBUG_LEADERBOARD_API_DATA,
Expand Down Expand Up @@ -108,7 +111,7 @@ module.exports = {
.getLeaderboard({
order: 'ASC',
statistic: mappedStat,
limit: playerLimit
limit: 100
});
} catch (err) {
// Properly logging the error if it is encountered
Expand Down Expand Up @@ -157,8 +160,11 @@ module.exports = {
return;
}

// Filter out our blacklisted ids/entries
const whitelistedData = res.filter((e) => !leaderboardBlacklist.includes(e.id.id));

// Constructing our embed onject
const lbEmbedData = buildLeaderboardEmbed(guild, res, isDefaultQuery, statToGet, mappedStat);
const lbEmbedData = buildLeaderboardEmbed(guild, whitelistedData, isDefaultQuery, statToGet, mappedStat, playerLimit);

// Responding to our request
interaction.editReply({
Expand All @@ -168,7 +174,7 @@ module.exports = {
};

// Dedicated function for building our embed data
const buildLeaderboardEmbed = (guild, res, isDefaultQuery, statToGet, mappedStat) => {
const buildLeaderboardEmbed = (guild, res, isDefaultQuery, statToGet, mappedStat, playerLimit) => {
// Initializing our embed vars
let description = '';
let fields = [];
Expand Down Expand Up @@ -225,7 +231,7 @@ const buildLeaderboardEmbed = (guild, res, isDefaultQuery, statToGet, mappedStat

// Returning our build embed data
return {
fields,
fields: fields.slice(0, playerLimit),
color: colorResolver(),
author: {
name: description,
Expand Down
1 change: 1 addition & 0 deletions src/modules/cftClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {

// export our CFTools client as unnamed default
module.exports = new cftSDK.CFToolsClientBuilder()
.withCache()
.withServerApiId(CFTOOLS_SERVER_API_ID)
.withCredentials(CFTOOLS_API_APPLICATION_ID, CFTOOLS_API_SECRET)
.build();

0 comments on commit a4ceab9

Please sign in to comment.