!7 sbool listen = true; static O onUpdate; static WebThoughtSpace ts; p { db(); ts = uniq(WebThoughtSpace); assertSame(mainConcepts, ts._concepts); if (isMain()) autoRestart(); if (empty(ts.webs)) loadFullHistory(); if (listen) { print("Listening to chat."); stefansChat_onLine(100, voidfunc(S line) { ChatMsg msg = mapToObject(stefansChat_onLine_fullParams!, ChatMsg); handleChatMsg(msg); pcallF(onUpdate); }); } bot("Chat Single Theory."); } svoid loadFullHistory() { int max = 10000; L l = stefansChat_readArchive(max); print("Got " + l(l) + "/" + max); for (ChatMsg msg : l) pcall { handleChatMsg(msg); } } svoid handleChatMsg(ChatMsg msg) { lock dbLock(); print("Handling " + msg.globalID); S sMsg = "Msg " + msg.globalID; WebNode node = ts.indexedNode(sMsg); if (node != null) ret; // No overwrite for now WebNode n = simpleWeb().newNode(); n.addLabel(/*"Text " +*/ quote(msg.text)); web_addString(n, msg.botMark ? "by bot" : "by user"); web_addStrings(n, ai_categoriesForChatLine(msg.text)); web_addString(n, "Time " + msg.time); web_addString(n, "Should I react?"); n.addLabel("Msg " + msg.globalID); thoughtSpace_addWeb(ts, n.web); print(" Have " + n(ts.webs, "web")); } answer { /*if "show *" ret showWeb(theoryForLineMap.get($1)) != null ? "OK" : "Not found";*/ if "load full history" ret "OK" with loadFullHistory(); if "size" ret lstr(ts.webs); }