aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-07-16 22:10:33 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-07-16 22:11:44 -0400
commit6c2e17ac7f2db4d128517ad1854c72e0fdd354ef (patch)
treeeffad6f890eb08c7407bdba70979139c3f12ae69
parentdf8c98f96deb3f0b817e1ab3270fe74b2cca1450 (diff)
used id and lecture delay
These should reduce the bot's total response count, improving efficiency with spammers. The lecture delay includes a space-replacement and differ to allow "b a d w o r d" to still only require 7 changes. Tile deletion delay upped to 5 minutes.
-rw-r--r--examples/nword.js42
1 files changed, 33 insertions, 9 deletions
diff --git a/examples/nword.js b/examples/nword.js
index 9367362..8fe8f5e 100644
--- a/examples/nword.js
+++ b/examples/nword.js
@@ -1,14 +1,18 @@
// 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 wwrap = require('../utils/writewrap');
+const id = require('../utils/ident');
var main = new Socket();
wwrap.call(main);
+id.call(main);
+
var search = new Search();
var ids = [];
var idcall = [];
@@ -17,14 +21,19 @@ var wq = new Queue(1000, 200, (w,max) =>{
let id;
while (id = ids.shift()) {
if (id > max) break;
- main.on(globid, idcall.shift());
+ let run = idcall.shift();
+ main.on(globid, ()=>{run();main.off(this)});
}
});
-main.on('open',()=>wq.enable());
+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];
@@ -34,15 +43,30 @@ main.on('tileUpdate', (send, source, tiles)=>{
}
search.add(loc, spc);
expire[loc] = setTimeout(() => {search.del(loc); delete expire[loc];},
- 30000);
+ 300*1000);
}
});
-search.match(['[Nn] *[Ii] *[Gg] *[Gg] *[Ee] *[Rr]'], clean);
+makeclean('I am racist', '[Nn] *[Ii] *[Gg] *[Gg] *([Ee] *[Rr]|[Aa])');
+makeclean('I am ableist', '[Rr] *[Ee] *[Tt] *[Aa] *[Rr] *[Dd]');
-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);});
+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;
+ if (!lecture[send]){
+ response.loc = coord;
+ out = response;
+ lecture[send] = true;
+ setTimeout(() => {delete lecture[send];}, 1000);
+ }else{
+ out = new Space().adhoc(space.print().replace(regex,
+ match=>' '.repeat(match.length))).comb(space, comb.sub);
+ }
+ ids.push(wq.enqueue(out.towrite()));
+ idcall.push(() => {search.update(response);});
+ }
+ search.match([reg], clean);
}