From 0577dadf000d0960e57a7c2f5339edc0e6d2cf21 Mon Sep 17 00:00:00 2001 From: John Facey Date: Tue, 9 Aug 2022 00:29:54 -0500 Subject: [PATCH] pushing food cmd --- commands/food.js | 25 +++++++++++++++++++++++++ commands/help.js | 1 + libFlayer.js | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 commands/food.js diff --git a/commands/food.js b/commands/food.js new file mode 100644 index 0000000..962a070 --- /dev/null +++ b/commands/food.js @@ -0,0 +1,25 @@ +var libFlayer = require("../libFlayer.js"); + +module.exports = { + name: 'food', + description: 'Food', + async execute(message, args) { + try { + + var resultArray = await libFlayer.getFood(); + + message.reply(`**Retrieving**: + [${resultArray.strMeal} - ${resultArray.strCategory}] + + ${resultArray.strInstructions} + + ${resultArray.strSource} + + ${resultArray.strMealThumb} + + `); + } catch (err) { + message.reply(err.toString()); + } + } +}; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 88b77b5..429fc23 100644 --- a/commands/help.js +++ b/commands/help.js @@ -23,6 +23,7 @@ module.exports = { **!npm** - Gets NPM info from repository: *!npm axios* **!alert** - Gets weather alerts for an area: *!alert TX* **!calc** - Do math: *!calc 2 + 2* + **!food** - Selects a random recipe: *!food* ` ); } diff --git a/libFlayer.js b/libFlayer.js index bb7d097..71321d3 100644 --- a/libFlayer.js +++ b/libFlayer.js @@ -231,6 +231,47 @@ exports.weatherAlert = async function (state) { return answerData; } +exports.getFood = async function () { + + var answerURL = `https://www.themealdb.com/api/json/v1/1/random.php`; + console.log(answerURL); + answerData = { + text: `No answer found try using a simpler search term`, + source: `` + } + await axios.get(answerURL) + .then(response => { + //console.log(response.data.RelatedTopics[0].Text); + //console.log(response.data.RelatedTopics[0].FirstURL); + + // if (response.data.meals.length != 0) { + + answerData = { + strMeal: `No Data`, + strSource: `-`, + strInstructions: `-`, + strMealThumb: `-`, + strCategory: `-` + } + + answerData = { + strMeal: `${unescape(response.data.meals[0].strMeal)}`, + strSource: `${unescape(response.data.meals[0].strSource)}`, + strInstructions: `${unescape(response.data.meals[0].strInstructions)}`, + strMealThumb: `${unescape(response.data.meals[0].strMealThumb)}`, + strCategory: `${unescape(response.data.meals[0].strCategory)}` + } + // } else { + + //} + return answerData; + }) + .catch(error => { + console.log(error); + }); + return answerData; +} + exports.search = async function (question) { var answerURL = `https://api.duckduckgo.com/?q=${question}&format=json&pretty=1`; @@ -241,8 +282,8 @@ exports.search = async function (question) { } await axios.get(answerURL) .then(response => { - console.log(response.data.RelatedTopics[0].Text); - console.log(response.data.RelatedTopics[0].FirstURL); + //console.log(response.data.RelatedTopics[0].Text); + //console.log(response.data.RelatedTopics[0].FirstURL); if (response.data.Abstract != "") { answerData = {