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

46
LINES

< > BotCompany Repo | #1028641 // WebBotTester

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

Transpiled version (6589L) is out of date.

1  
sclass WebBotTester implements AutoCloseable {
2  
  S botURL; // without the "/incremental"
3  
  S cookie = "test_" + aGlobalID();
4  
  int n; // number of messages grabbed
5  
  Thread grabThread;
6  
  volatile bool closed;
7  
  LS allHtml = syncList();
8  
  new L<WebChatBotMsg> msgs;
9  
  double readTimeout = 120.0, sendTimeout = 20.0;
10  
  double waitForMessagesTimeout = 20.0;
11  
  SS params = new LinkedHashMap;
12  
13  
  *(S botID) { botURL = "https://botcompany.de/" + psI(botID) + "/raw"; }
14  
  
15  
  public void close {
16  
    set closed;
17  
    cancelAndInterruptThread(grabThread);
18  
  }
19  
  
20  
  selfType start() {
21  
    if (grabThread == null)
22  
      grabThread = startThread(r _grabLoop);
23  
    this;
24  
  }
25  
  
26  
  void _grabLoop {
27  
    while (!closed) {
28  
      S html = loadPageWithTimeout(botURL + "/incremental" + hquery(mapPlus(params, +cookie, a := n)), readTimeout);
29  
      allHtml.add(html);
30  
      printWithIndent("> ", html);
31  
      msgs.addAll(webBotTester_extractMsgs(html));
32  
      S comment = first(getHTMLComments(html));
33  
      int n = parseFirstIntOrMinus1(comment);
34  
      if (n >= 0) this.n = n;
35  
      sleepSeconds(1);
36  
    }
37  
  }
38  
  
39  
  void sendMsg(S message) {
40  
    print(doPostWithTimeout(mapPlus(params, +cookie, +message), botURL + "/msg", toMS_int(sendTimeout)));
41  
  }
42  
  
43  
  void waitForMessages(int n) {
44  
    waitUntil(50, waitForMessagesTimeout, () -> l(msgs) >= n);
45  
  }
46  
}

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: #1028641
Snippet name: WebBotTester
Eternal ID of this version: #1028641/18
Text MD5: 9005533c32e504eb10be71be09b3e6a4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-02 18:21:25
Source code size: 1379 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 207 / 544
Version history: 17 change(s)
Referenced in: [show references]