!7 static Map theoryForLineMap; static L globalIDList; // msg index to global ID sbool listen = true; p { autoRestart(5); theoryForLineMap = persistentHashMap('theoryForLineMap); globalIDList = persistentList('globalIDList); if (listen) { print("Listening to chat."); stefansChat_onLine(10, voidfunc(S line) { ChatMsg msg = mapToObject(stefansChat_onLine_fullParams!, ChatMsg); handleChatMsg(msg); }); } bot("Chat 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); listPut(globalIDList, msg.nr, msg.globalID); Web web = theoryForLineMap.get(msg.globalID); 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); n.addLabel("Msg " + msg.globalID); if (web_contentsDifferent(web, n.web)) { if (web != null) print("Overwriting " + msg.globalID); theoryForLineMap.put(msg.globalID, n.web); } } answer { if "show *" ret showWeb(theoryForLineMap.get($1)) != null ? "OK" : "Not found"; if "load full history" ret "OK" with loadFullHistory(); }