Pass whom when creating the say function;
This commit is contained in:
parent
e5840d521c
commit
4c9a1e381e
22
index.js
22
index.js
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user