abstract sclass AbstractTelegramThinkBot > DynPrintLog { abstract void thinkAbout(S input); transient int lookback = 3; // old lines to grab transient Set toSend; transient new LatestList recentHistory; start { loadFunctions_preferCached(); dm_useLocallyCopiedMechLists(); recentHistory.addAll(map_pcall unstructureUnquote(dropLast(lastNLines(lookback, telegramLogFile())))); watchStructureLog_plusLastLine(500, telegramLogFile(), voidfunc(Map map) { if (!eqGet(map, 'type, 'heard)) ret; printStruct(map); try { setThreadLocal((ThreadLocal) getOptMC('makeAndCall_initChild), voidfunc(Class c) { copyFields(mc(), c, 'telegram_msg_tl) }); temp tempSetThreadLocal(telegram_msg_tl(), map); S s = getString(map, 'text); toSend = new LinkedHashSet; thinkAbout(s); for (S out : takeFirst(3, getAndClearList(toSend))) telegram_postToSendLog(out); } catch e { printStackTrace(e); postMessage(exceptionToStringShort(e)); } finally { recentHistory.add(map); } }); } void postMessage(S s) { print("Sending: " + s); toSend.add(s); } }