// 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] = []; } }); main.on('write', (acc)=>{ for (let id in writeids) if (acc.indexOf(id) > -1){ for (let it of writeids[id]) writeids[id](); delete writeids[id]; } }); main.on('init',(send)=>{ main.sender = send; wq.enable(); }); 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); expire[loc] = setTimeout(() => {search.del(loc); delete expire[loc];}, 300*1000); } }); makeclean('I am racist', '[Nn] *[1Ii] *[Gg] *[Gg] *([3Ee] *[Rr]|[4@Aa])'); makeclean('I am ableist', '[Rr] *[3Ee] *[Tt] *[4@Aa] *[Rr] *[Dd]'); 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))); if (!lecture[send]){ response.loc = coord; out.comb(response, comb.add); lecture[send] = true; setTimeout(() => {delete lecture[send];}, 1000); } out.comb(space, comb.sub); ids.push(wq.enqueue(out.towrite())); idcall.push(() => {search.update(response);}); } search.match([reg], clean); }