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).

1  
abstract sclass DynAttractorBot > DynPrintLog {
2  
  S input, dialogText;
3  
  bool voiceMode;
4  
  AttractorBot bot;
5  
  transient L onBotSaid = synchroList(); // L<VF1<S>>
6  
  transient bool activateOnOutput = true;
7  
  bool persistBot;
8  
  transient JTabbedPane tabs;
9  
10  
  void submitInput(S input) {
11  
    setField(+input);
12  
    submitInput();
13  
  }
14  
  
15  
  void submitInput {
16  
    lock lock;
17  
    setField(input := trim(input));
18  
    addToDialog("User: " + input);
19  
    S s = input;
20  
    if "new dialogue|new dialog"
21  
      startDialog();
22  
    else if (bot != null)
23  
      bot.addInput(input);
24  
  }
25  
  
26  
  visual tabs = jtabs("Dialog" :=
27  
    northCenterAndSouthWithMargins(
28  
      rightAlignedButtons(
29  
        dm_fieldCheckBox('voiceMode),
30  
        "New dialog", rThread startDialog,
31  
        "Clear window", rThread clearDialogText),
32  
      wordWrapTextArea(dm_textArea_scrollDown_readOnly('dialogText)),
33  
      dm_textFieldAndSubmit_q('input, 'submitInput, focusOnShow := true)), "Log" := super);
34  
35  
  void runBot(AttractorBot bot) {
36  
    setField(+bot);
37  
    runBot();
38  
  }
39  
  
40  
  void addToDialog(S s) {
41  
    setField(dialogText := appendWithNewLine(dialogText, print(s)));
42  
  }
43  
  
44  
  void runBot {
45  
    bot.say = voidfunc(S s) {
46  
      addToDialog("Bot: " + s);
47  
      pcallFAll(onBotSaid, s);
48  
      vmBus_send aBotSaid(me(), s);
49  
      if (voiceMode) {
50  
        if (activateOnOutput) dm_activateOSAndModule();
51  
        dm_say(s);
52  
      }
53  
    };
54  
    
55  
    thread "Bot" {
56  
      bot.run_public();
57  
      print("\n[end]");
58  
    }
59  
  }
60  
  
61  
  void clearDialogText {
62  
    setField(dialogText := "");
63  
  }
64  
  
65  
  abstract AttractorBot makeBot();
66  
  
67  
  void makeBotIfNotThere {
68  
    if (bot == null) setField(bot := makeBot());
69  
  }
70  
  
71  
  void startDialog {
72  
    clearDialogText();
73  
    makeBotIfNotThere();
74  
    runBot(bot);
75  
  }
76  
  
77  
  start {
78  
    logModuleOutput();
79  
    dontPersist('bot);
80  
    dm_onTopInput_q(voidfunc(S s) {
81  
      if (!voiceMode) ret;
82  
      //dm_activateOSAndModule();
83  
      submitInput(s);
84  
    });
85  
    startDialog();
86  
  }
87  
  
88  
  void persistBot {
89  
    doPersist('bot);
90  
  }
91  
}

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: 311 / 925
Version history: 34 change(s)
Referenced in: [show references]