Files
xiao/commands/search/recipe.js
T
Daniel Odendahl Jr 1c9ac56831 Change arg assignment
2017-09-16 01:44:44 +00:00

43 lines
1.2 KiB
JavaScript

const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
module.exports = class RecipeCommand extends Command {
constructor(client) {
super(client, {
name: 'recipe',
group: 'search',
memberName: 'recipe',
description: 'Searches for recipes that include 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()
.setColor(0xC20000)
.setURL(recipe.href)
.setTitle(recipe.title)
.setDescription(`**Ingredients:** ${recipe.ingredients}`)
.setThumbnail(recipe.thumbnail);
return msg.embed(embed);
} catch (err) {
return msg.say('Could not find any results.');
}
}
};