!7 set flag DynModule. // for transpilation cmodule2 GazelleMultiBot > DynGazelleBot { switchable int maxEvalResultLength = oneMegabyte_int(); switchable double evalTimeout = 60.0; transient new L bots; Map allPosts = syncTreeMap(); class Bot { S name; *() {} *(S *name) {} *(S *name, IVF1 *handlePost) {} swappable void handlePost(GazellePost post) {} GazelleBotCred cred() { ret GazelleBotCred(_user, _botToken, name); } } start { dm_useLocalMechListCopies(); // legacy conversion to sort allPosts setField_noCheck(allPosts := asSyncTreeMap(allPosts)); bots.add(new Bot("Math Bot", post -> gazelle_mathBot1_handlePost_2(_user, _botToken, post))); bots.add(new Bot("Code Safety Checker") { void handlePost(GazellePost post) { if (eqic(post.type, "JavaX Code")) gazelle_createPost(cred(), codeSafetyCheckResult(post.text), "Code Safety", refs := post.id); } }); bots.add(new Bot("Safe Code Runner") { void handlePost(GazellePost post) { if (eqic(post.type, "JavaX Code")) { S code = post.text; if (isCodeSafe(code)) { code = tok_addReturn(code); if (containsToken(code, "post")) { long ref = gazelle_firstPostRef(post.id); if (ref ! 0) code = "S post = " + quote(gazelle_text(ref)) + "\n" + code; } if (containsToken(code, "post2")) { long ref = gazelle_firstPostRef(gazelle_firstPostRef(post.id)); if (ref != 0) code = "S post2 = " + quote(gazelle_text(ref)) + "\n" + code; } printWithIndent("CODE> ", code); S out = shorten(maxEvalResultLength, runCode(code)); gazelle_createPost(cred(), out, "Code Result", refs := post.id); } } } }); bots.add(new Bot("Run Code On All Posts") { void handlePost(GazellePost post) { if (eqic(post.type, "Instruction") && match("Please run this code on all posts", post.text)) { long ref = gazelle_firstPostRef(post.id); if (ref == 0) ret; S code = gazelle_text(ref); if (!isCodeSafe(code)) ret; S code2 = "ret func(S post) { " + code + " };"; O function = dm_javaEval(code2); new LS lines; S out = shorten(maxEvalResultLength, runCode(code)); for (GazellePost post2 : cloneValues(allPosts)) { lines.add("Post " + post2.id + " (" + quote(shorten(20, post2.text)) + "): " + shorten(80, runFunc(() -> callF(function, post2.text)))); } gazelle_createPost(cred(), lines(lines), "Code Result", refs := post.id); } } }); } void handlePost(GazellePost post) { allPosts.put(post.id, post); change(); for (Bot bot : bots) pcall { bot.handlePost(post); } } // assumes code is safety-checked S runCode(S code) { ret runFunc(() -> str(dm_javaEval(code))); } S runFunc(IF0 f) { ret str(evalWithTimeoutOrException(evalTimeout, func { try { ret str(f!); } catch e { ret str(e); } })); } }