!752 // must be run together with sub-bot #1002185 (queries the // slack slurper's database) static class SlackMsg { S user, botName; // one of these is going to be set S userName; // looked up if user != null S type, text, ts; O reactions; S channelID; } static O mainBot; p { makeBot("Slack Answerer (about msgs)"); } synchronized answer { O slurper = getBot("#1002185"); if (match("what was the * msg in #*", s, m) || match("what was msg * in #*", s, m)) exceptionToUser { S what = m.unq(0); S channelName = "#" + m.unq(1); List log = cast call(slurper, "getLog", channelName); if (empty(log)) ret "The channel is empty or unslurped."; O e; try { int i = elementIndexFromNL(log, what); e = get(log, i); } catch (Throwable x) { ret exceptionToUser(x); } ret e == null ? "No msg found, sorry" : structure(e); // structure of msg } if "how many messages in *" exceptionToUser { S channelName = "#" + m.unq(0); List log = cast call(slurper, "getLog", channelName); ret lstr(log); } } static int elementIndexFromNL(L l, S s) { new Matches m; // matches stuff like "5" or "5th" or "52nd" S n = get(javaTok(s), 1); if (isInteger(n)) ret parseInt(n)-1; // matching on s if "first" ret 0; if "last" ret l(l)-1; if "second" ret 1; if "second to last" ret l(l)-2; throw fail("What is " + quote(s) + "?"); }