57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
const { translateText } = require('../plugins/translator');
|
|
|
|
/**
|
|
* Formatea la información de una receta para enviarla como mensaje.
|
|
* @param {Object} recipe - Objeto de receta obtenido de TheMealDB.
|
|
* @returns {String} - Mensaje formateado con la información de la receta.
|
|
*/
|
|
const formatRecipeInfo = async (recipe) => {
|
|
// Traducir instrucciones de la receta
|
|
const instructions = recipe.strInstructions
|
|
? await translateText(recipe.strInstructions, 'es')
|
|
: 'No hay instrucciones disponibles.';
|
|
|
|
return `
|
|
🍽️ *${recipe.strMeal}*
|
|
|
|
📄 *Categoría:* ${recipe.strCategory || 'No disponible'}
|
|
🌍 *Área:* ${recipe.strArea || 'No disponible'}
|
|
|
|
📝 *Instrucciones:*
|
|
${instructions}
|
|
|
|
🔗 *Fuente:*
|
|
${recipe.strSource || 'No disponible'}
|
|
|
|
🌐 *Video:*
|
|
${recipe.strYoutube || 'No disponible'}
|
|
|
|
🌐 *Imagen:*
|
|
${recipe.strMealThumb}
|
|
|
|
🛒 *Ingredientes:*
|
|
${getIngredientsList(recipe)}
|
|
`.trim();
|
|
};
|
|
|
|
/**
|
|
* Genera una lista de ingredientes y sus medidas.
|
|
* @param {Object} recipe - Objeto de receta obtenido de TheMealDB.
|
|
* @returns {String} - Lista formateada de ingredientes.
|
|
*/
|
|
const getIngredientsList = (recipe) => {
|
|
let ingredients = '';
|
|
for (let i = 1; i <= 20; i++) {
|
|
const ingredient = recipe[`strIngredient${i}`];
|
|
const measure = recipe[`strMeasure${i}`];
|
|
if (ingredient && ingredient.trim() !== '') {
|
|
ingredients += `- ${ingredient} - ${measure}\n`;
|
|
}
|
|
}
|
|
return ingredients || 'No hay ingredientes disponibles.';
|
|
};
|
|
|
|
module.exports = {
|
|
formatRecipeInfo
|
|
};
|