Uses 408K of libraries. Click here for Pure Java version (15033L/106K).
!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; } }
Began life as a copy of #1019669
download show line numbers debug dex old transpilations
Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jozkyjcghlvl, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1019675 |
Snippet name: | OS Chat Bot v1 [OK] |
Eternal ID of this version: | #1019675/20 |
Text MD5: | 1974dd34c126b9ab35f6150a54270e27 |
Transpilation MD5: | 8165cd2ac09c55a024b785247195070c |
Author: | stefan |
Category: | javax / stefan's os / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-27 20:26:16 |
Source code size: | 1664 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 392 / 3520 |
Version history: | 19 change(s) |
Referenced in: | #1020415 - Train Interaction [dev.] |