Skip to content

Commit

Permalink
Implemented country-specific historic death data which can be narrowe…
Browse files Browse the repository at this point in the history
…d down by number of days
  • Loading branch information
kevin-pierce committed Jul 24, 2020
1 parent 8e558e6 commit 1ed7b7a
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions commands/deaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = {
// Create a new embedded message for the bot to display the historic deaths
const historicDeathEmbed = new Discord.MessageEmbed()
.setColor("#990000")
.setTitle("Historic Deaths for Past 30 Days")
.setTitle("Historic Deaths for the Past 30 Days Globally")
.setImage(`https://quickchart.io/chart?width=500&height=350&c={type:'line',data:{labels:[${xAxisLabels}],datasets:[{label:'Deaths',data:[${deathData}],fill:false,borderColor:"red",pointBackgroundColor:"red"}]},options:{legend:{labels:{fontColor:"white",fontSize:18}},scales:{yAxes:[{ticks:{fontColor:"white",beginAtZero:false,fontSize:16}}],xAxes:[{ticks:{fontColor:"white",fontSize:16}}]}}}`)

return message.channel.send(historicDeathEmbed);
Expand Down Expand Up @@ -140,7 +140,41 @@ module.exports = {
// Create a new embedded message for the bot to display the Country-specific historic deaths
const historicDeathEmbed = new Discord.MessageEmbed()
.setColor("#990000")
.setTitle(`Historic Deaths for Past 30 Days in ${historicCountryDeaths["country"]}`)
.setTitle(`Historic Deaths for the Past 30 Days in ${historicCountryDeaths["country"]}`)
.setImage(`https://quickchart.io/chart?width=500&height=350&c={type:'line',data:{labels:[${xAxisLabels}],datasets:[{label:'Deaths',data:[${countryDeathData}],fill:false,borderColor:"red",pointBackgroundColor:"red"}]},options:{legend:{labels:{fontColor:"white",fontSize:18}},scales:{yAxes:[{ticks:{fontColor:"white",beginAtZero:false,fontSize:16}}],xAxes:[{ticks:{fontColor:"white",fontSize:16}}]}}}`)

return message.channel.send(historicDeathEmbed);
}
// Country specific historic deaths for certain days
else if (args.length == 3) {
let countryName = args.slice(1,2).join(" ");
let numDays = args.slice(2).join(" ");
console.log(countryName);
console.log(numDays);

let getCountryHistoricDeaths = async () => {
let response = await axios.get("https://corona.lmao.ninja/v2/historical/" + countryName + "?lastdays=" + numDays).catch(err =>{
if (err.response){
message.channel.send(`<@${message.author.id}> - Please enter a valid country.`)
}
});
return data = response.data;
}
let historicCountryDeaths = await getCountryHistoricDeaths();

let countryDeathData = [];
let xAxisLabels = [];

// Format x-axis labels and compile data to be used on graph
for (day in historicCountryDeaths["timeline"]["deaths"]){
xAxisLabels.push("\"" + day + "\"");
countryDeathData.push(historicCountryDeaths["timeline"]["deaths"][`${day}`])
}

// Create a new embedded message for the bot to display the Country-specific historic deaths
const historicDeathEmbed = new Discord.MessageEmbed()
.setColor("#990000")
.setTitle(`Historic Deaths for the Past ${numDays} Days in ${historicCountryDeaths["country"]}`)
.setImage(`https://quickchart.io/chart?width=500&height=350&c={type:'line',data:{labels:[${xAxisLabels}],datasets:[{label:'Deaths',data:[${countryDeathData}],fill:false,borderColor:"red",pointBackgroundColor:"red"}]},options:{legend:{labels:{fontColor:"white",fontSize:18}},scales:{yAxes:[{ticks:{fontColor:"white",beginAtZero:false,fontSize:16}}],xAxes:[{ticks:{fontColor:"white",fontSize:16}}]}}}`)

return message.channel.send(historicDeathEmbed);
Expand Down

0 comments on commit 1ed7b7a

Please sign in to comment.