Compare commits

...

2 commits

Author SHA1 Message Date
dartz
1c82c1d5ca display electoral votes if the election type supports it 2024-07-23 17:55:44 -04:00
dartz
b7033305ec we can save an api call here 2024-07-23 17:47:14 -04:00

View file

@ -72,11 +72,12 @@ if (!config.token) {
.setDescription("API test") .setDescription("API test")
.addFields(Object.values(results[year][0].candidates).map((candidate: any) => ({ .addFields(Object.values(results[year][0].candidates).map((candidate: any) => ({
name: `${candidate.winner ? ":white_check_mark:" : ""} ${CandidateEmojis[candidate.party] ?? ""} ${candidate.name} ${candidate.incumbent ? "(I)" : ""} (${candidate.party})`, name: `${candidate.winner ? ":white_check_mark:" : ""} ${CandidateEmojis[candidate.party] ?? ""} ${candidate.name} ${candidate.incumbent ? "(I)" : ""} (${candidate.party})`,
value: `${candidate.votes.toLocaleString()} votes (${candidate.percent}%)`, value: `${results[year][0].election_type === "electoral" ? `${candidate.electoral_votes} electoral votes\n` : ""} ${candidate.votes.toLocaleString()} votes (${candidate.percent}%)`,
inline: true inline: true
}))) })))
.setTimestamp(); .setTimestamp();
if(results[year][0].has_map === true) {
const map = await fetch(`http://127.0.0.1:3000/api/v1/election/${country}/${election_type}/${year}/map`); // temp test url const map = await fetch(`http://127.0.0.1:3000/api/v1/election/${country}/${election_type}/${year}/map`); // temp test url
if (map.ok) { if (map.ok) {
const arrayBuffer = await map.arrayBuffer(); const arrayBuffer = await map.arrayBuffer();
@ -88,7 +89,10 @@ if (!config.token) {
await i.editReply({embeds: [embed]}); await i.editReply({embeds: [embed]});
break; break;
} }
} else {
await i.editReply({embeds: [embed]});
break; break;
}
} else { } else {
await i.editReply("Election not found"); await i.editReply("Election not found");
break; break;