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

91
LINES

< > BotCompany Repo | #1022807 // DynAttractorBot

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (14794L/106K).

abstract sclass DynAttractorBot > DynPrintLog {
  S input, dialogText;
  bool voiceMode;
  AttractorBot bot;
  transient L onBotSaid = synchroList(); // L<VF1<S>>
  transient bool activateOnOutput = true;
  bool persistBot;
  transient JTabbedPane tabs;

  void submitInput(S input) {
    setField(+input);
    submitInput();
  }
  
  void submitInput {
    lock lock;
    setField(input := trim(input));
    addToDialog("User: " + input);
    S s = input;
    if "new dialogue|new dialog"
      startDialog();
    else if (bot != null)
      bot.addInput(input);
  }
  
  visual tabs = jtabs("Dialog" :=
    northCenterAndSouthWithMargins(
      rightAlignedButtons(
        dm_fieldCheckBox('voiceMode),
        "New dialog", rThread startDialog,
        "Clear window", rThread clearDialogText),
      wordWrapTextArea(dm_textArea_scrollDown_readOnly('dialogText)),
      dm_textFieldAndSubmit_q('input, 'submitInput, focusOnShow := true)), "Log" := super);

  void runBot(AttractorBot bot) {
    setField(+bot);
    runBot();
  }
  
  void addToDialog(S s) {
    setField(dialogText := appendWithNewLine(dialogText, print(s)));
  }
  
  void runBot {
    bot.say = voidfunc(S s) {
      addToDialog("Bot: " + s);
      pcallFAll(onBotSaid, s);
      vmBus_send aBotSaid(me(), s);
      if (voiceMode) {
        if (activateOnOutput) dm_activateOSAndModule();
        dm_say(s);
      }
    };
    
    thread "Bot" {
      bot.run_public();
      print("\n[end]");
    }
  }
  
  void clearDialogText {
    setField(dialogText := "");
  }
  
  abstract AttractorBot makeBot();
  
  void makeBotIfNotThere {
    if (bot == null) setField(bot := makeBot());
  }
  
  void startDialog {
    clearDialogText();
    makeBotIfNotThere();
    runBot(bot);
  }
  
  start {
    logModuleOutput();
    dontPersist('bot);
    dm_onTopInput_q(voidfunc(S s) {
      if (!voiceMode) ret;
      //dm_activateOSAndModule();
      submitInput(s);
    });
    startDialog();
  }
  
  void persistBot {
    doPersist('bot);
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1022807
Snippet name: DynAttractorBot
Eternal ID of this version: #1022807/35
Text MD5: 8be2108f2e28fc63584873bc2cff637c
Transpilation MD5: 7b116835c81820e3d13430b3b7999afe
Author: stefan
Category: javax / stefan's os
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-06-17 00:07:08
Source code size: 2105 bytes / 91 lines
Pitched / IR pitched: No / No
Views / Downloads: 305 / 917
Version history: 34 change(s)
Referenced in: [show references]