diff --git a/README.md b/README.md index 18ba2c77..7ba74424 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ in the appropriate channel's topic to use it. ## Commands -Total: 562 +Total: 563 ### Utility: @@ -449,6 +449,7 @@ Total: 562 * **anime-airing:** Responds with a list of the anime that air today. * **apod:** Responds with today's Astronomy Picture of the Day. * **calendar:** Responds with today's holidays. +* **covid-19:** Responds with stats for COVID-19. * **days-since:** Responds with how many days there have been since a certain date. * **days-until:** Responds with how many days there are until a certain date. * **doomsday-clock:** Responds with the current time of the Doomsday Clock. @@ -1065,6 +1066,8 @@ here. * dicebear (API) - [Digital Equipment Corporation](http://gordonbell.azurewebsites.net/digital/timeline/tmlnhome.htm) * dec-talk (Original DECTalk Software) +- [disease.sh](https://disease.sh/) + * covid-19 ([COVID-19 API](https://disease.sh/docs/#/)) - [Discord](https://discord.com/) * airhorn ([Airhorn Sounds](https://github.com/discord/airhornbot/tree/master/audio)) - [Discord Status Button](https://discord.c99.nl/) diff --git a/commands/events/covid-19.js b/commands/events/covid-19.js new file mode 100644 index 00000000..d205fbb4 --- /dev/null +++ b/commands/events/covid-19.js @@ -0,0 +1,63 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { MessageEmbed } = require('discord.js'); +const { formatNumber } = require('../../util/Util'); + +module.exports = class Covid19Command extends Command { + constructor(client) { + super(client, { + name: 'covid-19', + aliases: ['coronavirus', 'corona', 'covid'], + group: 'events', + memberName: 'covid-19', + description: 'Responds with stats for COVID-19.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'disease.sh', + url: 'https://disease.sh/', + reason: 'COVID-19 API', + reasonURL: 'https://disease.sh/docs/#/' + } + ], + args: [ + { + key: 'country', + prompt: 'What country do you want to get the stats for? Type `all` to get world stats.', + type: 'string', + default: 'all', + parse: country => encodeURIComponent(country) + } + ] + }); + } + + async run(msg, { country }) { + try { + const data = await this.fetchStats(country); + const embed = new MessageEmbed() + .setColor(0xA2D84E) + .setAuthor('Worldometers', 'https://i.imgur.com/IoaBMuK.jpg', 'https://www.worldometers.info/coronavirus/') + .setTitle(`Stats for ${data.country}`) + .setURL(`https://www.worldometers.info/coronavirus/country/${data.countryInfo.iso2}/`) + .setThumbnail(data.countryInfo.flag || null) + .addField('❯ Total Cases', `${formatNumber(data.cases)} (${formatNumber(data.casesToday)} Today)`, true) + .addField('❯ Total Deaths', `${formatNumber(data.deaths)} (${formatNumber(data.deathsToday)} Today)`, true) + .addField('❯ Total Recoveries', + `${formatNumber(data.recovered)} (${formatNumber(data.recoveredToday)} Today)`, true) + .addField('❯ Active Cases', formatNumber(data.active), true) + .addField('❯ Active Critical Cases', formatNumber(data.critical), true) + .addField('❯ Tests', formatNumber(data.tests), true); + return msg.embed(embed); + } catch (err) { + if (err.status === 404) return msg.say('Country not found or doesn\'t have any cases.'); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async fetchStats(country) { + const { body } = await request + .get(`https://disease.sh/v3/covid-19/${country === 'all' ? 'all' : `countries/${country}`}`); + return body; + } +}; diff --git a/package.json b/package.json index e57352c2..47f0157b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "121.1.0", + "version": "121.2.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {