!759 !include #1002412 // Turing static void tests() { pcall { questions(); } } static void questions() { // load from bot //L list = cast call(getBot("#1002462"), "getLiveList"); // load from file L list = unnull((L) loadForeignVariable("#1002462", "questions")); L vals = unnull((L) loadForeignVariable("#1002462", "vals")); vals = slackUsersOnly(vals); Map valsByID = indexByField(vals, "id"); prot("Found " + n(l(list), "question") + "."); // no shuffling for now, so latest questions show up top in "last dialogs" //list = shuffled(list); for (O tq : list) try { S id = getString(tq, "id"); S q = getString(tq, "question"); S a = getString(tq, "answer"); O _level = getOpt(tq, "level"); int level = (int) max(1, _level == null ? 1L : (long) _level); if (valsByID.containsKey(id)) prot("Skipping invalidated question: " + q + " => " + a); else add(q, a); } catch (Throwable e) { prot(str(e)); } } // TODO: .text static O loadForeignVariable(S progID, S varName) { S s = loadTextFile(getProgramFile(progID, varName + ".structure")); ret s == null ? null : unstructure(s); } static L slackUsersOnly(L vals) { // List comprehension syntax? // vals = [O val in vals where get(val, "user") != null]; new L l; for (O val : vals) if (get(get(val, "source"), "user") != null) l.add(val); ret l; }