Libraryless. Click here for Pure Java version (1970L/13K/42K).
!752 static S atEleuPrefix = "<@u0hb7bpkm>"; static int maxLen = 100; static PersistentMap<S, S> inToOut; static S last; p { inToOut = new PersistentMap("inToOut"); load("last"); } synchronized answer { if (neq(getChannel(), "devchannel, #talkingbots")) null; if (match("clear ua ub uc", s) && master()) { inToOut.clear(); ret getProgramID() + " cleared"; } s = s.trim(); boolean at = startsWithIgnoreCase(s, atEleuPrefix); if (at) s = dropPrefixIgnoreCase(atEleuPrefix, s); S in = simplifySentence2(s); saveIt(s, in, at); S out = inToOut.get(in); print("1002967: in=" + in + ", out=" + out); if (nempty(out)) { // TODO: bump in LRU ret out; } } static void saveIt(S s, S in, boolean at) { S lastOut = getLastOut(); if (nempty(lastOut)) saveEntry(lastOut, s); if (!at && nempty(last)) saveEntry(last, s); last = s; save("last"); } static void saveEntry(S in, S out) { if (l(in) > maxLen || l(out) > maxLen) ret; in = simplifySentence2(in); print(getProgramID() + " saving: " + in + " -> " + out); inToOut.put(in, out); } static S getLastOut() { ret (S) callOpt(getBot("#1002979"), "getLastAnswer"); }
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