!7 sS regexpActivator = "."; // always !include once #1017764 // VirtualMechLists sS mechLibID = #1400124; static O onOutput; // VF1 static bool authorized; sS msgGlobalID; static L bots; abstract sclass AbstractThinkBot { transient VF1 postMessage; transient new L recentHistory; abstract void thinkAbout(S input); void postMessage(S s) { callF(postMessage, s); } JComponent visualize() { ret jpanel(); } } p { mech_useLibrary(mechLibID); L> classes = botClasses(); print("Have think classes: " + classNames(classes)); makeBots(); bot(); } static L> botClasses() { ret myNonAbstractClassesImplementing(AbstractThinkBot); } svoid makeBots() { bots = map nuWithoutArguments(botClasses()); } sbool telegram_amIAuthorized() { ret authorized; } svoid setMsgGlobalID(S globalID) { msgGlobalID = globalID; } sS answer(S s) { temp tempSetThreadLocal(telegram_msg_tl(), litorderedmap(globalID := msgGlobalID)); msgGlobalID = null; final new L output; for (AbstractThinkBot bot : bots) pcall { bot.postMessage = voidfunc(S s) { print(">> " + s); pcallF(onOutput, s); output.add(s); }; bot.thinkAbout(s); } ret rtrim(lines(output)); } svoid setDebug(bool b) { for (O bot : unnull(bots)) setOpt(bot, debug := b); } sclass TelegramThinkBot > AbstractThinkBot { void thinkAbout(S s) { s = trim(s); final new Matches m; S procedure = nlLookup(mechMap("Telegram Procedures"), s, m); if (procedure != null) { procedure = expandDollarRefsToMatches(procedure, m, true); print(">> " + procedure); postMessage(strOrNull(javaEvalOrInterpret(procedure))); } print("s=" + s); S language = 'english; if (swic_trim(s, "!german ", m)) { language = 'german; s = m.rest(); print("s=" + s); } ai_setLanguage(language); if (swic_trim(s, "!say ", m)) postMessage(m.rest()); if (eq(s, "!gac")) postMessage(random_gac36k()); if (swic_trim(s, "!parse ", m)) postMessage(ai_renderCulledParseTree(ai_parseToTreeWithGuessing(m.rest()))); if (swic_trim(s, "!simplify ", m)) postMessage(lines(ai_parseTree_simplifiedTexts(ai_parseToTreeWithGuessing(m.rest())))); if (telegram_amIAuthorized()) { if (eq(s, "!fresh")) { dm_refreshTranspiler(); postMessage("OK"); } if (telegram_amIFullyAuthorized()) { if (swic_trim(s, "!eval ", m)) postMessage(pcallOrExceptionText(func { strOrNull(javaEvalOrInterpret(m.rest())) })); if (swic_trim(s, "!real-eval ", m)) postMessage(pcallOrExceptionText(func { strOrNull(javaEval(m.rest())) })); } if (swic_trim(s, "!rule ", m)) { S rule = m.rest(); if (!telegram_authorizedToStoreRule(rule)) ret; LS rules = trimAll(ai_unparsedTalkRules()); if (!contains(rules, rule)) { // TODO: ignore global IDs rule = nlLogic_addGlobalID(rule); appendToMechList_noUniq("NL Logic Examples", "\n" + rule); postMessage("Rule saved as " + leadingSquareBracketOptions_id(rule) + ". Have " + n2(l(rules)+1, "rule") + "."); } } if (swic_trim(s, "!fact ", m)) { S fact = m.rest(); LS facts = mL("Random facts"); if (!contains(facts, fact)) { appendToMechList_noUniq("Random facts", fact); postMessage("Fact saved. Have " + n2(l(facts)+1, "fact") + "."); } } if (eqic(s, "!deriveFacts")) postMessage("Got " + n2(ai_applyFactToFactRules(), "fact") + ". Total: " + l(mL("Derived facts"))); // end of authorized functions } } } sclass TelegramFactsBot > AbstractThinkBot { !include #1017946 }