Skip to content

Commit

Permalink
Fix and enhance aoc embed (#121)
Browse files Browse the repository at this point in the history
* fix undefined issue

* better print
  • Loading branch information
Kr0nox authored Dec 14, 2023
1 parent 402bb69 commit dd9def6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions modules/aoc/aocEmbedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export async function embedLeaderboard(id:number, year: number) : Promise<EmbedB
map[m.name] = "";
for (const k in m.completion_day_level) {
let emoji = ":eight_pointed_black_star:";
if (m.completion_day_level[k]["1"].get_star_ts != 0) {
if (m.completion_day_level[k]["2"].get_star_ts != 0) {
if (m.completion_day_level[k]["1"] != undefined && m.completion_day_level[k]["1"].get_star_ts != 0) {
if (m.completion_day_level[k]["2"] != undefined && m.completion_day_level[k]["2"].get_star_ts != 0) {
emoji = ":star2:";
} else {
emoji = ":star:";
Expand All @@ -26,7 +26,15 @@ export async function embedLeaderboard(id:number, year: number) : Promise<EmbedB
map[m.name] = map[m.name] + emoji;
}
}

return new EmbedBuilder().setURL("https://adventofcode.com").setTitle("Advent of Code Leaderboard")
.addFields({name:"Ranking", value:members.map(e => { return e.name + ": " + e.local_score + map[e.name]; }).join("\n")});

.addFields(
...members.filter(m => map[m.name] != undefined && map[m.name].length > 0)
.map(m => {
return {
name: m.name + ": " + m.local_score,
value: map[m.name]
};
})
);
}

0 comments on commit dd9def6

Please sign in to comment.