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

54
LINES

< > BotCompany Repo | #1002463 // Turing Tests: Dynamic Questions (added by #1002462)

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

Libraryless. Click here for Pure Java version (2197L/15K/48K).

1  
!759
2  
3  
!include #1002412 // Turing
4  
5  
static void tests() {
6  
  pcall { questions(); }
7  
}
8  
9  
static void questions() {
10  
  // load from bot
11  
  //L list = cast call(getBot("#1002462"), "getLiveList");
12  
  
13  
  // load from file
14  
  L list = unnull((L) loadForeignVariable("#1002462", "questions"));
15  
  L vals = unnull((L) loadForeignVariable("#1002462", "vals"));
16  
  
17  
  vals = slackUsersOnly(vals);
18  
  Map<S, O> valsByID = indexByField(vals, "id");
19  
  
20  
  prot("Found " + n(l(list), "question") + ".");
21  
  
22  
  // no shuffling for now, so latest questions show up top in "last dialogs"
23  
  
24  
  //list = shuffled(list);
25  
  
26  
  for (O tq : list) try {
27  
    S id = getString(tq, "id");
28  
    S q = getString(tq, "question");
29  
    S a = getString(tq, "answer");
30  
    O _level = getOpt(tq, "level");
31  
    int level = (int) max(1, _level == null ? 1L : (long) _level);
32  
    if (valsByID.containsKey(id))
33  
      prot("Skipping invalidated question: " + q + " => " + a);
34  
    else
35  
      add(q, a);
36  
  } catch (Throwable e) {
37  
    prot(str(e));
38  
  }
39  
}
40  
41  
// TODO: .text
42  
static O loadForeignVariable(S progID, S varName) {
43  
  S s = loadTextFile(getProgramFile(progID, varName + ".structure"));
44  
  ret s == null ? null : unstructure(s);
45  
}
46  
47  
static L slackUsersOnly(L vals) {
48  
  // List comprehension syntax?
49  
  // vals = [O val in vals where get(val, "user") != null];
50  
  
51  
  new L l;
52  
  for (O val : vals) if (get(get(val, "source"), "user") != null) l.add(val);
53  
  ret l;
54  
}

Author comment

Began life as a copy of #1002413

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: #1002463
Snippet name: Turing Tests: Dynamic Questions (added by #1002462)
Eternal ID of this version: #1002463/1
Text MD5: 9fe797434af02c37e254cb81de214c47
Transpilation MD5: e3eefab9ed541861a5fc4b909a4f869d
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-02 23:35:10
Source code size: 1463 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 799 / 2197
Referenced in: [show references]