!7 cmodule TrainableBot > DynSockPuppetConvo { delegate Post to JChatConvo. LS suggestions; S functions; transient SingleComponentPanel scpSuggestions; transient FunctionsLoader loader; transient Thread playThread; start { onPostAdded.add(post -> startPlaying()); loadIfNotLoaded(); } visual jvsplit(super, withMargin(jhsplit( jCenteredSection("Suggestions", scpSuggestions = singleComponentPanel(renderSuggestions())), northAndCenterWithMargin( jrightaligned(jbutton("Load", rThreadEnter loadFunctions)), dm_textAreaAsSection functions())))); JComponent renderSuggestions() { ret ele_renderSuggestions(null, suggestions, sayAction := (IVF1) s -> { addPost(s, true); dm_say(s); }, submitAction := (IVF1) s -> { addPost(s, false); dm_say(s); }); } void showSuggestions(Cl suggestions) { setField(suggestions := asList(suggestions)); showSuggestions(); } void showSuggestions { scpSuggestions?.setComponent(renderSuggestions()); } void loadFunctions { dispose loader; loader = new FunctionsLoader(filter isStandardFunction(tlftj(functions))); loader.loadFunctionsParams = litparams(header := "set flag NoGenericFunctions."); loader.onLoaded(r startPlaying); loader.loadInBackground(); } void startPlaying enter { if (loader == null) loadFunctions(); cancelThread(playThread); playThread = null; playThread = startThread(rEnter play); } void play { //showSuggestions(ll("test " + now())); new LinkedHashSet l; S input = lastInput(); for ping (S f : loader.functions) { addIfInstanceOf(l, S, callBlobFunction(f)); ping(); if (nempty(input)) addIfInstanceOf(l, S, callBlobFunction(f, input)); } showSuggestions(l); } // API void loadIfNotLoaded() { if (loader == null) loadFunctions(); } Set loadedFunctions() { ret loader.functions; } S maxNum() { ret firstIntegerString(tlftj(functions)); } O blob() { ret loader.blob; } O callBlobFunction(S fname, O... args) { if (canCallWithVarargs(module(), fname, args)) ret callWithVarargs(module(), fname ,args); else ret callOpt(loader.blob, fname, args); } LPairS userBotPairs() { ret chatConvo_userBotPairs(posts); } LS rawLines() { ret collect html(posts); } S firstLine() { ret getString html(first(posts)); } int numLines() { ret l(posts); } void suggest(S s) { showSuggestions(ll(s)); } }