Browse Source

Add functional cross-server leaderboard

pull/41/head
Abheek Dhawan 3 years ago
parent
commit
69e57317eb
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 9
      src/commands/top.ts
  2. 2
      src/index.ts

9
src/commands/top.ts

@ -14,7 +14,7 @@ export async function execute(interaction) {
userScore userScore
.find({}) .find({})
.sort({ score: -1 }) // Sort by descending order .sort({ score: -1 }) // Sort by descending order
.exec((err, obj) => { .exec(async (err, obj) => {
if (err) { if (err) {
log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' }); log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' });
console.log(err); console.log(err);
@ -42,11 +42,10 @@ export async function execute(interaction) {
embeds.push(leaderboardEmbed); embeds.push(leaderboardEmbed);
let sMessageContent = ''; let sMessageContent = '';
const members = interaction.guild.members.cache; const members = await interaction.guild.members.fetch();
const serverLeaderBoardArray = obj.filter(o => members.some(m => m.user.id === o.authorID)); const serverLeaderBoardArray = await obj.filter(o => members.some(m => m.user.id === o.authorID));
console.log(serverLeaderBoardArray[0]); if (serverLeaderBoardArray.length > 10) {
if (serverLeaderBoardArray.length < 10) {
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
sMessageContent += `${i + 1}: <@${serverLeaderBoardArray[i].authorID}>: ${serverLeaderBoardArray[i].score}\n`; sMessageContent += `${i + 1}: <@${serverLeaderBoardArray[i].authorID}>: ${serverLeaderBoardArray[i].score}\n`;
} }

2
src/index.ts

@ -6,7 +6,7 @@ import { token } from './helpers/env';
import log from './helpers/log'; import log from './helpers/log';
const client = new Client({ const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS], intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS],
}); });
client['commands'] = new Collection(); client['commands'] = new Collection();

Loading…
Cancel
Save