From b5d15b827a56688e8e6d90809cb5198321128d25 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 14 Mar 2020 11:22:52 -0400 Subject: [PATCH] Right Stuf Command --- README.md | 5 ++- commands/search/right-stuf.js | 80 +++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 commands/search/right-stuf.js diff --git a/README.md b/README.md index e2c6df51..fe0d5976 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ don't grant that permission. ## Commands -Total: 366 +Total: 367 ### Utility: @@ -296,6 +296,7 @@ Total: 366 * **pokedex:** Searches the Pokédex for a Pokémon. * **recipe:** Searches for recipes based on your query. * **reddit:** Responds with information on a Reddit user. +* **right-stuf:** Searches Right Stuf Anime for your query. * **rotten-tomatoes:** Searches Rotten Tomatoes for your query. * **rule:** Responds with a rule of the internet. * **safebooru:** Responds with an image from Safebooru, with optional query. @@ -931,6 +932,8 @@ here. * subreddit ([API](https://www.reddit.com/dev/api/)) - [Redeeming God](https://redeeminggod.com/) * approved ([Image](https://redeeminggod.com/courses/gospel-dictionary/lessons/gospel-dictionary-approved/)) +- [Right Stuf Anime](https://www.rightstufanime.com/) + * right-stuf (API) - [Riot Games](https://www.riotgames.com/en) * league-of-legends ([API](https://developer.riotgames.com/)) - [RoboHash](https://robohash.org/) diff --git a/commands/search/right-stuf.js b/commands/search/right-stuf.js new file mode 100644 index 00000000..4cf7ff50 --- /dev/null +++ b/commands/search/right-stuf.js @@ -0,0 +1,80 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const request = require('node-superfetch'); +const { stripIndents } = require('common-tags'); +const { shorten } = require('../../util/Util'); + +module.exports = class RightStufCommand extends Command { + constructor(client) { + super(client, { + name: 'right-stuf', + aliases: ['right-stuf-anime'], + group: 'search', + memberName: 'right-stuf', + description: 'Searches Right Stuf Anime for your query.', + clientPermissions: ['EMBED_LINKS'], + credit: [ + { + name: 'Right Stuf Anime', + url: 'https://www.rightstufanime.com/', + reason: 'API' + } + ], + args: [ + { + key: 'query', + prompt: 'What product would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { body } = await request + .get('https://www.rightstufanime.com/api/items') + .query({ + country: 'US', + currency: 'USD', + fieldset: 'search', + include: '', + language: 'en', + limit: 1, + pricelevel: 2, + q: query, + sort: 'relevance:asc', + custitem_rs_adult: msg.channel.nsfw ? true : false + }); + if (!body.items.length) return msg.say('Could not find any results.'); + const data = body.items[0]; + const embed = new MessageEmbed() + .setColor(0x00D474) + .setTitle(data.storedisplayname) + .setURL(`https://www.rightstufanime.com/${data.urlcomponent}`) + .setAuthor('Right Stuf', 'https://i.imgur.com/CTB8Imp.jpg', 'https://www.rightstufanime.com/') + .setDescription(shorten(data.storedescription)) + .setThumbnail(this.getImageURL(data)) + .addField('❯ Price', stripIndents` + Retail Price: ${data.pricelevel1_formatted} + Non-Member Price: ${data.pricelevel5_formatted} + Member Price: ${data.onlinecustomerprice_formatted} + `); + return msg.embed(embed); + } catch (err) { + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } + + getImageURL(item) { + let found = null; + let current = item.itemimages_detail + while (!found) { + if (current.primary) found = current.primary.url; + const key = Object.keys(current)[0]; + if (!key) break; + current = current[key]; + } + return found; + } +}; diff --git a/package.json b/package.json index b2bce141..45728afa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.6.2", + "version": "112.7.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {