From aa28611a501f2850270a6e800697adc4fda4d9ed Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 20 Mar 2018 22:39:47 +0000 Subject: [PATCH] Welcome back, recipe --- README.md | 3 ++- commands/search/recipe.js | 45 +++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 commands/search/recipe.js diff --git a/README.md b/README.md index 6755a219..518d5616 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Xiao is a Discord bot coded in JavaScript with 300 commands, she is one of the most feature-filled bots out there, and formerly served over 10,000 servers with a uniquely devoted fanbase. -## Commands (293) +## Commands (294) ### Utility: * **prefix**: Shows or sets the command prefix. @@ -147,6 +147,7 @@ served over 10,000 servers with a uniquely devoted fanbase. * **osu**: Responds with information on an Osu! user. * **periodic-table**: Finds an element on the periodic table. * **pokedex**: Searches the Pokédex for a Pokémon. +* **recipe**: Searches for recipes based on your query. * **rotten-tomatoes**: Searches Rotten Tomatoes for your query. * **safebooru**: Responds with an image from Safebooru, with optional query. * **spoopy-link**: Determines if a link is spoopy or not. diff --git a/commands/search/recipe.js b/commands/search/recipe.js new file mode 100644 index 00000000..774bbe42 --- /dev/null +++ b/commands/search/recipe.js @@ -0,0 +1,45 @@ +const { Command } = require('discord.js-commando'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class RecipeCommand extends Command { + constructor(client) { + super(client, { + name: 'recipe', + aliases: ['recipe-puppy'], + group: 'search', + memberName: 'recipe', + description: 'Searches for recipes based on your query.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What recipe would you like to search for?', + type: 'string' + } + ] + }); + } + + async run(msg, { query }) { + try { + const { text } = await snekfetch + .get('http://www.recipepuppy.com/api/') + .query({ q: query }); + const body = JSON.parse(text); + if (!body.results.length) return msg.say('Could not find any results.'); + const recipe = body.results[Math.floor(Math.random() * body.results.length)]; + const embed = new MessageEmbed() + .setAuthor('Recipe Puppy', 'https://i.imgur.com/lT94snh.png', 'http://www.recipepuppy.com/') + .setColor(0xC20000) + .setURL(recipe.href) + .setTitle(recipe.title) + .setDescription(`**Ingredients**: ${recipe.ingredients}`) + .setThumbnail(recipe.thumbnail); + return msg.embed(embed); + } catch (err) { + if (err.status === 500) return msg.say('Could not find any results.'); + return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); + } + } +}; diff --git a/package.json b/package.json index f5c35e5e..e264eefe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "69.4.0", + "version": "69.5.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {