From 10461a907aed4a5fddcd84565359ff06793c742f Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Fri, 27 Jul 2018 10:41:35 -0400 Subject: [PATCH] eShop Command --- README.md | 4 +- commands/search/eshop.js | 81 +++++++++++++++++++++++++++++++++++ commands/single/just-do-it.js | 17 ++++++++ package.json | 2 +- 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 commands/search/eshop.js create mode 100644 commands/single/just-do-it.js diff --git a/README.md b/README.md index 6ef88f5b..81cf17a4 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 (295) +## Commands (297) ### Utility: * **eval**: Executes JavaScript code. @@ -92,6 +92,7 @@ on the [home server](https://discord.gg/sbMe32W). * **hi**: Hello. * **isnt-joke**: Isn't joke... * **its-joke**: It's joke! +* **just-do-it**: Sends a link to the "Just Do It!" motivational speech. * **lenny**: Responds with the lenny face. * **nitro**: Sends the "This message can only be viewed by users with Discord Nitro." message. * **slow-clap**: _slow clap_ @@ -118,6 +119,7 @@ on the [home server](https://discord.gg/sbMe32W). * **danbooru**: Responds with an image from Danbooru, with optional query. * **deviantart**: Responds with an image from a DeviantArt section, with optional query. * **dictionary**: Defines a word. +* **eshop**: Searches the Nintendo eShop 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 new file mode 100644 index 00000000..1943cbd2 --- /dev/null +++ b/commands/search/eshop.js @@ -0,0 +1,81 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { list } = require('../../util/Util'); +const systems = ['3ds', 'switch', 'wii_u']; + +module.exports = class EshopCommand extends Command { + constructor(client) { + super(client, { + name: 'eshop', + aliases: ['nintendo-eshop'], + group: 'search', + memberName: 'eshop', + description: 'Searches the Nintendo eShop for your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'system', + prompt: `What system's store do you want to search? Either ${list(systems, 'or')}.`, + type: 'string', + oneOf: systems, + parse: system => system.toLowerCase() + }, + { + key: 'query', + prompt: 'What game would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { system, query }) { + try { + const id = await this.search(system, query); + if (!id) return msg.say('Could not find any results.'); + const data = await this.fetchGame(id); + const embed = new MessageEmbed() + .setColor(0xFF7D01) + .setAuthor( + `Nintendo eShop (${system})`, + 'https://i.imgur.com/9Ik6IlB.jpg', + 'https://www.nintendo.com/games/buy-digital' + ) + .setURL(data.microsite_ref ? data.microsite_ref.microsite.url : null) + .setThumbnail(data.front_box_art.image.image.url) + .setTitle(data.title) + .addField('❯ Price', data.eshop_price === '0.00' ? `$${data.eshop_price}` : 'Free!', true) + .addField('❯ Category', data.game_category_ref ? data.game_category_ref.title : '???', true) + .addField('❯ Release Date', data.release_date ? new Date(data.release_date).toDateString() : '???', true) + .addField('❯ Player Count', data.number_of_players || '???', true) + .addField('❯ DLC?', data.dlc === 'true' ? 'Yes' : 'No', true) + .addField('❯ Demo?', data.demo === 'true' ? 'Yes' : 'No', true) + .addField('❯ Developer', data.developer_ref ? data.developer_ref.title : '???', true) + .addField('❯ Publisher', data.publisher_ref ? data.publisher_ref.title : '???', true); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + async search(system, query) { + const { text } = await request + .get('https://www.nintendo.com/json/content/get/filter/game') + .query({ + system, + sort: 'relevance', + direction: 'asc', + search: query, + limit: 1, + availability: 'now' + }); + const body = JSON.parse(text); + return body.games.game ? body.games.game.id : null; + } + + async fetchGame(id) { + const { text } = await request.get(`https://www.nintendo.com/json/content/get/game/${id}`); + return JSON.parse(text).game; + } +}; diff --git a/commands/single/just-do-it.js b/commands/single/just-do-it.js new file mode 100644 index 00000000..0b09b46c --- /dev/null +++ b/commands/single/just-do-it.js @@ -0,0 +1,17 @@ +const Command = require('../../structures/Command'); + +module.exports = class JustDoItCommand extends Command { + constructor(client) { + super(client, { + name: 'just-do-it', + aliases: ['motivate'], + group: 'single', + memberName: 'just-do-it', + description: 'Sends a link to the "Just Do It!" motivational speech.' + }); + } + + run(msg) { + return msg.say('https://www.youtube.com/watch?v=ZXsQAXx_ao0'); + } +}; diff --git a/package.json b/package.json index ae4653bb..bb4af39f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "85.6.0", + "version": "85.7.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {