Skip to content

Commit

Permalink
leaderboard fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Jul 22, 2024
1 parent 54d5b33 commit 5508cb3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion commands/Economy/clean-leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CleanLeaderboard extends Command {

if (verified) {
toRemove.forEach(async (i) => {
await db.delete(`servers.${msg.guild.id}.users.${i}.economy`);
await db.delete(`servers.${msg.guild.id}.users.${i}`);
});
return msg.channel.send(`${toRemove.length} users have been removed from the leaderboard.`);
} else {
Expand Down
9 changes: 6 additions & 3 deletions commands/Economy/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Leaderboard extends Command {

for (const userId in usersData) {
try {
const user = await this.client.users.cache.get(userId);
const user = await this.client.users.fetch(userId);
if (user) {
const cash = BigInt(usersData[userId]?.economy?.cash || 0);
const bank = BigInt(usersData[userId]?.economy?.bank || 0);
Expand All @@ -43,15 +43,18 @@ class Leaderboard extends Command {
const sortedLeaderboard = leaderboard
.sort((a, b) => (b.money > a.money ? 1 : -1))
.map((c, index) => {
let moneyStr = `${c.money.toLocaleString()}`;
const bigMoney = BigInt(c.money);
const neg = bigMoney < 0n;
const money = neg ? -bigMoney : bigMoney;
let moneyStr = `${money.toLocaleString()}`;
if (moneyStr.length > 150) {
moneyStr = moneyStr.slice(0, 147) + '...';
}
return {
rank: index + 1,
user: c.user,
userId: c.userId,
display: `**${index + 1}.** ${c.user}: ${c.money < 0n ? '-' : ''}${currencySymbol}${moneyStr}`,
display: `**${index + 1}.** ${c.user}: ${bigMoney < 0n ? '-' : ''}${currencySymbol}${moneyStr}`,
};
});

Expand Down
11 changes: 7 additions & 4 deletions slash_commands/Economy/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ exports.run = async (interaction) => {
try {
const user = await interaction.client.users.fetch(userId);
if (user) {
const cash = BigInt(parseInt(usersData[userId].economy.cash || 0, 10));
const bank = BigInt(parseInt(usersData[userId].economy.bank || 0, 10));
const cash = BigInt(usersData[userId].economy.cash || 0);
const bank = BigInt(usersData[userId].economy.bank || 0);
const money = cash + bank;
leaderboard.push({ user: user.tag, userId: user.id, money });
}
Expand All @@ -50,15 +50,18 @@ exports.run = async (interaction) => {
const sortedLeaderboard = leaderboard
.sort((a, b) => (b.money > a.money ? 1 : -1))
.map((c, index) => {
let moneyStr = `${Math.abs(Number(c.money)).toLocaleString()}`;
const bigMoney = BigInt(c.money);
const neg = bigMoney < 0n;
const money = neg ? -bigMoney : bigMoney;
let moneyStr = `${money.toLocaleString()}`;
if (moneyStr.length > 150) {
moneyStr = moneyStr.slice(0, 147) + '...';
}
return {
rank: index + 1,
user: c.user,
userId: c.userId,
display: `**${index + 1}.** ${c.user}: ${c.money < 0n ? '-' : ''}${currencySymbol}${moneyStr}`,
display: `**${index + 1}.** ${c.user}: ${bigMoney < 0n ? '-' : ''}${currencySymbol}${moneyStr}`,
};
});

Expand Down

0 comments on commit 5508cb3

Please sign in to comment.