Skip to content

Commit

Permalink
Now can send a leaderboard message for death data, in which the top 1…
Browse files Browse the repository at this point in the history
…0 countries along with their respective death cases is sent in an embed
  • Loading branch information
kevin-pierce committed Jul 26, 2020
1 parent d4b601b commit 80b93c1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions commands/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,30 @@ module.exports = {
leadingDeaths.sort(compareDeaths);
leadingRecoveries.sort(compareRecoveries);
leadingCases.sort(compareCases);

const leadingEmbed = new Discord.MessageEmbed()
.setColor("#990000")
.setTitle("Global COVID-19 Stats")
.addField("Most Deaths", formatData(leadingDeaths), true);

// for (let countryNum = 0; countryNum < 9; countryNum++){
// `${leadingDeaths[countryNum]["country"]}:${leadingDeaths[countryNum]["deaths"]}`, true);
// }

return message.channel.send(leadingEmbed);
}
}
}

let formatData = (arr) => {
let msg = ``;

for (let countryNum = 0; countryNum < 10; countryNum++){
msg += `${countryNum + 1}: ${arr[countryNum]["country"]} :flag_${arr[countryNum]["countryInfo"]["iso2"].toLowerCase()}:: ${arr[countryNum]["deaths"]}\n`
}
return msg;
}

let compareDeaths = (a, b) => {
// Use toUpperCase() to ignore character casing
const countryA = a["deaths"]
Expand Down

0 comments on commit 80b93c1

Please sign in to comment.