Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1015659 // Suggestion Master v1 [single suggestion]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 4281K of libraries. Click here for Pure Java version (13774L/101K).

1  
!7
2  
3  
!include #1001372 // direct nohupJavax for fast program starting
4  
5  
// useful stuff to avoid transpilation
6  
please include function rpcNoArgs.
7  
8  
concept Suggestion {
9  
  S globalID = aGlobalID();
10  
  long date;
11  
  S text;
12  
  S author;
13  
  S actionCode;
14  
}
15  
16  
static Suggestion showing;
17  
static ReliableSingleThread rstUpdate = new(f updateImpl);
18  
static PastValueKeeper<Suggestion> past = new(3600.0);
19  
20  
p-subst {
21  
  defaultFrameTitle("Suggestion");
22  
  autoRestart();
23  
  db();
24  
  botWithInput("Suggestion Master.",
25  
    [=[ me suggests hello with action [[infoBox("hello")]] ]=]);
26  
}
27  
28  
answer {
29  
  if "* suggests * with action *" {
30  
    Suggestion sugg = cnew(Suggestion, date := now(), text := $2, author := $1, actionCode := $3);
31  
    rstUpdate!;
32  
    ret "OK, ID: " + sugg.globalID;
33  
  }
34  
  if "show last suggestion" { ret showLastSuggestion(); }
35  
}
36  
37  
svoid updateImpl {
38  
  final Suggestion s = highestByField(list(Suggestion), 'date);
39  
  if (s != showing) {
40  
    showing = s;
41  
    print("Showing suggestion: " + s.text);
42  
    logQuotedWithDate(javaxDataDir("suggestions.log"), "Showing: " + struct(s));
43  
    past.add(s);
44  
    showSuggestion_master(s.text, r {
45  
      printIndent(s.actionCode);
46  
      logQuotedWithDate(javaxDataDir("suggestions.log"), "Running: " + struct(s));
47  
      optimizedJavaEval(s.actionCode);
48  
    });
49  
  }
50  
}
51  
52  
sS showLastSuggestion() {
53  
  double lookback = 1.0;
54  
  print('showLastSuggestion);
55  
  Suggestion s = past.valueAt_orFirst(toMS(lookback));
56  
  if (s != null) {
57  
    Suggestion sugg = cnew(Suggestion, date := now());
58  
    ccopyFields(s, sugg, 'text, 'author, 'actionCode);
59  
    cset(sugg, copiedFrom := s.globalID);
60  
    rstUpdate!;
61  
    ret "OK, ID: " + sugg.globalID;
62  
  }
63  
  ret "Nothing there";
64  
}

Author comment

Began life as a copy of #1015629

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga

No comments. add comment

Snippet ID: #1015659
Snippet name: Suggestion Master v1 [single suggestion]
Eternal ID of this version: #1015659/1
Text MD5: e277ae502e1e5fca4d5558ac4fb60281
Transpilation MD5: 4fbcb97edf3ac3ae7c515dbbffdd9e64
Author: stefan
Category: javax / a.i. / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-20 19:35:24
Source code size: 1748 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 442 / 1009
Referenced in: [show references]