3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Map request functions to extMap. getQuoteCategory external API function [#361]

This commit is contained in:
reality 2013-04-14 18:14:59 +00:00
parent a628d12361
commit 1a1a08768a
3 changed files with 25 additions and 6 deletions

View File

@ -9,6 +9,7 @@ var api = function(dbot) {
dbot.modules.web.app.get('/api/:module/:method', function(req, res) {
var module = req.params.module,
method = req.params.method,
reqArgs = req.query,
body = { 'err': null, 'data': null };
if(!_.has(dbot.api, module)) {
@ -21,11 +22,16 @@ var api = function(dbot) {
}
if(!body.err) {
var func = dbot.api[module][method];
var paramNames = func.extMap;
var args = [];
var func = dbot.api[module][method],
paramNames = func.extMap,
args = [];
// TODO: Use request params to map to extMap args
_.each(reqArgs, function(arg, name) {
var callbackIndex = paramNames.indexOf(name);
if(callbackIndex != -1) {
args[callbackIndex] = decodeURIComponent(arg);
}
});
var callbackIndex = paramNames.indexOf('callback');
if(callbackIndex != -1) {
@ -35,7 +41,7 @@ var api = function(dbot) {
};
func.apply(null, args);
} else {
body.data = func.call(null, args);
body.data = func.apply(null, args);
res.json(body);
}
} else {

View File

@ -83,9 +83,22 @@ var quotes = function(dbot) {
return false;
}
}
},
'getQuoteCategory': function(name) {
console.log(name);
var key = name.trim().toLowerCase();
if(_.has(this.quotes, key)) {
return this.quotes[key];
} else {
return false;
}
}
};
this.api['getQuoteCategory'].external = true;
this.api['getQuoteCategory'].extMap = [ 'name' ];
this.listener = function(event) {
if(event.action == 'PRIVMSG') {
if(event.user == 'reality') {

View File

@ -1,6 +1,6 @@
{
"webHost": "localhost",
"webPort": 8080,
"webPort": 9001,
"externalPath": false,
"help": "https://github.com/reality/depressionbot/blob/master/modules/web/README.md"
}