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

54
LINES

< > BotCompany Repo | #1002561 // Again Bot (LIVE)

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

Libraryless. Click here for Pure Java version (1850L/12K/40K).

1  
!752
2  
3  
// TODO: When in a dialog, this should be prioritized by dispatcher
4  
5  
static new Map<S, Status> statusMap; // key = dialog id
6  
7  
p {
8  
  load("statusMap");
9  
}
10  
11  
static abstract class Status {
12  
  abstract S answer(S s);
13  
}
14  
15  
static class AgainThis extends Status {
16  
  S q;
17  
  *() {}
18  
  *(S *q) {}
19  
  
20  
  S answer(S s) {
21  
    status(null); // always forget question after one line
22  
    
23  
    if (isYes(s)) exceptionToUser {
24  
      ret quote(q) + " >> " + askSelf(q);
25  
    } else if (isNo(s))
26  
      ret "OK";
27  
    null;
28  
  }
29  
}
30  
31  
static void status(Status s) {
32  
  if (s == null)
33  
    statusMap.remove(getDialogID());
34  
  else
35  
    statusMap.put(getDialogID(), s);
36  
  save("statusMap");
37  
}
38  
39  
answer {
40  
  if "again" {
41  
    Map last = last(getDialog());
42  
    if (last == null)
43  
      ret "Again what?";
44  
    else {
45  
      S q = getString(last, "question");
46  
      status(new AgainThis(q));
47  
      ret "Again this? >> " + q;
48  
    }
49  
  }
50  
  
51  
  Status status = statusMap.get(getDialogID());
52  
  if (status != null)
53  
    ret status.answer(s);
54  
}

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: #1002561
Snippet name: Again Bot (LIVE)
Eternal ID of this version: #1002561/1
Text MD5: 9b6dfb66da736203c5520192e6e52f2d
Transpilation MD5: d52d3e88c4b46e485819aca29721bfe5
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-03-03 03:09:41
Source code size: 1047 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 633 / 1089
Referenced in: [show references]