sclass GazelleTalkToBot { long botID; // Gazelle post ID S cookie = "test_" + aGlobalID(); int n; // number of messages loaded double serverTimeout = 10, networkTimeout = 10; new L msgs; *(long *botID) {} swappable void onNewDialog() {} swappable void onNewMsg(Msg msg) {} void grab { S json = loadPageWithTimeoutAndParamsSilently(serverTimeout+networkTimeout, "https://gazelle.rocks/incremental", +cookie, _botConfig := "codePost=" + botID, json := 1, a := zeroToNull(n), timeout := iceil(serverTimeout)); if (empty(json)) ret; // just timed out Map map = decodeJSONMap(json); onResult(map); } swappable void onResult(Map map) { if (map.containsKey("n")) n = toInt(map.get("n")); if (isTrue(map.get("newDialog"))) onNewDialog(); fOr (Map m : (L) map.get("msgs")) { new Msg msg; msg.fromUser = isTrue(m.get("fromUser")); msg.text = (S) m.get("text"); msg.time = toLong(m.get("time")); msgs.add(msg); print("Got msg: " + msg); pcall { onNewMsg(msg); } } } // send a message to bot void send(S message) { S response = loadPageWithTimeoutAndParamsSilently(networkTimeout, "https://gazelle.rocks/msg", +cookie, _botConfig := "codePost=" + botID, +message); if (!startsWith(response, "OK")) print("Server said: " + response); } }