From ce3aae28407a4ce3167cae3f713a392476f73f35 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 27 Mar 2020 12:11:37 -0400 Subject: [PATCH] Country Command --- README.md | 5 +++- commands/search/country.js | 54 ++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 commands/search/country.js diff --git a/README.md b/README.md index c67204ab..852ca240 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ don't grant that permission. ## Commands -Total: 380 +Total: 381 ### Utility: @@ -273,6 +273,7 @@ Total: 380 * **bulbapedia:** Searches Bulbapedia for your query. * **character:** Searches AniList for your query, getting character results. * **company:** Responds with the name and logo of a company. +* **country:** Responds with information on a country. * **danbooru:** Responds with an image from Danbooru, with optional query. (NSFW) * **define:** Defines a word. * **derpibooru:** Responds with an image from Derpibooru. @@ -959,6 +960,8 @@ here. * subreddit ([API](https://www.reddit.com/dev/api/)) - [Redeeming God](https://redeeminggod.com/) * approved ([Image](https://redeeminggod.com/courses/gospel-dictionary/lessons/gospel-dictionary-approved/)) +- [Rest Countries](https://restcountries.eu/) + * country (API) - [Right Stuf Anime](https://www.rightstufanime.com/) * right-stuf (API) - [Riot Games](https://www.riotgames.com/en) diff --git a/commands/search/country.js b/commands/search/country.js new file mode 100644 index 00000000..0f3fb234 --- /dev/null +++ b/commands/search/country.js @@ -0,0 +1,54 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { formatNumber } = require('../../util/Util'); + +module.exports = class CountryCommand extends Command { + constructor(client) { + super(client, { + name: 'country', + group: 'search', + memberName: 'country', + description: 'Responds with information on a country.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'Rest Countries', + url: 'https://restcountries.eu/', + reason: 'API' + } + ], + args: [ + { + key: 'query', + prompt: 'What country would you like to search for?', + type: 'string', + parse: query => encodeURIComponent(query) + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request.get(`https://restcountries.eu/rest/v2/name/${query}`); + const data = body[0]; + const embed = new MessageEmbed() + .setColor(0x00AE86) + .setTitle(data.name) + .setThumbnail(`https://www.countryflags.io/${data.alpha2Code}/flat/64.png`) + .addField('❯ Population', formatNumber(data.population)) + .addField('❯ Capital', data.capital, true) + .addField('❯ Currency', data.currencies[0].symbol, true) + .addField('❯ Location', data.subregion || data.region, true) + .addField('❯ Demonym', data.demonym, true) + .addField('❯ Native Name', data.nativeName, true) + .addField('❯ Area', `${formatNumber(data.area)}km`, true) + .addField('❯ Languages', data.languages.map(lang => lang.name).join('/')); + return msg.embed(embed); + } catch (err) { + if (err.status === 404) return msg.say('Could not find any results.'); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index 9e9d6e05..9d8e2077 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.17.1", + "version": "112.18.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {