!7 static L bots; abstract sclass AbstractThinkBot { transient VF1 postMessage; abstract void thinkAbout(S input); void postMessage(S s) { callF(postMessage, s); } } p { mech_useLibrary(#1400122); L> classes = botClasses(); print("Have think classes: " + classNames(classes)); makeBots(); bot(); } static L> botClasses() { ret myNonAbstractClassesImplementing(AbstractThinkBot); } svoid makeBots() { bots = map nuWithoutArguments(botClasses()); } sS answer(S s) { for (AbstractThinkBot bot : bots) pcall { bot.postMessage = vfPrint(); temp tempSetThreadLocal(telegram_msg_tl(), new Map); bot.thinkAbout(s); } ret " "; } sclass TelegramThinkBot > AbstractThinkBot { void thinkAbout(S s) { 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))); } if (swic_trim(s, "!say ", m)) postMessage(m.rest()); 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 (swic_trim(s, "!eval ", m)) postMessage(strOrNull(javaEvalOrInterpret(m.rest()))); } } } sclass TelegramFactsBot > AbstractThinkBot { void thinkAbout(S s) { NLLogicChecker_v2 c = new NLLogicChecker_v2 { bool checkExpression(Exp e, Matching m) { if (e cast Func) { if (eq(e.name, "verbPhraseFromThirdPerson")) { L l = tok_splitAtComma(javaTokWithBrackets(nlLogic_text(e.arg))); if (l(l) != 2) false; l = mapReplaceVars2(l, m.matches); if (isDollarVar(second(l)) && !isDollarVar(first(l))) ret strictPutIC(m.matches, second(l), ai_verbPhraseFromThirdPerson(first(l))); ret eqic(second(l), first(l)); } } ret super.checkExpression(e, m); } }; c.matcher = new NLStringMatcher_dollarVars_underscores; c.input = s; c.facts = mL("Random facts"); applyNLLogicFacts_v2(c, voidfunc(S s) { postMessage(s) }, ai_mL_parsedLogicExamples()); } } sclass TelegramInitiativeBot > AbstractThinkBot { new L> activeTempRules; void thinkAbout(S s) { if (eq(s, "!initiative")) { L rules = mL_parsedNLRulesWithoutIDs("Initiative rules"); for (IfThen rule : shuffledIterator(rules)) { Pair p = nlLogic_extractFirstCondition(rule.in); if (p == null) continue; if (nlLogic_isFunc(p.a, 'initiative)) { postMessage(nlLogic_text(((Func) p.a).arg)); IfThen temp = IfThen(p.b, rule.out); print("Have temp rule: " + sfu(temp)); activeTempRules.add(pair(aGlobalID(), temp)); ret; } } } applyNLLogicFacts_v2(s, voidfunc(S s) { postMessage(s) }, new L, activeTempRules); activeTempRules.clear(); } }