mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-04 15:56:52 +02:00
ESRB Command is back!
This commit is contained in:
@@ -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 (324)
|
||||
## Commands (325)
|
||||
### Utility:
|
||||
|
||||
* **eval:** Executes JavaScript code.
|
||||
@@ -131,6 +131,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.
|
||||
* **giphy:** Searches Giphy for your query.
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const request = require('node-superfetch');
|
||||
const cheerio = require('cheerio');
|
||||
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.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What game would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const data = await this.search(query);
|
||||
if (!data) return msg.say('Could not find any results.');
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x231F20)
|
||||
.setAuthor('ESRB', 'https://i.imgur.com/dV2BamF.jpg', 'https://www.esrb.org/')
|
||||
.setTitle(data.title)
|
||||
.setDescription(data.summary || 'No summary available.')
|
||||
.setThumbnail(data.image)
|
||||
.addField('❯ Rating', ratings[data.rating], true)
|
||||
.addField('❯ Content Descriptors', data.descriptors.length ? data.descriptors.join('\n') : 'None', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async search(query) {
|
||||
const { text } = await request
|
||||
.get('https://www.esrb.org/ratings/search.aspx')
|
||||
.query({
|
||||
from: 'home',
|
||||
titleOrPublisher: query
|
||||
});
|
||||
const $ = cheerio.load(text);
|
||||
const result = $('table').first().children().eq(1).children();
|
||||
if (!result.length) return null;
|
||||
const image = result.find('td[data-title="Ratings"]').first().find('img').attr('src');
|
||||
return {
|
||||
title: result.find('td[data-title="Title"]').first().text().trim(),
|
||||
rating: image.match(/(EC|E|E10plus|T|M|AO)\.png/i)[1],
|
||||
descriptors: result.find('td[data-title="Content Descriptors"]').first().text().trim().split(', '),
|
||||
summary: result.find('td[style="border-width: 0 3px 0 0; padding: 10px;"]').first().text().trim() || null,
|
||||
image
|
||||
};
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "92.2.6",
|
||||
"version": "92.3.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user