diff --git a/assets/images/esrb/AO.png b/assets/images/esrb/AO.png new file mode 100644 index 00000000..174a753e Binary files /dev/null and b/assets/images/esrb/AO.png differ diff --git a/assets/images/esrb/E.png b/assets/images/esrb/E.png new file mode 100644 index 00000000..c541843a Binary files /dev/null and b/assets/images/esrb/E.png differ diff --git a/assets/images/esrb/E10plus.png b/assets/images/esrb/E10plus.png new file mode 100644 index 00000000..aa1dbeb5 Binary files /dev/null and b/assets/images/esrb/E10plus.png differ diff --git a/assets/images/esrb/M.png b/assets/images/esrb/M.png new file mode 100644 index 00000000..71ee8a6b Binary files /dev/null and b/assets/images/esrb/M.png differ diff --git a/assets/images/esrb/RP.png b/assets/images/esrb/RP.png new file mode 100644 index 00000000..a8063f97 Binary files /dev/null and b/assets/images/esrb/RP.png differ diff --git a/assets/images/esrb/T.png b/assets/images/esrb/T.png new file mode 100644 index 00000000..74e54bfa Binary files /dev/null and b/assets/images/esrb/T.png differ diff --git a/commands/search/esrb.js b/commands/search/esrb.js new file mode 100644 index 00000000..c18cbfa7 --- /dev/null +++ b/commands/search/esrb.js @@ -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]; + } +}; diff --git a/package.json b/package.json index 855adaa4..d78f87f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "132.3.0", + "version": "132.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {