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

58
LINES

< > BotCompany Repo | #1002967 // UA UB UC (#talkingbots)

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

Libraryless. Click here for Pure Java version (1970L/13K/42K).

1  
!752
2  
3  
static S atEleuPrefix = "<@u0hb7bpkm>";
4  
static int maxLen = 100;
5  
6  
static PersistentMap<S, S> inToOut;
7  
static S last;
8  
9  
p {
10  
  inToOut = new PersistentMap("inToOut");
11  
  load("last");
12  
}
13  
14  
synchronized answer {
15  
  if (neq(getChannel(), "devchannel, #talkingbots")) null;
16  
  
17  
  if (match("clear ua ub uc", s) && master()) {
18  
    inToOut.clear();
19  
    ret getProgramID() + " cleared";
20  
  }
21  
  
22  
  s = s.trim();
23  
  boolean at = startsWithIgnoreCase(s, atEleuPrefix);
24  
  if (at)
25  
    s = dropPrefixIgnoreCase(atEleuPrefix, s);
26  
27  
  S in = simplifySentence2(s);
28  
  
29  
  saveIt(s, in, at);
30  
  
31  
  S out = inToOut.get(in);
32  
  print("1002967: in=" + in + ", out=" + out);
33  
  if (nempty(out)) {
34  
    // TODO: bump in LRU
35  
    ret out;
36  
  }
37  
}
38  
39  
static void saveIt(S s, S in, boolean at) {
40  
  S lastOut = getLastOut();
41  
  if (nempty(lastOut))
42  
    saveEntry(lastOut, s);
43  
  if (!at && nempty(last))
44  
    saveEntry(last, s);
45  
  last = s;
46  
  save("last");
47  
}
48  
49  
static void saveEntry(S in, S out) {
50  
  if (l(in) > maxLen || l(out) > maxLen) ret;
51  
  in = simplifySentence2(in);
52  
  print(getProgramID() + " saving: " + in + " -> " + out);
53  
  inToOut.put(in, out);
54  
}
55  
56  
static S getLastOut() {
57  
  ret (S) callOpt(getBot("#1002979"), "getLastAnswer");
58  
}

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: #1002967
Snippet name: UA UB UC (#talkingbots)
Eternal ID of this version: #1002967/1
Text MD5: 60b220e9d43cee5aedeb08d76c25874a
Transpilation MD5: e99699e9b1bc28946ac2c7664ad75ca6
Author: stefan
Category: nl bots
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-15 23:07:14
Source code size: 1255 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 734 / 827
Referenced in: [show references]