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

74
LINES

< > BotCompany Repo | #1026808 // Parrot 1.1 (with functions list, runs each function invidiually)

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (16334L/91K).

!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());
  }
  
  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>) s -> addPost(s, true),
      submitAction := (IVF1<S>) s -> addPost(s, false));
  }
  
  void showSuggestions(Cl<S> 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<S> 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);
  }
  
  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); }
}

Author comment

Began life as a copy of #1026803

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026808
Snippet name: Parrot 1.1 (with functions list, runs each function invidiually)
Eternal ID of this version: #1026808/32
Text MD5: 311c0366ca4b19ccfc098bcb7553f9cd
Transpilation MD5: 140b5960b0c9a372a6f0b6ab34fc0ff2
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-25 15:52:27
Source code size: 2138 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 245 / 610
Version history: 31 change(s)
Referenced in: [show references]