Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1011976 // smartBotsChat_onLine

JavaX fragment (include)

1  
// We're also using some of stefansChat_onLine's variables
2  
please include function stefansChat_onLine.
3  
4  
static double smartBotsChat_onLine_safetyDelay = 1; // seconds
5  
static double smartBotsChat_onLine_shortSafetyDelay = 0.1;
6  
static double smartBotsChat_onLine_errorDelay = 10;
7  
static int smartBotsChat_onLine_lookback = 0;
8  
static int smartBotsChat_onLine_firstRead = -1;
9  
static new ThreadLocal smartBotsChat_onLine_onHistoryRead;
10  
11  
static void smartBotsChat_onLine(int lookback, O f) {
12  
  smartBotsChat_onLine_lookback = lookback;
13  
  smartBotsChat_onLine(f);
14  
}
15  
16  
static void smartBotsChat_onLine(fO f) {
17  
  fO hr = getAndClearThreadLocal(smartBotsChat_onLine_onHistoryRead);
18  
  thread "Smart Bot's Chat" {
19  
    int a = smartBotsChat_onLine_firstRead = max(0, smartBotsChat_n() - smartBotsChat_onLine_lookback);
20  
    bool first = true;
21  
    while licensed { pcall {
22  
      S s = loadPageWithTimeout("http://botcompany.de/1011975/raw/incremental?json=1&a=" + a, 120*1000);
23  
      if (empty(trim(s))) {
24  
        sleepSeconds(smartBotsChat_onLine_safetyDelay);
25  
        //print("Re-polling.");
26  
        continue;
27  
      }
28  
      try {
29  
        Map map = safeUnstructMap(s);
30  
        int n = getInt(map, 'n);
31  
        L msgs = cast get(map, 'msgs);
32  
        for (O msg : msgs)
33  
          try {
34  
            stefansChat_onLine_fullParams.set(mapPlus((Map) msg, chatName := "Smart Bot's Chat"));
35  
            pcallF(f, getString(msg, 'text));
36  
          } finally {
37  
            stefansChat_onLine_fullParams.set(null);
38  
          }
39  
        sleepSeconds(smartBotsChat_onLine_shortSafetyDelay);
40  
        a = n;
41  
      } catch e {
42  
        printException(e);
43  
        sleepSeconds(smartBotsChat_onLine_errorDelay);
44  
      }
45  
      
46  
      if (first) {
47  
        pcallF(hr);
48  
        first = false;
49  
      }
50  
    }} // end pcall, while licensed
51  
  }
52  
}

Author comment

Began life as a copy of #1009193

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: #1011976
Snippet name: smartBotsChat_onLine
Eternal ID of this version: #1011976/12
Text MD5: a0acbeb5f0318f2573df06ee6feb3e99
Author: stefan
Category: javax / chat
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-02 16:33:32
Source code size: 1854 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 470 / 525
Version history: 11 change(s)
Referenced in: [show references]