Uses 911K of libraries. Click here for Pure Java version (16421L/91K).
1 | !7 |
2 | |
3 | cmodule TrainableBot > DynSockPuppetConvo {
|
4 | delegate Post to JChatConvo. |
5 | |
6 | LS suggestions; |
7 | S functions; |
8 | transient SingleComponentPanel scpSuggestions; |
9 | transient FunctionsLoader loader; |
10 | transient Thread playThread; |
11 | |
12 | start {
|
13 | onPostAdded.add(post -> startPlaying()); |
14 | loadIfNotLoaded(); |
15 | } |
16 | |
17 | visual jvsplit(super, |
18 | withMargin(jhsplit( |
19 | jCenteredSection("Suggestions", scpSuggestions = singleComponentPanel(renderSuggestions())),
|
20 | northAndCenterWithMargin( |
21 | jrightaligned(jbutton("Load", rThreadEnter loadFunctions)),
|
22 | dm_textAreaAsSection functions())))); |
23 | |
24 | JComponent renderSuggestions() {
|
25 | ret ele_renderSuggestions(null, suggestions, |
26 | sayAction := (IVF1<S>) s -> { addPost(s, true); dm_say(s); },
|
27 | submitAction := (IVF1<S>) s -> { addPost(s, false); dm_say(s); });
|
28 | } |
29 | |
30 | void showSuggestions(Cl<S> suggestions) {
|
31 | setField(suggestions := asList(suggestions)); |
32 | showSuggestions(); |
33 | } |
34 | |
35 | void showSuggestions {
|
36 | scpSuggestions?.setComponent(renderSuggestions()); |
37 | } |
38 | |
39 | void loadFunctions {
|
40 | dispose loader; |
41 | loader = new FunctionsLoader(filter isStandardFunction(tlftj(functions))); |
42 | loader.loadFunctionsParams = litparams(header := "set flag NoGenericFunctions."); |
43 | loader.onLoaded(r startPlaying); |
44 | loader.loadInBackground(); |
45 | } |
46 | |
47 | void startPlaying enter {
|
48 | if (loader == null) loadFunctions(); |
49 | cancelThread(playThread); |
50 | playThread = null; |
51 | playThread = startThread(rEnter play); |
52 | } |
53 | |
54 | void play {
|
55 | //showSuggestions(ll("test " + now()));
|
56 | new LinkedHashSet<S> l; |
57 | S input = lastInput(); |
58 | for ping (S f : loader.functions) {
|
59 | addIfInstanceOf(l, S, callBlobFunction(f)); |
60 | ping(); |
61 | if (nempty(input)) |
62 | addIfInstanceOf(l, S, callBlobFunction(f, input)); |
63 | } |
64 | showSuggestions(l); |
65 | } |
66 | |
67 | // API |
68 | |
69 | void loadIfNotLoaded() { if (loader == null) loadFunctions(); }
|
70 | Set<S> loadedFunctions() { ret loader.functions; }
|
71 | S maxNum() { ret firstIntegerString(tlftj(functions)); }
|
72 | O blob() { ret loader.blob; }
|
73 | |
74 | O callBlobFunction(S fname, O... args) {
|
75 | if (canCallWithVarargs(module(), fname, args)) |
76 | ret callWithVarargs(module(), fname ,args); |
77 | else |
78 | ret callOpt(loader.blob, fname, args); |
79 | } |
80 | |
81 | LPairS userBotPairs() { ret chatConvo_userBotPairs(posts); }
|
82 | LS rawLines() { ret collect html(posts); }
|
83 | S firstLine() { ret getString html(first(posts)); }
|
84 | int numLines() { ret l(posts); }
|
85 | |
86 | void suggest(S s) { showSuggestions(ll(s)); }
|
87 | } |
Began life as a copy of #1026808
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1026824 |
| Snippet name: | Parrot 1.2 [with API] |
| Eternal ID of this version: | #1026824/16 |
| Text MD5: | 07874683d6681f8c3c3d654377c88043 |
| Transpilation MD5: | 559f691a0719d3fc177e7b5d0ad49bce |
| Author: | stefan |
| Category: | javax / stefan's os |
| Type: | JavaX source code (Dynamic Module) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-01-26 15:58:52 |
| Source code size: | 2616 bytes / 87 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 510 / 5491 |
| Version history: | 15 change(s) |
| Referenced in: | [show references] |