saiteja-madha / discord-js-bot

🤖 Multipurpose discord bot built using discord.js v14 with moderation, music, ticketing, translation, and much more
https://strangedocs.hostz.me
Apache License 2.0
696 stars 699 forks source link

Reputation Leaderboard #458

Open MohamedShadd opened 10 months ago

MohamedShadd commented 10 months ago

The reputation leaderboard also says Deleted user

async function getRepLeaderboard(author) {
  // Create a cache key using the user ID and the type of leaderboard
  const cacheKey = `${author.id}:rep`;

  // Check if there is a cached result for this request
  if (cache.has(cacheKey)) {
    // Return the cached result if it exists
    return cache.get(cacheKey);
  }

  const lb = await getReputationLb(10);
  if (lb.length === 0) return "There are no users in the leaderboard";

  let collector = "";
  for (let i = 0; i < lb.length; i++) {
    try {
      const user = await author.client.users.fetch(lb[i].member_id);
      collector += `**#${(i + 1).toString()}** - ${escapeInlineCode(user.tag)} [${lb[i].rep}]\n`;
    } catch (ex) {
      collector += `**#${(i + 1).toString()}** - DeletedUser#0000 [${lb[i].rep}]\n`;
    }
  }

  const embed = new EmbedBuilder()
    .setAuthor({ name: "Reputation Leaderboard" })
    .setColor(EMBED_COLORS.BOT_EMBED)
    .setDescription(collector)
    .setFooter({ text: `Requested by ${author.tag}` });

  // Store the result in the cache for future requests
  cache.set(cacheKey, { embeds: [embed] });
  return { embeds: [embed] };
}
image
NavIshanOp commented 2 days ago

Hey check this once :- https://github.com/saiteja-madha/discord-js-bot/pull/552