Covid command

Coded by: Rhaze
 avatar
unknown
javascript
3 years ago
1.9 kB
10
Indexable
if(input.startsWith("/covid")){
   const https = require('https');
    const got = require('got');
    got.get('https://disease.sh/v3/covid-19/countries/' + location)
    .then(res => {
        var resp = res.body;
        var response = JSON.parse(resp);
        cont = response.country,
        cases = response.cases,
        death = response.deaths,
        recovered = response.recovered,
        tests = response.tests
        population = response.population,
        continent = response.continent,
        todayD = response.todayDeaths,
        todayR = response.todayRecovered,
        todayC = response.todayCases,
        critical = response.critical,
        active = response.active,
        flag = response.countryInfo.flag;
        var file = fs.createWriteStream("flag.png");
        var targetUrl = flag;
        var gifRequest = http.get(targetUrl, function (gifResponse) 
            gifResponse.pipe(file);
            file.on('finish', function () {
                console.log('finished downloading flag')
                var message = {
                                 body: "COVID CASES UPDATE\nAs of: " + time + "\nCountry: " + cont + "\nContinent: " + continent + "\nPopulation: "+ population + "\nTotal Cases: " + cases + "\nTotal Recovered:" + recovered + "\nTotal Death: " + death + "\nActive: " + active + "\nCritical: " + critical + "\nToday's Cases: " + todayC + "\nToday's Recovered: " + todayR + "\nToday's Death: " + todayD ,
                              attachment: fs.createReadStream(__dirname + '/flag.png')
                           }
            });
        });
    })
    .catch(err => {
        console.log("⚠️Error: " + err.message)
                    console.log(err.message)
                     api.sendMessage("❎"+location+" country not found or doesn't have any cases", event.threadID, event.messageID);
    });
}
Editor is loading...