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

64
LINES

< > BotCompany Repo | #1015629 // Suggestion Master - receives and displays suggestions [OK]

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  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015629
Snippet name: Suggestion Master - receives and displays suggestions [OK]
Eternal ID of this version: #1015629/27
Text MD5: e277ae502e1e5fca4d5558ac4fb60281
Transpilation MD5: 5ddb0c24012ed1b1970d5ebe9720f5cb
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:38:30
Source code size: 1748 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 488 / 1487
Version history: 26 change(s)
Referenced in: [show references]