!752 // must be run together with sub-bot #1002677 (IRC Log Bot) static PersistentMap tagsByTS; p { tagsByTS = new PersistentMap("tagsByTS.log"); makeBot("Slack Tagger Bot!!"); } synchronized answer { /*if match "get tags for msg *" { S msgID = m.unq(0); L tags = tagsByTS.get(msgID); if (empty(tags)) ret "No tags for that msg"; else ret structure(tags); }*/ } static S html(S uri, Map params) { L keepFields = litlist("channel", "n"); //S channelName = formatChannelName(or(params.get("channel"), "##linux")); S channelName = "freenode"; // rather the network name... O slurper = getBot("#1002677"); L log = cast call(slurper, "getLog", channelName); boolean canEdit = master(); if (canEdit) for (S key : keys(params)) if (key.startsWith("tag_")) { S ts = dropPrefix("tag_", key); S val = params.get(key); tagsByTS.put(ts, val); } new L data; int n; if (!empty(params.get("n"))) n = parseInt(params.get("n")); else n = max(0, l(log)-1)/100*100; for (int i = n; i < min(n+100, l(log)); i++) { O o = log.get(i); S line = getString(o, "line"); O ts = get(o, "time"); if (ts == null || line == null) continue; ts = str(ts); int i1 = line.indexOf(' '); if (i1 < 0) continue; int i2 = line.indexOf(' ', i1+1); if (i2 < 0) continue; S code = line.substring(i1+1, i2); if (!eq(code, "PRIVMSG")) continue; S text = dropPrefix(":", dropUntilSpace(line.substring(i2+1))); S tag = tagsByTS.get(ts); // Pure text fields Map map = htmlencode(litmap( "Timestamp", ts, //"Line", get(o, "line"), "#", i+1 )); // Fields with actual HTML map.put("Text & Simplification", htmlencode(text) + "
" + htag("input", "", "type", "text", "name", "tag_" + ts, "value", or(tag, text), "style", "width: 100%")); /*if (mcBot != null) pcall { L mc = cast call(mcBot, "listMiniChat", "dc" + ts); new L miniChat; for (O _m : mc) { McMsg m = cast restructure(_m); miniChat.add(htmlencode(m.user + ": " + m.text)); } map.put("Mini-Chat", join("
", miniChat)); }*/ data.add(map); } new StringBuilder buf; S title = "Tagging " + 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))); if (canEdit) buf.append(htag("p","You are clear to edit.")); S formContents = ""; formContents += p(htag("input", "", "type", "submit", "value", "Submit!")); formContents += htmlTable(data, false); formContents += hiddenFields(params, keepFields); formContents += p(htag("input", "", "type", "submit", "value", "Submit!")); buf.append(htag("form", formContents, "method", "POST")); ret str(buf); }