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

62
LINES

< > BotCompany Repo | #1002442 // Bot with feedback (not implemented) - Finding the answer() function in bots (implemented)

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

Libraryless. Click here for Pure Java version (3076L/20K/65K).

1  
!752
2  
3  
static class Feedback {
4  
  long date;
5  
  int goodBadNotSure; // +1 (good) / -1 (bad) / 0 (not sure)
6  
  S user;
7  
  S comment;
8  
}
9  
10  
static class Action {
11  
  S input;
12  
  S output;
13  
  S algorithmMD5;
14  
  long date;
15  
  new L<Feedback> feedback;
16  
}
17  
18  
static new L<Action> actionLog;
19  
20  
p {
21  
  load("actionLog");
22  
}
23  
24  
synchronized answer {
25  
  if (match("parse answer function of *", s, m)
26  
    || match("show answer function of *", s, m)) try {
27  
    S botID = m.fsi(0);
28  
    O bot = getBot(botID);
29  
    S mainJava = getMainJava(bot);
30  
    L<S> tok = javaTok(mainJava);
31  
    int i = jfind(tok, "String answer(String");
32  
    if (i < 0)
33  
      ret "No answer function found...";
34  
    i = leftScanModifiers(tok, i);
35  
    int j = findBeginningOfBlock(tok, i);
36  
    j = findEndOfBlock(tok, j);
37  
    S func = join(tok.subList(i, j));
38  
    boolean fullParse = matchStart("parse", s);
39  
    S answer = func;
40  
    if (fullParse) {
41  
      L<S> lines = toLines(answer);
42  
      for (i = 0; i < l(lines); i++) {
43  
        S line = lines.get(i);
44  
        boolean ok = false;
45  
        pcall {
46  
          ok = jparse(line, "statement") != null;
47  
        }
48  
        lines.set(i, (ok ? "STA" : "???") + " " + line);
49  
      }
50  
      answer = fromLines(lines);
51  
    }
52  
    answer = slackSnippet(answer);
53  
    O parsed = null;
54  
    pcall {
55  
      parsed = jparse(func, "method");
56  
    }
57  
    answer = (parsed != null ? "parses." : "does not parse.") + "\n" + answer;
58  
    ret answer;
59  
  } catch (Throwable e) {
60  
    ret exceptionToUser(e);
61  
  }
62  
}

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: #1002442
Snippet name: Bot with feedback (not implemented) - Finding the answer() function in bots (implemented)
Eternal ID of this version: #1002442/1
Text MD5: a6b96937b31bb5bd3822a4b31bf4f91b
Transpilation MD5: 531ee6a6e7ddd7932ca8c7888f9a1090
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-23 19:31:20
Source code size: 1526 bytes / 62 lines
Pitched / IR pitched: No / No
Views / Downloads: 716 / 1337
Referenced in: [show references]