Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude bots from leaderboard #281

Merged
merged 7 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/production/vars.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"NOTIF_CHANNEL_ID": "872305316522508329",
"ANNOUNCEMENTS_CHANNEL_ID": "669294029804011540",
"OFFICE_STATUS_CHANNEL_ID": "997926133083422740",
"RESUME_CHANNEL_ID": "824068952933924924"
"RESUME_CHANNEL_ID": "824068952933924924",
"IRC_USER_ID": "806518167404937260"
}
14 changes: 8 additions & 6 deletions src/commandDetails/coin/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ const getCurrentCoinLeaderboardEmbed = async (
const userBalance = await getCoinBalanceByUserId(currentUserId);
const currentPosition = await getUserIdCurrentCoinPosition(currentUserId);

let currentLeaderboardText = '';
for (let i = 0; i < limit; i++) {
if (leaderboard.length <= i) break;
const leaderboardArray: string[] = [];
for (let i = 0; i < leaderboard.length && leaderboardArray.length < limit; i++) {
const userCoinEntry = leaderboard[i];
const user = await client.users.fetch(userCoinEntry.user_id);
if (user.bot) continue;
const userTag = user?.tag ?? '<unknown>';
const userCoinEntryText = `${i + 1}. ${userTag} - ${userCoinEntry.balance} ${getCoinEmoji()}\n`;
currentLeaderboardText += userCoinEntryText;
const userCoinEntryText = `${leaderboardArray.length + 1}. ${userTag} - ${userCoinEntry.balance} ${getCoinEmoji()}`;
leaderboardArray.push(userCoinEntryText);
}
const currentLeaderboardText = leaderboardArray.join('\n');
const currentLeaderboardEmbed = new MessageEmbed()
.setColor(EMBED_COLOUR)
.setTitle('CodeyCoin Leaderboard')
Expand All @@ -56,7 +57,8 @@ const coinCurrentLeaderboardExecuteCommand: SapphireMessageExecuteType = async (
_args
): Promise<SapphireMessageResponse> => {
const userId = getUserIdFromMessage(messageFromUser);
const leaderboard = await getCurrentCoinLeaderboard();
// Get extra users to filter bots later
const leaderboard = await getCurrentCoinLeaderboard(limit * 2);
return { embeds: [await getCurrentCoinLeaderboardEmbed(client, leaderboard, userId)] };
};

Expand Down
6 changes: 6 additions & 0 deletions src/listeners/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PDFDocument } from 'pdf-lib';

const ANNOUNCEMENTS_CHANNEL_ID: string = vars.ANNOUNCEMENTS_CHANNEL_ID;
const RESUME_CHANNEL_ID: string = vars.RESUME_CHANNEL_ID;
const IRC_USER_ID: string = vars.IRC_USER_ID;

/*
* If honeypot is to exist again, then add HONEYPOT_CHANNEL_ID to the config
Expand Down Expand Up @@ -112,6 +113,11 @@ export class MessageCreateListener extends Listener {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case can be removed, since it is already covered below.


// Ignore all bots besides IRC
if (message.author.bot && message.author.id !== IRC_USER_ID) {
return;
}

if (await punishSpammersAndTrolls(message)) {
return;
}
Expand Down