From 4467e9fd5b544388837d4d9bf374c14452702744 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 23 Apr 2015 14:53:33 +0000 Subject: [PATCH] food --- modules/food/config.json | 4 ++++ modules/food/food.js | 38 ++++++++++++++++++++++++++++++++++++++ modules/food/strings.js | 8 ++++++++ 3 files changed, 50 insertions(+) create mode 100644 modules/food/config.json create mode 100644 modules/food/food.js create mode 100644 modules/food/strings.js diff --git a/modules/food/config.json b/modules/food/config.json new file mode 100644 index 0000000..eaa2c5a --- /dev/null +++ b/modules/food/config.json @@ -0,0 +1,4 @@ +{ + "outputPrefix": "\u000311food\u000f", + "api_key": "http://food2fork.com/about/api" +} diff --git a/modules/food/food.js b/modules/food/food.js new file mode 100644 index 0000000..2873544 --- /dev/null +++ b/modules/food/food.js @@ -0,0 +1,38 @@ +/** + * Module name: Food + * Description: recipe search + */ + +var _ = require('underscore')._, + request = require('request'); + +var food = function(dbot) { + this.commands = { + '~strain': function(event) { + request.get('http://food2fork.com/api/search', { + 'qs': { + 'key': this.config.api_key, + 'search': event.input[1] + }, + '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(dbot.t('recipe', { + 'title': recipe.title, + 'link': recipe.source_url + })); + } else { + event.reply(dbot.t('no_recipe')); + } + }.bind(this)); + } + }; + this.commands['~food'].regex = [/^food (.+)$/, 2]; +}; + +exports.fetch = function(dbot) { + return new food(dbot); +}; diff --git a/modules/food/strings.js b/modules/food/strings.js new file mode 100644 index 0000000..242a919 --- /dev/null +++ b/modules/food/strings.js @@ -0,0 +1,8 @@ +{ + "recipe": { + "en": "{title} - {link}" + }, + "no_recipe": { + "en": "No recipes found." + } +}