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

38
LINES

< > BotCompany Repo | #1003117 // simpleChatListen - calls "process(L msgs)" method

JavaX fragment (include)

1  
// TODO: wait for chat to come up
2  
static void simpleChatListen() {
3  
  O chat = simpleChatBot();
4  
  if (chat == null)
5  
    simpleChatListen_remote();
6  
  else {
7  
    simpleChatListen_n = (int) call(chat, "size");
8  
    simpleChatNotifyMe();
9  
  }
10  
}
11  
12  
static void simpleChatListen_remote() {
13  
  thread "Chat Listener" {
14  
    simpleChatListen_n = parseInt(loadPage("http://ai1.lol/" + simpleChatID() + "/raw/n"));
15  
    
16  
    while (licensed()) {
17  
      pcall {
18  
        L msgs = cast unstructure(htmldecode(loadPage("http://ai1.lol/" + simpleChatID() + "/raw/incremental?robo=1&a=" + simpleChatListen_n)));
19  
        simpleChatListen_n += l(msgs);
20  
        process(msgs);
21  
      }
22  
      sleep(simpleChatListen_delay);
23  
    }
24  
  }
25  
}
26  
27  
static volatile int simpleChatListen_delay = 5000;
28  
static int simpleChatListen_n;
29  
30  
static void simpleChatUpdated() {
31  
  O chat = simpleChatBot();
32  
  int n2 = (int) call(chat, "size");
33  
  if (n2 > simpleChatListen_n) {
34  
    L msgs = cast call(chat, "getMessages", simpleChatListen_n, n2);
35  
    simpleChatListen_n = n2;
36  
    process(msgs);
37  
  }
38  
}

Author comment

Note: It keeps the program alive in the remote case (runs a listener thread)

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: #1003117
Snippet name: simpleChatListen - calls "process(L msgs)" method
Eternal ID of this version: #1003117/1
Text MD5: 684a7d5f743d69dadbb124fe09450520
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-06-06 00:53:00
Source code size: 1083 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 562 / 547
Referenced in: [show references]