From 9d682455f555fd101d69433cc9b58b3814e6a68b Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 23 Apr 2015 15:11:45 +0000 Subject: [PATCH] food suggest --- modules/food/food.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/food/food.js b/modules/food/food.js index a8ff594..b719c90 100644 --- a/modules/food/food.js +++ b/modules/food/food.js @@ -31,6 +31,25 @@ var food = function(dbot) { } }; this.commands['~recipe'].regex = [/^recipe (.+)$/, 2]; + + this.listener = function(event) { + var match = event.message.match(new RegExp(dbot.config.name + ': what should i (have|eat|make)\\??( for dinner)?\\??', 'i')); + if(match) { + request.get('http://food2fork.com/api/search', { + 'qs': { + 'key': this.config.api_key, + }, + 'json': true + }, function(error, response, body) { + if(_.isObject(body) && _.has(body, 'recipes') && body.recipes.length > 0) { + var num = _.random(0, body.recipes.length - 1), + recipe = body.recipes[num]; + + event.reply('You should make ' + recipe.title + '. See: ' + recipe.source_url); + } + }.bind(this)); + } + }; }; exports.fetch = function(dbot) {