!7 module OSChatBot > DynModule { transient S imageID = #1101205; transient JTextField tfInput; transient JLabel lblOutput; start { 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(S s) { 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_setAIBarTextAndFire(s) }); ret withBottomMargin(20, centerAndSouthWithMargins( westAndCenterWithMargin(jimage(imageID), dm_printLogComponent()), jvstackWithSpacing( setFontSize(20, lblOutput = jCenteredBoldLabel("Hello!")), setFontSize(16, tfInput))); } void say(S s) { logStructureWithDate(osChatBotLogFile(), printLogEntry(ll("said", s))); } void got(S s) { logStructureWithDate(osChatBotLogFile(), printLogEntry(ll("typed", s))); } 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; } }