Check the current corona cases, you can check cases based on country or global
/* Required Modules */
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios')
/* Check if message starts with "!corona" */
if (context.params.event.content.startsWith('!corona')) {
/* Split the message content with space */
const args = context.params.event.content.split(" ")
/* Remove first element of the array which will be command name "!corona" */
args.splice(0,1)
/* Global link */
let link = "https://disease.sh/v3/covid-19/all"
/* Change the link if the country is provided */
if(args[0]) link = `https://disease.sh/v3/covid-19/countries/${args.join(" ")}`
/* Send Request to the API */
let data = await axios(link).catch(err => {})
/* if something goes wrong then return the process with error message in console */
if(!data) return console.log(`Unable to get the request from API`);
else data = data.data
/* Now send the message with all the data you gathered */
await lib.discord.channels['@0.1.1'].messages.create({
"channel_id": `${context.params.event.channel_id}`,
"content": "",
"embed": {
"type": "rich",
"title": `${args[0] ? data.country.toUpperCase() : "Global Cases"}`,
"description": "Sometimes cases number may differ from small amount.",
"color": 0x00FFFF,
"fields": [
{
"name": "Total Cases",
"value": data.cases.toLocaleString(),
"inline": true
},
{
"name": "Total Deaths",
"value": data.deaths.toLocaleString(),
"inline": true
},
{
"name": "Total Recovered",
"value": data.recovered.toLocaleString(),
"inline": true
},
{
"name": "Today's Cases",
"value": data.todayCases.toLocaleString(),
"inline": true
},
{
"name": "Today's Deaths",
"value": data.todayDeaths.toLocaleString(),
"inline": true
},
{
"name": "Active Cases",
"value": data.active.toLocaleString(),
"inline": true
}
],
thumbnail: { url: args[0] ? data.countryInfo.flag : "https://img.pngio.com/global-icon-png-200227-free-icons-library-global-icon-png-1000_1000.jpg" }
}
});
}