sclass WebBotTester implements AutoCloseable { S botURL; // without the "/incremental" S cookie = "test_" + aGlobalID(); int n; // number of messages grabbed Thread grabThread; volatile bool closed; LS allHtml = syncList(); new L msgs; double readTimeout = 120.0, sendTimeout = 20.0; sclass Msg { S html; bool fromUser; long timeReceived; } *(S botID) { botURL = "https://botcompany.de/" + psI(botID) + "/raw"; } public void close { set closed; cancelAndInterruptThread(grabThread); } selfType start() { if (grabThread == null) grabThread = startThread(r _grabLoop); this; } void _grabLoop { while (!closed) { S html = loadPageWithTimeout(botURL + "/incremental" + hquery(+cookie, a := n), readTimeout); allHtml.add(html); S comment = first(getHTMLComments(html)); int n = parseFirstIntOrMinus1(comment); if (n >= 0) this.n = n; sleepSeconds(1); } } void sendMsg(S msg) { print(postPageWithTimeout(sendTimeout, botURL + "/msg", +cookie, +msg)); } }