Libraryless. Click here for Pure Java version (2356L/16K/52K).
!759 static class PerUser { S dialogID; S name; } static new Map<S, PerUser> perUserMap; // key = dialogID static new ThreadLocal<PerUser> puCurrent; p { load("perUserMap"); makeBot("User Name Bot"); } synchronized answer { if (!attn ()) null; // init per-user stuff S dialogID = getDialogID(); if (dialogID == null) ret null; // need a dialog id to proceed PerUser pu = perUserMap.get(dialogID); if (pu == null) { pu = new PerUser; pu.dialogID = dialogID; printFormat("Created new dialog: *", dialogID); perUserMap.put(dialogID, pu); } puCurrent.set(pu); if (matchStart("my name is", s, m) || matchStart("i am", s, m) || matchStart("you can call me", s, m) || matchStart("call me", s, m) || matchStart("they call me", s, m) || matchStart("my friends call me", s, m)) { pu.name = unquote(m.rest().trim()); save("perUserMap"); ret "Hello " + pu.name + "!"; } if (match("who am i?", s) || match("eleu what's my name", s)) { if (nempty(pu.name)) ret "You are " + pu.name + "."; ret "I don't know, stranger. Who are you?"; } } static synchronized S getUserName() { PerUser pu = perUserMap.get(getDialogID()); ret pu == null ? null : pu.name; }
Began life as a copy of #1002211
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment