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

62
LINES

< > BotCompany Repo | #1011364 // Chat Single Theory Module

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (14639L/104K).

1  
!7
2  
3  
sbool listen = true;
4  
static O onUpdate;
5  
6  
static WebThoughtSpace ts;
7  
8  
p {
9  
  db();
10  
  ts = uniq(WebThoughtSpace);
11  
  assertSame(mainConcepts, ts._concepts);
12  
  
13  
  if (isMain()) autoRestart();
14  
  
15  
  if (empty(ts.webs)) loadFullHistory();
16  
  if (listen) {
17  
    print("Listening to chat.");
18  
    stefansChat_onLine(100, voidfunc(S line) {
19  
      ChatMsg msg = mapToObject(stefansChat_onLine_fullParams!, ChatMsg);
20  
      handleChatMsg(msg);
21  
      pcallF(onUpdate);
22  
    });
23  
  }
24  
  bot("Chat Single Theory.");
25  
}
26  
27  
svoid loadFullHistory() {
28  
  int max = 10000;
29  
  L<ChatMsg> l = stefansChat_readArchive(max);
30  
  print("Got " + l(l) + "/" + max);
31  
  for (ChatMsg msg : l) pcall { handleChatMsg(msg); }
32  
}
33  
34  
svoid handleChatMsg(ChatMsg msg) {
35  
  lock dbLock();
36  
  
37  
  print("Handling " + msg.globalID);
38  
  
39  
  S sMsg = "Msg " + msg.globalID;
40  
  WebNode node = ts.indexedNode(sMsg);
41  
  if (node != null) ret; // No overwrite for now
42  
  
43  
  WebNode n = simpleWeb().newNode();
44  
  n.addLabel(/*"Text " +*/ quote(msg.text));
45  
  web_addString(n, msg.botMark ? "by bot" : "by user");
46  
  web_addStrings(n, ai_categoriesForChatLine(msg.text));
47  
  web_addString(n, "Time " + msg.time);
48  
  web_addString(n, "Should I react?");
49  
  n.addLabel("Msg " + msg.globalID);
50  
51  
  thoughtSpace_addWeb(ts, n.web);
52  
  print("  Have " + n(ts.webs, "web"));
53  
}
54  
55  
answer {
56  
  /*if "show *" 
57  
    ret showWeb(theoryForLineMap.get($1)) != null ? "OK" : "Not found";*/
58  
  if "load full history"
59  
    ret "OK" with loadFullHistory();
60  
    
61  
  if "size" ret lstr(ts.webs);
62  
}

Author comment

Began life as a copy of #1010963

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: #1011364
Snippet name: Chat Single Theory Module
Eternal ID of this version: #1011364/3
Text MD5: 053ce0cd1156d01473f2f6abd2908e9a
Transpilation MD5: 5431a62e7a24f32278d27e77b293fe38
Author: stefan
Category: javax / chat
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-26 04:03:26
Source code size: 1554 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 487 / 6591
Version history: 2 change(s)
Referenced in: [show references]