ESRB Command

This commit is contained in:
Dragon Fire
2021-03-13 14:29:20 -05:00
parent ffa179e7e3
commit abdb601aa1
8 changed files with 69 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

+68
View File
@@ -0,0 +1,68 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch');
const path = require('path');
const { shorten } = require('../../util/Util');
module.exports = class EsrbCommand extends Command {
constructor(client) {
super(client, {
name: 'esrb',
aliases: ['game-rating'],
group: 'search',
memberName: 'esrb',
description: 'Searches ESRB for your query.',
clientPermissions: ['EMBED_LINKS'],
credit: [
{
name: 'ESRB',
url: 'https://www.esrb.org/',
reason: 'API'
}
],
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 ratingFile = path.join(__dirname, '..', '..', 'assets', 'images', 'esrb', `${data.rating}.png`);
const embed = new MessageEmbed()
.attachFiles([{ attachment: ratingFile, name: 'rating.png' }])
.setColor(0x1C8CDE)
.setTitle(`${data.title} by ${data.company}`)
.setDescription(data.descriptors || 'No Descriptors')
.setAuthor('ESRB', 'https://i.imgur.com/ZyCxONf.jpg', 'https://www.esrb.org/')
.setThumbnail('attachment://rating.png')
.setURL(`https://www.esrb.org/ratings/${data.certificate}/`);
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
.post('https://www.esrb.org/wp-admin/admin-ajax.php')
.attach({
action: 'search_rating',
'args[searchKeyword]': query,
'args[searchType]': 'All',
'args[pg]': 1,
'args[platform][]': 'All Platforms',
'args[rating][]': 'E,E10+,T,M,AO',
'args[descriptor]': 'All Content'
});
const body = JSON.parse(text);
if (!body.games.length) return null;
return body.games[0];
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "132.3.0",
"version": "132.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {