mirror of
https://github.com/reality/dbot.git
synced 2025-02-17 14:01:04 +01:00
Map request functions to extMap. getQuoteCategory external API function [#361]
This commit is contained in:
parent
a628d12361
commit
1a1a08768a
@ -9,6 +9,7 @@ var api = function(dbot) {
|
|||||||
dbot.modules.web.app.get('/api/:module/:method', function(req, res) {
|
dbot.modules.web.app.get('/api/:module/:method', function(req, res) {
|
||||||
var module = req.params.module,
|
var module = req.params.module,
|
||||||
method = req.params.method,
|
method = req.params.method,
|
||||||
|
reqArgs = req.query,
|
||||||
body = { 'err': null, 'data': null };
|
body = { 'err': null, 'data': null };
|
||||||
|
|
||||||
if(!_.has(dbot.api, module)) {
|
if(!_.has(dbot.api, module)) {
|
||||||
@ -21,11 +22,16 @@ var api = function(dbot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!body.err) {
|
if(!body.err) {
|
||||||
var func = dbot.api[module][method];
|
var func = dbot.api[module][method],
|
||||||
var paramNames = func.extMap;
|
paramNames = func.extMap,
|
||||||
var args = [];
|
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');
|
var callbackIndex = paramNames.indexOf('callback');
|
||||||
if(callbackIndex != -1) {
|
if(callbackIndex != -1) {
|
||||||
@ -35,7 +41,7 @@ var api = function(dbot) {
|
|||||||
};
|
};
|
||||||
func.apply(null, args);
|
func.apply(null, args);
|
||||||
} else {
|
} else {
|
||||||
body.data = func.call(null, args);
|
body.data = func.apply(null, args);
|
||||||
res.json(body);
|
res.json(body);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,8 +83,21 @@ var quotes = function(dbot) {
|
|||||||
return false;
|
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) {
|
this.listener = function(event) {
|
||||||
if(event.action == 'PRIVMSG') {
|
if(event.action == 'PRIVMSG') {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"webHost": "localhost",
|
"webHost": "localhost",
|
||||||
"webPort": 8080,
|
"webPort": 9001,
|
||||||
"externalPath": false,
|
"externalPath": false,
|
||||||
"help": "https://github.com/reality/depressionbot/blob/master/modules/web/README.md"
|
"help": "https://github.com/reality/depressionbot/blob/master/modules/web/README.md"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user