Skip to content

Commit

Permalink
feat: update 10 Days in Public leaderboard to accept custom start and…
Browse files Browse the repository at this point in the history
… end dates and display them in the leaderboard title
  • Loading branch information
taciturnaxolotl committed Feb 16, 2024
1 parent 687d031 commit a453d5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ app.get("/g/:id", async (req, res) => {

// #10daysinpublic leaderboard
app.get("/s/10days", async (req, res) => {
const leaderboard = await get10DaysLeaderboard();
const leaderboard = await get10DaysLeaderboard(
new Date("2024-02-15"),
new Date("2024-02-30"),
);
streamData(req, res, leaderboard);
});

Expand Down
8 changes: 4 additions & 4 deletions utils/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function generateLeaderboardTable(users: user[]): string {
].join("\n");
}

export async function get10DaysLeaderboard() {
export async function get10DaysLeaderboard(start: Date, end: Date) {
const users: user[] = [];

const response = await fetch(
Expand All @@ -69,8 +69,8 @@ export async function get10DaysLeaderboard() {
);

if (
timestampAdjusted.getTime() < new Date("2024-02-15").getTime() ||
timestampAdjusted.getTime() > new Date("2024-02-30").getTime()
timestampAdjusted.getTime() < start.getTime() ||
timestampAdjusted.getTime() > end.getTime()
) {
return;
}
Expand All @@ -92,7 +92,7 @@ export async function get10DaysLeaderboard() {
});

// display the leaderboard in markdown format
const leaderboardFormatted = `# 10 Days in Public Leaderboard\n\n${generateLeaderboardTable(users)}`;
const leaderboardFormatted = `# 10 Days in Public Leaderboard from ${start.toISOString().split("T")[0]} to ${end.toISOString().split("T")[0]}\nGood Luck and have fun!\n\n${generateLeaderboardTable(users)}`;

return leaderboardFormatted;
}

0 comments on commit a453d5d

Please sign in to comment.