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

36
LINES

< > BotCompany Repo | #1027721 // CruddieFollower - web client for cruddie

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4054L/27K).

1  
sclass CruddieFollower {
2  
  S cookie;
3  
  int n;
4  
  double timeout = 70;
5  
6  
  swappable void newDialog() {}
7  
  swappable void botUtterance(S html) {
8  
    print("Bot said (HTML): " + html);
9  
    vmBus_send cruddieSaid(cookie, html);
10  
  }
11  
  swappable void onUserUtterance(S html) {} // TODO
12  
  swappable void onBotUtterance(S html) {}
13  
  
14  
  *(S cookie) { this(cookie, false); }
15  
  
16  
  *(S *cookie, bool withHistory) {
17  
    if (!withHistory)
18  
      n = parseInt(loadPageWithParamsSilently("https://cruddie.site/bot/n", +cookie);
19  
  }
20  
  
21  
  // may block for 60 seconds. returns HTML
22  
  public S get() {
23  
    // TODO: I think cruddie.site doesn't close existing connections when rebooting (?)
24  
    S src = loadPageWithTimeoutAndParamsSilently(timeout, "https://cruddie.site/bot/incremental",
25  
      +cookie, a := zeroToNull(n));
26  
    S newN = firstIntAsString_regexp(src);
27  
    if (nempty(newN)) {
28  
      n = parseInt(newN);
29  
      if (cic(src, "NEW DIALOG -->")) newDialog();
30  
      else
31  
        doForEach botUtterance(regexpAllFirstGroups(
32  
          [[bot-utterance">(.*?)<]], src));
33  
    }
34  
    ret src;
35  
  }
36  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027721
Snippet name: CruddieFollower - web client for cruddie
Eternal ID of this version: #1027721/22
Text MD5: 1889aef814a05c031103e2a266ecb3d6
Transpilation MD5: e1746412c7cfb6fa656cec0418445520
Author: stefan
Category: javax / cruddie
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-20 23:12:03
Source code size: 1113 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 248 / 646
Version history: 21 change(s)
Referenced in: [show references]