Libraryless. Click here for Pure Java version (5741L/38K).
static double stefansChat_onLine_safetyDelay = 1; // seconds static double stefansChat_onLine_shortSafetyDelay = 0.1; static double stefansChat_onLine_errorDelay = 10; static int stefansChat_onLine_lookback = 0; static int stefansChat_onLine_firstRead = -1; static new ThreadLocal<Map> stefansChat_onLine_fullParams; static new ThreadLocal stefansChat_onLine_onHistoryRead; static void stefansChat_onLine(int lookback, O f) { stefansChat_onLine_lookback = lookback; stefansChat_onLine(f); } static void stefansChat_onLine(fO f) { fO hr = getAndClearThreadLocal(stefansChat_onLine_onHistoryRead); thread "Stefan's Chat" { int a = stefansChat_onLine_firstRead = max(0, stefansChat_n()-stefansChat_onLine_lookback); bool first = true; while licensed { pcall { S s = loadPageWithTimeout("http://botcompany.de/1008998/raw/incremental?json=1&a=" + a, 120*1000); if (empty(trim(s))) { sleepSeconds(stefansChat_onLine_safetyDelay); //print("Re-polling."); continue; } try { Map map = safeUnstructMap(s); int n = getInt n(map); L msgs = cast get(map, 'msgs); for (O msg : msgs) try { stefansChat_onLine_fullParams.set(mapPlus((Map) msg, chatName := "Stefan's Chat")); pcallF(f, getString(msg, 'text)); } finally { stefansChat_onLine_fullParams.set(null); } sleepSeconds(stefansChat_onLine_shortSafetyDelay); a = n; } catch e { printException(e); sleepSeconds(stefansChat_onLine_errorDelay); } if (first) { pcallF(hr); first = false; } }} // end pcall, while licensed } }
Began life as a copy of #1009191
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009193 |
Snippet name: | stefansChat_onLine |
Eternal ID of this version: | #1009193/24 |
Text MD5: | 8d9160ad69b4469ee25b10e1e0865468 |
Transpilation MD5: | b6cf54d5fae3fa56ccfd1af7e6f45320 |
Author: | stefan |
Category: | javax / chat |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-07-14 21:47:12 |
Source code size: | 1765 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 578 / 700 |
Version history: | 23 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1009374 - stefansChat_lastLine #1010744 - stefansChat_onLine_safe #1011976 - smartBotsChat_onLine |