abstract sclass AbstractTelegramThinkBot > DynPrintLog { abstract void thinkAbout(S input); transient int lookback = 3; // old lines to grab transient int maxCharsPerMessage = 2000; transient int maxLinesPerMessage = 20; transient Set toSend; transient LatestList recentHistory; // only called when not in test mode start { loadFunctions_preferCached(); dm_useLocallyCopiedMechLists(); recentHistory = new LatestList(lookback); recentHistory.addAll(map_pcall unstructureUnquote(dropLast(lastNLines(lookback, telegramLogFile())))); watchStructureLog_plusLastLine(500, telegramLogFile(), voidfunc(final Map map) { temp tempAfterwards(r { recentHistory.add(map) }); if (!eqGet(map, 'type, 'heard)) ret; printStruct(map); try { setThreadLocal((ThreadLocal) getOptMC('makeAndCall_initChild), voidfunc(Class c) { copyFields(mc(), c, 'telegram_msg_tl, 'telegram_recentHistory_tl) }); temp tempSetThreadLocal(telegram_msg_tl(), map); temp tempSetThreadLocal(telegram_recentHistory_tl(), recentHistory); S s = getString(map, 'text); toSend = new LinkedHashSet; thinkAbout(s); for (S out : takeFirst(3, getAndClearList(toSend))) { Long chatID = (Long) _get(map, 'where); S globalID = isTrue(_get(map, 'fromVoice)) ? telegram_postVoiceMessageToSendLog(out, "Andy", chatID) : telegram_postToSendLog(out, chatID); if (globalID != null) recentHistory.add(litmap(text := out, globalID)); } } catch e { printStackTrace(e); postMessage(exceptionToStringShort(e)); } }); } void postMessage(S s) { s = shortenToMaxLinesAndChars(rtrim(s), maxLinesPerMessage, maxCharsPerMessage); print("Sending: " + s); toSend.add(s); } }