!7 set flag DynModule. // for transpilation cmodule GazelleMultiBot > DynGazelleBot { switchable int maxEvalResultLength = oneMegabyte_int(); switchable double evalTimeout = 60.0; transient new L bots; Map allPosts = syncMap(); 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(); 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)) { 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)) { S code = post.text; if (!isCodeSafe(code)) ret; S code2 = "func(S post) { " + code + " }"; O function = dm_javaEvalMedium(code2); new LS lines; S out = shorten(maxEvalResultLength, runCode(code)); for (GazellePost post : cloneValues(allPosts)) { lines.add(post.id + ": " + shorten(80, runFunc(() -> callF(function, post.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_javaEvalMedium(code))); } S runFunc(IF0 f) { ret str(evalWithTimeoutOrException(evalTimeout, func { try { ret str(f!); } catch e { ret str(e); } })); } }