!7 cmodule StatementFulfillments > DynObjectTable { transient ReliableSingleThread rstSearch = dm_rst(this, r search); transient Flag cancel; start { set fieldsInOrder; dm_vmBus_onMessage_q('newDiscordLine, voidfunc(O line) { new L list; scanLines(ll(dm_discord_importLine(line)), list, 100, null); addAll(list); }); dm_vmBus_onMessage('gazelleRuleCreated, rstSearch); // TODO: optimize } visualize { ret withCenteredButtons(super.visualize(), "Search Chat", rstSearch); } void search { new Flag cancel; this.cancel = cancel; new L list; // "john doe is a guy" L lines = dm_discord_allLines(); print("Scanning " + n2(lines, "line")); scanLines(lines, list, 1000, cancel); print("Scan yielded " + n2(list, "entry", "entries")); setList(list); } void scanLines(L lines, L list_out, int maxEntries, Flag cancel) { GazelleEvalContext ctx = dm_gazelle_stdEvalContext(dm_gazelle_rulesOnFacts()); for (GazelleLine line : lines) pcall { for (GazelleTree t : gazelle_getChildren(GazelleTree(ctx, line.text))) pcall { if (flagIsUp(cancel) || l(list_out) >= maxEntries) ret with print("Cancel"); list_out.add(nu GazelleFulfillment( line := t.parent.line, varMap := struct(t.varMap()), rule := t.ruleID(), matchedRuleStruct := struct(t.mr), context := "discord msg " + line.msgID)); } } } // API L entriesForRule(S ruleID) { ret filterWhere(list(), rule := ruleID); } }