ESRB Command

This commit is contained in:
Dragon Fire
2018-07-27 14:35:05 -04:00
parent f6a1b8692e
commit 6960dcb148
4 changed files with 70 additions and 3 deletions
+2 -1
View File
@@ -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.
+1 -1
View File
@@ -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)
+66
View File
@@ -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 name="title">(.+)<\/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
};
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "85.8.0",
"version": "85.9.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {