!752 static O parser; // 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 PersistentMap tagsByTS; static class Tag { S parseResult; } p { tagsByTS = new PersistentMap("tagsByTS.log"); } synchronized answer { if match "get analysis for msg *" { S msgID = m.unq(0); Tag tag = tagsByTS.get(msgID); if (tag == null) ret "No analysis for that msg"; else ret structure(tag); } } static synchronized S html(S uri, Map params) { L keepFields = litlist("channel", "n"); S channelName = formatChannelName(or(params.get("channel"), "talkingbots")); O slurper = call(getMainBot(), "getBot", "#1002185"); L log = cast call(slurper, "getLog", channelName); new L data; int n; if (!empty(params.get("n"))) n = parseInt(params.get("n")); else n = max(0, l(log)-1)/100*100; int n_end = min(n+100, l(log)); boolean analyze = !empty(params.get("analyze")); for (int i = n; i < n_end; i++) { O o = log.get(i); S ts = getString(o, "ts"); Tag tag = tagsByTS.get(ts); S text = cast get(o, "text"); if (analyze) { tag = new Tag; try { tag.parseResult = nlparse(text); } catch (Exception e) { tag.parseResult = exceptionToUser(e); } tagsByTS.put(ts, tag); } // make line and add to table Map map = htmlencode(litmap( "Timestamp", ts, "User", get(o, "userName"), "Text", text, "#", i+1, "Parse Result", tag == null ? "-" : tag.parseResult )); data.add(map); } new StringBuilder buf; S title = "Analyzing " + channelName; buf.append(htag("title", title)); buf.append(htag("h3", title)); // navigation new L l; for (int i = 0; i < l(log); i += 100) l.add(htag("a", str(i/100+1), "href", selfLink(params, keepFields, "n", str(i)))); buf.append(htag("p", "Pages: " + join("\n", l))); S formContents = htmlTable(data, false); formContents += htag("p", htag("input", "", "name", "analyze", "type", "submit", "value", "Re-analyze!")); formContents += hiddenFields(params, keepFields); buf.append(htag("form", formContents, "method", "POST")); ret str(buf); } static S nlparse(S text) { if (parser == null) { parser = hotwire_overBot("#1002369"); call(getBot("#1002372"), "fillNLParser", parser); } O result = call(parser, "parse", text); ret structure(call(result, "explainLongestMatch")); }