mirror of
https://github.com/reality/dbot.git
synced 2024-11-27 14:29:29 +01:00
food
This commit is contained in:
parent
0384a45bf7
commit
4467e9fd5b
4
modules/food/config.json
Normal file
4
modules/food/config.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"outputPrefix": "\u000311food\u000f",
|
||||
"api_key": "http://food2fork.com/about/api"
|
||||
}
|
38
modules/food/food.js
Normal file
38
modules/food/food.js
Normal file
@ -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);
|
||||
};
|
8
modules/food/strings.js
Normal file
8
modules/food/strings.js
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"recipe": {
|
||||
"en": "{title} - {link}"
|
||||
},
|
||||
"no_recipe": {
|
||||
"en": "No recipes found."
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user