From 80b93c1a14ec018b25c53d495f9a4c8ecf34b9bd Mon Sep 17 00:00:00 2001 From: Kevin Pierce Date: Sun, 26 Jul 2020 15:17:45 -0400 Subject: [PATCH] Now can send a leaderboard message for death data, in which the top 10 countries along with their respective death cases is sent in an embed --- commands/leaderboard.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/commands/leaderboard.js b/commands/leaderboard.js index 4c23f17..91fc1a3 100644 --- a/commands/leaderboard.js +++ b/commands/leaderboard.js @@ -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"]