aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-01-14 21:05:59 -0500
committerHolden Rohrer <hr@hrhr.dev>2020-01-14 21:06:04 -0500
commitd146dbbab184a6e78f58bda9f997d68bac34b240 (patch)
tree3906186728f6f59a6f19b8d6e0317a2d5d0f57c1
parent89ddce7ab6de3efb089f352209bad65f25ab27c9 (diff)
moved exclusions to responder
-rw-r--r--examples/jarvis.js10
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index 0df6151..157808f 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -138,10 +138,8 @@ var search = new Space();
search.adhoc('jarvis'); // The search space is the word jarvis, so whenever that's caught, a relevant function can be called.
var read = new Search(search);
var expire = {};
-var limits = []; // an array of senders within the last 5 seconds to act as a 'rate limiter'
function detectPrompt(send, tiles, locs){ // tries to detect the prompt ('jarvis') and calls respond if found.
- if (limits.indexOf(send) >= 0) return;
for (let i=0; i<locs.length; i++){
let loc = locs[i];
if (read.has(loc)){
@@ -150,20 +148,22 @@ function detectPrompt(send, tiles, locs){ // tries to detect the prompt ('jarvis
read.del(loc);
}
let results = read.add(loc, tiles[loc]);
- if (results.length > 0) respond(results);
+ if (results.length > 0) respond(results, send);
expire[loc] = setTimeout(() => {read.del(loc); delete expire[loc];}, 30000);
}
limits.push(send);
- setTimeout(() => {limits.splice(limits.indexOf(send))}, 5*1000);
}
let response = new Space();
response.adhoc('yes, my liege');
-function respond(coord){
+var limits = []; // an array of senders within the last 5 seconds to act as a 'rate limiter'
+function respond(coord, send){
+ if (limits.indexOf(send) >= 0) return;
console.log('called at', coord);
callct += 1;
response.loc = coord;
writes.enqueue(response.towrite().concat(notifRefresh()));
read.update(response);
+ setTimeout(() => {limits.splice(limits.indexOf(send))}, 5*1000);
}