Skip to content

Commit 277acf2

Browse files
authored
Merge pull request #514 from uwcsc/issue#-471
Issue# 471 resolved
2 parents b127cc5 + e49dc99 commit 277acf2

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/commandDetails/coin/leaderboard.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const getCoinLeaderboardEmbed = async (
2929
let rank = 0;
3030
let offset = 0;
3131
let i = 0;
32+
let absoluteCount = 0;
3233
while (leaderboardArray.length < LEADERBOARD_LIMIT_DISPLAY || position === 0) {
3334
if (i === LEADERBOARD_LIMIT_FETCH) {
3435
offset += LEADERBOARD_LIMIT_FETCH;
@@ -46,10 +47,15 @@ const getCoinLeaderboardEmbed = async (
4647
continue;
4748
}
4849
if (user.bot) continue;
49-
if (previousBalance !== userCoinEntry.balance) {
50+
if (previousBalance === userCoinEntry.balance) {
5051
previousBalance = userCoinEntry.balance;
51-
rank = rank + 1;
52+
// rank does not change
53+
} else {
54+
previousBalance = userCoinEntry.balance;
55+
rank = absoluteCount + 1;
5256
}
57+
// count how many total users have been processed:
58+
absoluteCount++;
5359
if (userCoinEntry.user_id === userId) {
5460
position = rank;
5561
}
@@ -64,7 +70,8 @@ const getCoinLeaderboardEmbed = async (
6470
.join('\\_')
6571
.split('`')
6672
.join('\\`');
67-
const userCoinEntryText = `${rank}. ${cleanUserTag} - ${
73+
// added a "\\" below in ${rank}\\. ${cleanUserTag} so that Markdown does not automatically increment by 1 each time
74+
const userCoinEntryText = `${rank}\\. ${cleanUserTag} - ${
6875
userCoinEntry.balance
6976
} ${getCoinEmoji()}`;
7077
leaderboardArray.push(userCoinEntryText);
@@ -81,7 +88,6 @@ const getCoinLeaderboardEmbed = async (
8188
value: `You are currently **#${position}** in the leaderboard with ${userBalance} ${getCoinEmoji()}.`,
8289
},
8390
]);
84-
8591
return leaderboardEmbed;
8692
};
8793

0 commit comments

Comments
 (0)