!7 module OSChatBot > DynModule { transient S imageID = #1101205; transient JTextField tfInput; transient JLabel lblOutput; start { dm_useLocalMechListCopies(); for (S s : lastNLinesOfFile(osChatBotLogFile(), 5)) pcall { if ((s = unquoteOrNull(s)) != null) printLogEntry((L) unstruct(afterSpace(s))); } if (empty(osChatBotLogFile())) say("Hello!"); // Gather voice input from other modules dm_onTopInput(voidfunc(fS s) { switch to q(); got(s) }); // Gather voice output from other modules ownResource(vmBus_onMessage('saying, voidfunc(S s) { setText(lblOutput, s); say(s) })); } visualize { onEnter(tfInput = jCenteredTextField(), r { S s = getText(tfInput); //got(s); dm_setAIBarTextAndFireWithInfo(s, "typed in chat bot window") }); ret withBottomMargin(20, centerAndSouthWithMargins( westAndCenterWithMargin(jimage(imageID), dm_printLogComponent()), jvstackWithSpacing( fontSize(20, lblOutput = jCenteredBoldLabel("Hello!")), withLabel("Type here:", focusOnShow(fontSize(16, tfInput))))); } void say(S s) { logStructureWithDate(osChatBotLogFile(), printLogEntry(ll("said", s))); } void got(S s) { logStructureWithDate(osChatBotLogFile(), printLogEntry(ll("typed", s))); reactTo(s); } void reactTo(S s) enter { } L printLogEntry(L l) { if (eq(first(l), "said")) print("Me: " + second(l)); else if (eq(first(l), "typed")) print("You: " + second(l)); ret l; } }