// Replaces the n-word with "n-word" const Socket = require('../socket'); const Space = require('../space'); const comb = require('../utils/comb'); const Search = require('../tools/search'); const Queue = require('../tools/queue'); const maketiles = require('../utils/maketiles'); const vec = require('../utils/vec'); const id = require('../utils/ident'); var main = new Socket(); id.call(main); var search = new Search(); var ids = []; var idcall = []; var writeids = {}; var wq = new Queue(1000, 200, (w,max)=>{ let globid = main.write(w); let id; while (id = ids.shift()) { if (id > max) break; if (writeids[globid]) writeids[globid].push(idcall.shift()); else writeids[globid] = [idcall.shift()]; } }); main.on('write', (acc)=>{ for (let id in writeids) if (acc.indexOf(parseInt(id)) > -1){ for (let it of writeids[id]) it(); delete writeids[id]; } }); main.on('init',(send)=>{ main.sender = send; wq.enable(); }); main.on('close',()=>{ wq.disable(); }); var expire = {}; main.on('tileUpdate', (send, source, tiles)=>{ if (send === main.sender) return; let tiledata = maketiles(tiles); for (let loc of tiledata.locs) { let spc = tiledata.tilespaces[loc]; if (search.has(loc)){ clearTimeout(expire[loc]); search.del(loc); } search.add(loc, spc, send); expire[loc] = setTimeout(() => {search.del(loc); delete expire[loc];}, 300*1000); } }); makeclean('','BL[A\u0410][C\u0421]K N[I\u0406]GG[E\u0415]RS'); makeclean('I am racist', '[Nn]+ *[1Ii]+ *[Gg]+ *[Gg]+ *([3Ee]+ *[Rr]+|[4@Aa]+)'); makeclean('I am ableist', '[Rr]+ *[3Ee]+ *[Tt]+ *[4@Aa]+ *[Rr]+ *[Dd]+'); let dolecture = false; let lecture = {}; function makeclean(resp, reg){ let response = new Space().adhoc(resp); let regex = new RegExp(reg,'g'); function clean(coord, send, space){ let out = new Space().adhoc(space.print().replace(regex, match=>' '.repeat(match.length))); out.loc = space.loc; if (dolecture && !lecture[send]){ response.loc = coord; out.comb(response, comb.flip(comb.add)); lecture[send] = true; setTimeout(() => {delete lecture[send];}, 10000); } out.comb(space, comb.sub); ids.push(wq.enqueue(out.towrite())); idcall.push(() => {search.update(out);}); } search.match([reg], clean); }