From 4c9a1e381e7fd6e41bb0fdc1fb542364a02590d6 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Sat, 16 Jul 2016 19:30:43 +0200 Subject: [PATCH] Pass whom when creating the say function; --- index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 174250b..ae532c5 100644 --- a/index.js +++ b/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);