Uses 408K of libraries. Click here for Pure Java version (15033L/106K).
1 | !7 |
2 | |
3 | module OSChatBot > DynModule {
|
4 | transient S imageID = #1101205; |
5 | transient JTextField tfInput; |
6 | transient JLabel lblOutput; |
7 | |
8 | start {
|
9 | dm_useLocalMechListCopies(); |
10 | |
11 | for (S s : lastNLinesOfFile(osChatBotLogFile(), 5)) pcall {
|
12 | if ((s = unquoteOrNull(s)) != null) |
13 | printLogEntry((L) unstruct(afterSpace(s))); |
14 | } |
15 | if (empty(osChatBotLogFile())) |
16 | say("Hello!");
|
17 | |
18 | // Gather voice input from other modules |
19 | dm_onTopInput(voidfunc(fS s) { switch to q(); got(s) });
|
20 | |
21 | // Gather voice output from other modules |
22 | ownResource(vmBus_onMessage('saying, voidfunc(S s) {
|
23 | setText(lblOutput, s); |
24 | say(s) |
25 | })); |
26 | } |
27 | |
28 | visualize {
|
29 | onEnter(tfInput = jCenteredTextField(), r {
|
30 | S s = getText(tfInput); |
31 | //got(s); |
32 | dm_setAIBarTextAndFireWithInfo(s, "typed in chat bot window") |
33 | }); |
34 | ret withBottomMargin(20, |
35 | centerAndSouthWithMargins( |
36 | westAndCenterWithMargin(jimage(imageID), dm_printLogComponent()), |
37 | jvstackWithSpacing( |
38 | fontSize(20, lblOutput = jCenteredBoldLabel("Hello!")),
|
39 | withLabel("Type here:", focusOnShow(fontSize(16, tfInput)))));
|
40 | } |
41 | |
42 | void say(S s) {
|
43 | logStructureWithDate(osChatBotLogFile(), printLogEntry(ll("said", s)));
|
44 | } |
45 | |
46 | void got(S s) {
|
47 | logStructureWithDate(osChatBotLogFile(), printLogEntry(ll("typed", s)));
|
48 | reactTo(s); |
49 | } |
50 | |
51 | void reactTo(S s) enter {
|
52 | } |
53 | |
54 | L printLogEntry(L l) {
|
55 | if (eq(first(l), "said")) |
56 | print("Me: " + second(l));
|
57 | else if (eq(first(l), "typed")) |
58 | print("You: " + second(l));
|
59 | ret l; |
60 | } |
61 | } |
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: | 640 / 3817 |
| Version history: | 19 change(s) |
| Referenced in: | [show references] |