Skip to content

Commit

Permalink
feat(discord-manager): add away to get the first 10 people ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
0xwal committed Feb 1, 2024
1 parent e1eb83e commit aed3056
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/classes/discord-challenge-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Client, Embed, Events, Message, MessageType, TextChannel} from "discord.js";
import {Client, Embed, Events, Message, MessageType, TextChannel, EmbedBuilder} from "discord.js";

import * as config from "../config.ts";
import {DiscordChallenge} from "./discord-challenge.ts";
Expand Down Expand Up @@ -51,6 +51,30 @@ export class DiscordChallengeManager {
return;
}

if (message.content == "top") {
// add leaderboard
const leaderboards = await repo.getUsersOrderedByScores(10);
const icons = ["🥇", "🥈", "🥉"];

const embeds = new EmbedBuilder();

embeds.setTitle("Leaderboard");
embeds.setAuthor({name: "0x"});

for (let i = 0; i < leaderboards.length; i++) {
const user = leaderboards[i];
const icon = icons.shift() ?? i + 1;
embeds.addFields({
name: `${icon}`,
value: `<@${user.id}> 🪙 **${user.score}**`,
inline: false
});
}

await message.reply({embeds: [embeds]});
return;
}

const author = message.author;

const challenge = this._challenge;
Expand Down

0 comments on commit aed3056

Please sign in to comment.