From 527c57a8d8e357107621f9c2203737c4b4b73358 Mon Sep 17 00:00:00 2001 From: Vitor Alano de Ataides Date: Wed, 26 Apr 2017 08:46:31 -0300 Subject: [PATCH] Adding joke feature. --- care.js | 26 ++++++++++++++++++++++++++ config.js | 2 ++ package.json | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/care.js b/care.js index 2605b96..db0de21 100755 --- a/care.js +++ b/care.js @@ -8,6 +8,7 @@ var contrib = require('blessed-contrib'); var chalk = require('chalk'); var parrotSay = require('parrotsay-api'); var weather = require('weather-js'); +var request = require('request'); var screen = blessed.screen( {fullUnicode: true, // emoji or bust @@ -46,6 +47,7 @@ function tick() { doTheWeather(); doTheTweets(); doTheCodes(); + doTheJokes(); } function doTheWeather() { @@ -121,6 +123,30 @@ function doTheCodes() { }); } +function doTheJokes() { + + request.get({url: 'http://tambal.azurewebsites.net/joke/random', json: true}, function (err, res, body) { + + if(err) { + + parrotSay('Knock, Knock! Ops ERROR!').then(function(text) { + parrotBox.content = text; + screen.render(); + }); + + } else { + + parrotSay(body.joke).then(function(text) { + parrotBox.content = text; + screen.render(); + }); + + } + + }); + +} + function makeBox(label) { return { label: label, diff --git a/config.js b/config.js index 9f216e0..6982c00 100644 --- a/config.js +++ b/config.js @@ -16,6 +16,8 @@ var config = { // Set to false if you're an imperial savage. <3 celsius: (process.env.TTC_CELSIUS || 'true') === 'true', + + joke: (process.env.TTC_JOKE === 'true'), updateInterval: parseFloat(process.env.TTC_UPDATE_INTERVAL) || 20, diff --git a/package.json b/package.json index 691a1dc..4138693 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "blessed": "^0.1.81", "blessed-contrib": "^4.7.5", "chalk": "^1.1.3", - "parrotsay-api": "^0.1.1", + "request": "^2.81.0", "scraperjs": "^1.2.0", "twit": "^2.2.5", "weather-js": "^2.0.0"