From 5575a8dfeec324b0a82d09c02627ed3f23ea6f26 Mon Sep 17 00:00:00 2001 From: Tilley Date: Fri, 23 Oct 2020 12:36:11 -0500 Subject: [PATCH 1/2] Added catfact fetcher --- scripts/cat_fact.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/cat_fact.js diff --git a/scripts/cat_fact.js b/scripts/cat_fact.js new file mode 100644 index 0000000..b81b2d3 --- /dev/null +++ b/scripts/cat_fact.js @@ -0,0 +1,27 @@ +// Description: +// Query https://catfact.ninja for cat facts +// +// Dependencies: +// None +// +// Configuration: +// None +// +// Commands: +// elvis catfact - returns a random cat fact +// +// Author: +// Xavier Tilley + +module.exports = function (robot) { + robot.respond(/catfact/i, function(msg) { + return msg.http(`https://catfact.ninja/fact?max_length=140`) + .get()(function(err, res, body) { + if (err) { + return msg.send(`The doggos stole the catfacts!`); + } else { + return msg.send(res.facts[0]); + } + }); + }); +} From fda52046eb217db2441464b6e9f7df434ca27bc7 Mon Sep 17 00:00:00 2001 From: Tilley Date: Fri, 23 Oct 2020 16:08:08 -0500 Subject: [PATCH 2/2] Fixed catfact, added catbreed --- scripts/cat_fact.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/cat_fact.js b/scripts/cat_fact.js index b81b2d3..b76f324 100644 --- a/scripts/cat_fact.js +++ b/scripts/cat_fact.js @@ -17,11 +17,30 @@ module.exports = function (robot) { robot.respond(/catfact/i, function(msg) { return msg.http(`https://catfact.ninja/fact?max_length=140`) .get()(function(err, res, body) { + let jsonBody = JSON.parse(body) if (err) { return msg.send(`The doggos stole the catfacts!`); } else { - return msg.send(res.facts[0]); + return msg.send(jsonBody.fact); } }); }); + + robot.respond(/catbreed/i, function(msg) { + return msg.http(`https://catfact.ninja/breeds?limit=1`) + .get()(function(err, res, body) { + const data = JSON.parse(body) + if (err) { + return msg.send(`Silly hooman! Only doggos have breeds!`); + } else { + let breed = data.breed + let country = data.country + let origin = data.origin + let coat = data.coat + let pattern = data.pattern + let reply = `Today's Cat Breed is ${breed}!\nThey are from ${country}, have a ${origin} origin and a ${coat} coat with ${pattern} patterns.` + return msg.send(reply) + } + }) + }) }