diff --git a/README.md b/README.md index 996748f1..43c2919c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Xiao is a Discord bot coded in JavaScript with The bot is no longer available for invite. You can self-host the bot, or use her on the [home server](https://discord.gg/sbMe32W). -## Commands (298) +## Commands (299) ### Utility: * **eval**: Executes JavaScript code. @@ -121,6 +121,7 @@ on the [home server](https://discord.gg/sbMe32W). * **dictionary**: Defines a word. * **discord-js-docs**: Searches the Discord.js docs for your query. * **eshop**: Searches the Nintendo eShop for your query. +* **esrb**: Searches ESRB for your query. * **flickr**: Searches Flickr for your query. * **forecast**: Responds with the seven-day forecast for a specific location. * **gelbooru**: Responds with an image from Gelbooru, with optional query. diff --git a/commands/search/eshop.js b/commands/search/eshop.js index ff545c76..934bdfaa 100644 --- a/commands/search/eshop.js +++ b/commands/search/eshop.js @@ -39,7 +39,7 @@ module.exports = class EshopCommand extends Command { .setColor(0xFF7D01) .setAuthor( `Nintendo eShop (${system})`, - 'https://i.imgur.com/9Ik6IlB.jpg', + 'https://i.imgur.com/lMh73lz.png', 'https://www.nintendo.com/games/buy-digital' ) .setURL(data.microsite_ref ? data.microsite_ref.microsite.url : null) diff --git a/commands/search/esrb.js b/commands/search/esrb.js new file mode 100644 index 00000000..5c0f3a27 --- /dev/null +++ b/commands/search/esrb.js @@ -0,0 +1,66 @@ +const Command = require('../../structures/Command'); +const request = require('node-superfetch'); +const { MessageEmbed } = require('discord.js'); +const ratings = { + EC: 'Early Childhood', + E: 'Everyone', + E10plus: 'Everyone 10+', + T: 'Teen', + M: 'Mature', + AO: 'Adults Only' +}; + +module.exports = class ESRBCommand extends Command { + constructor(client) { + super(client, { + name: 'esrb', + aliases: ['esrb-rating'], + group: 'search', + memberName: 'esrb', + description: 'Searches ESRB for your query.', + args: [ + { + key: 'query', + prompt: 'What game would you like to get the rating of?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const data = await this.fetchRating(query); + const embed = new MessageEmbed() + .setColor(0x231F20) + .setAuthor('ESRB', 'https://i.imgur.com/6KAG7gD.png', 'http://www.esrb.org/') + .setTitle(data.title) + .setURL(data.url) + .setThumbnail(data.ratingImage) + .addField('❯ Rating', ratings(data.rating)); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async fetchRating(query) { + const { text, url } = await request + .get('http://www.esrb.org/ratings/search.aspx') + .query({ + from: 'home', + titleOrPublisher: query + }); + const title = text.match(/(.+)<\/strong>/); + if (!title) return null; + const rating = text.match( + /https:\/\/esrbstorage.blob.core.windows.net\/esrbcontent\/images\/(EC|E|E10plus|T|M|AO).png/ + ); + return { + title: title[1].trim(), + rating: rating[1], + ratingImage: rating[0], + url + }; + } +}; diff --git a/package.json b/package.json index d0a1619c..4c7d054e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "85.8.0", + "version": "85.9.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {