!7 static Env env; static new ThreadLocal session; static ThreadLocal> buttons = new ThreadLocal; static Map spellMap; static interface Env { void sayAsync(S session, S msg); } concept Session { S cookie; S lastQuestion; } sbool debug; svoid setSession(S cookie) { session.set(uniq_sync(Session, +cookie)); } svoid clearSession(S cookie) { deleteConcepts(Session, +cookie); } p { db(); // load stuff spellMap = loadSpellList(#1008389); //printStruct(spellMap); veryBigConsole(); bot(); } sS returnQuestion(S q) { cset(session!, lastQuestion := q); ret q; } sS answer(S s) { if (session! == null) setSession("default"); buttons.set(null); if (creator() == null) if "debug" set debug; S lq = session->lastQuestion; cset(session!, lastQuestion := null); if (eq(lq, "Would you like some tea?")) { if "yes" ret "Here's your tea."; if "no" ret "Very well then."; } if "test buttons" { buttons.set(ll("Yes", "No")); ret returnQuestion("Would you like some tea?"); } if "say something later" { if (env == null) ret("No env"); final S mySession = session->cookie; thread { sleepSeconds(5); env.sayAsync(mySession, "Here it is."); } ret "OK, will do it in 5 seconds"; } S _s = s; s = levenAttract(spellMap, s); if (neqic(s, _s)) print("Spell-correct => " + s); ret "Sorry, I didn't understand that"; } sS initialMessage() { ret "Your personal bot here. " + returnQuestion("How can I help you?"); }