Libraryless. Click here for Pure Java version (5741L/38K).
1 | static double stefansChat_onLine_safetyDelay = 1; // seconds |
2 | static double stefansChat_onLine_shortSafetyDelay = 0.1; |
3 | static double stefansChat_onLine_errorDelay = 10; |
4 | static int stefansChat_onLine_lookback = 0; |
5 | static int stefansChat_onLine_firstRead = -1; |
6 | |
7 | static new ThreadLocal<Map> stefansChat_onLine_fullParams; |
8 | static new ThreadLocal stefansChat_onLine_onHistoryRead; |
9 | |
10 | static void stefansChat_onLine(int lookback, O f) { |
11 | stefansChat_onLine_lookback = lookback; |
12 | stefansChat_onLine(f); |
13 | } |
14 | |
15 | static void stefansChat_onLine(fO f) { |
16 | fO hr = getAndClearThreadLocal(stefansChat_onLine_onHistoryRead); |
17 | thread "Stefan's Chat" { |
18 | int a = stefansChat_onLine_firstRead = max(0, stefansChat_n()-stefansChat_onLine_lookback); |
19 | bool first = true; |
20 | while licensed { pcall { |
21 | S s = loadPageWithTimeout("http://botcompany.de/1008998/raw/incremental?json=1&a=" + a, 120*1000); |
22 | if (empty(trim(s))) { |
23 | sleepSeconds(stefansChat_onLine_safetyDelay); |
24 | //print("Re-polling."); |
25 | continue; |
26 | } |
27 | try { |
28 | Map map = safeUnstructMap(s); |
29 | int n = getInt n(map); |
30 | L msgs = cast get(map, 'msgs); |
31 | for (O msg : msgs) |
32 | try { |
33 | stefansChat_onLine_fullParams.set(mapPlus((Map) msg, chatName := "Stefan's Chat")); |
34 | pcallF(f, getString(msg, 'text)); |
35 | } finally { |
36 | stefansChat_onLine_fullParams.set(null); |
37 | } |
38 | sleepSeconds(stefansChat_onLine_shortSafetyDelay); |
39 | a = n; |
40 | } catch e { |
41 | printException(e); |
42 | sleepSeconds(stefansChat_onLine_errorDelay); |
43 | } |
44 | |
45 | if (first) { |
46 | pcallF(hr); |
47 | first = false; |
48 | } |
49 | }} // end pcall, while licensed |
50 | } |
51 | } |
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: | 579 / 702 |
Version history: | 23 change(s) |
Referenced in: | [show references] |