// We're also using some of stefansChat_onLine's variables please include function stefansChat_onLine. static double smartBotsChat_onLine_safetyDelay = 1; // seconds static double smartBotsChat_onLine_shortSafetyDelay = 0.1; static double smartBotsChat_onLine_errorDelay = 10; static int smartBotsChat_onLine_lookback = 0; static int smartBotsChat_onLine_firstRead = -1; static new ThreadLocal smartBotsChat_onLine_onHistoryRead; static void smartBotsChat_onLine(int lookback, O f) { smartBotsChat_onLine_lookback = lookback; smartBotsChat_onLine(f); } static void smartBotsChat_onLine(fO f) { fO hr = getAndClearThreadLocal(smartBotsChat_onLine_onHistoryRead); thread "Smart Bot's Chat" { int a = smartBotsChat_onLine_firstRead = max(0, smartBotsChat_n() - smartBotsChat_onLine_lookback); bool first = true; while licensed { pcall { S s = loadPageWithTimeout("http://botcompany.de/1011975/raw/incremental?json=1&a=" + a, 120*1000); if (empty(trim(s))) { sleepSeconds(smartBotsChat_onLine_safetyDelay); //print("Re-polling."); continue; } try { Map map = safeUnstructMap(s); int n = getInt(map, 'n); L msgs = cast get(map, 'msgs); for (O msg : msgs) try { stefansChat_onLine_fullParams.set(mapPlus((Map) msg, chatName := "Smart Bot's Chat")); pcallF(f, getString(msg, 'text)); } finally { stefansChat_onLine_fullParams.set(null); } sleepSeconds(smartBotsChat_onLine_shortSafetyDelay); a = n; } catch e { printException(e); sleepSeconds(smartBotsChat_onLine_errorDelay); } if (first) { pcallF(hr); first = false; } }} // end pcall, while licensed } }