Pass whom when creating the say function;

This commit is contained in:
Benjamin Bouvier 2016-07-16 19:30:43 +02:00
parent e5840d521c
commit 4c9a1e381e

View File

@ -143,16 +143,18 @@ var handlers = {
};
function say(msgs) {
if (msgs) {
var whom = hookToChannel[body.object_kind] || [];
if (msgs instanceof Array) {
for (var i = 0; i < msgs.length; i++)
client.say(whom, msgs[i]);
} else {
client.say(whom, msgs);
function makeSay(body) {
var whom = hookToChannel[body.object_kind] || [];
return function say(msgs) {
if (msgs) {
if (msgs instanceof Array) {
for (var i = 0; i < msgs.length; i++)
client.say(whom, msgs[i]);
} else {
client.say(whom, msgs);
}
}
}
};
}
app.post('/', function(req, res) {
@ -160,7 +162,7 @@ app.post('/', function(req, res) {
var msgs = null;
if (body.object_kind && handlers[body.object_kind])
handlers[body.object_kind](body, say);
handlers[body.object_kind](body, makeSay(body));
else
console.log("Unexpected object_kind:", body.object_kind);