!752 sclass Tag { S name; } sclass 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; int index; new TreeSet tags; } static PersistentMap> tagMap; static PersistentLog msgs; static new L taggedMsgs; static new TreeMap msgsByIndex; static new MultiMap msgsByTag; p { tagMap = new PersistentMap("#1002192", "tagsByTS.log"); print("Tags: " + l(tagMap)); S channelName = "talkingbots"; msgs = new PersistentLog("#1002185", parseChannelName(channelName) + ".msgs"); print("Msgs: " + l(msgs)); if (empty(tagMap) || empty(msgs)) fail("no data"); //printStructure(last(msgs)); // put tags and index in messages int n = 1; for (SlackMsg msg : msgs) { L tags = tagMap.get(msg.ts); /*if (nempty(tags)) print(structure(tags) + " " + structure(msg));*/ msg.index = n++; msgsByIndex.put(msg.index, msg); for (Tag t : unnull(tags)) { if (msg.tags.add(t.name)) msgsByTag.put(t.name, msg); } if (nempty(msg.tags)) taggedMsgs.add(msg); } print(l(taggedMsgs) + " tagged msgs."); for (SlackMsg msg : taggedMsgs) { for (S tag : msg.tags) { if (tag.startsWith("@") && isInteger(tag.substring(1))) pcall { int i = parseInt(tag.substring(1)); if (i < 0) i += msg.index; SlackMsg m2 = msgsByIndex.get(i); S t2 = m2 == null ? "NOT FOUND" : m2.userName + ": " + m2.text; S t1 = msg.userName + ": " + msg.text; //print(msg.text + " => " + (m2 == null ? "NOT FOUND" : m2.text)); print(t2); print(" " + t1); print(); } } } print("Bot greetings: " + structure(collect(msgsByTag.get("bot greeting"), "text"))); }