aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-07-16 17:13:47 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-07-16 17:13:47 -0400
commit327ed17b1d66f89a2165d626775698edbc2c0e9d (patch)
treede1b1a18517f112112b61dc5b7dfdb1e5d256607 /examples
parent246a4582eda90825a6beaaa963c8d3772c6cf8dc (diff)
added nword protector using an add'l id func to Queue
This should be added to sched.Queue so (even if it requires a somewhat convoluted workflow), any write may be tracked.
Diffstat (limited to 'examples')
-rw-r--r--examples/nword.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/nword.js b/examples/nword.js
new file mode 100644
index 0000000..fe09a0b
--- /dev/null
+++ b/examples/nword.js
@@ -0,0 +1,50 @@
+// Replaces the n-word with "n-word"
+const Socket = require('../socket');
+const Space = require('../space');
+const Search = require('../tools/search');
+const Queue = require('../tools/queue');
+const maketiles = require('../utils/maketiles');
+const vec = require('../utils/vec');
+const wwrap = require('../utils/writewrap');
+
+var main = new Socket();
+wwrap.call(main);
+var search = new Search();
+var ids = [];
+var idcall = [];
+var wq = new Queue(1000, 200, (w,max) =>{
+ let globid = main.write(w);
+ let id;
+ while (id = ids.shift()) {
+ if (id > max) break;
+ main.on(globid, idcall.shift());
+ }
+});
+
+main.on('open',()=>{wq.enable(); console.log('here');});
+
+var expire = {};
+main.on('tileUpdate', (send, source, tiles)=>{
+ let tiledata = maketiles(tiles);
+ for (loc of tiledata.locs) {
+ let spc = tiledata.tilespaces[loc];
+ if (search.has(loc)){
+ clearTimeout(expire[loc]);
+ search.del(loc);
+ }
+ search.add(loc, spc);
+ expire[loc] = setTimeout(() => {search.del(loc); delete expire[loc];},
+ 30000);
+ }
+});
+
+search.match(new Space().adhoc('nigger'), clean);
+search.match(new Space().adhoc('Nigger'), clean);
+search.match(new Space().adhoc('NIGGER'), clean);
+
+let response = new Space().adhoc(' I am a racist ');
+function clean(coord, send){
+ response.loc = vec.add(coord,[0,-6]);
+ ids.push(wq.enqueue(response.towrite()));
+ idcall.push(() => {search.update(response);});
+}