# HG changeset patch # User Kim Alvefur # Date 1614106377 -3600 # Node ID 228bd43fbc3d818b6715cb27315b671d7804b6e3 # Parent 19a59cb7311e86b5e9e8935af6074e51d33eca6d mod_csi_simple: Add command to test importance algorithm on stream of stanzas This won't include behavior provided by extra modules tho. diff -r 19a59cb7311e -r 228bd43fbc3d plugins/mod_csi_simple.lua --- a/plugins/mod_csi_simple.lua Tue Feb 23 16:07:41 2021 +0100 +++ b/plugins/mod_csi_simple.lua Tue Feb 23 19:52:57 2021 +0100 @@ -218,3 +218,35 @@ end end end + +function module.command(arg) + if arg[1] ~= "test" then + print("Usage: "..module.name.." test < test-stream.xml") + print(""); + print("Provide a series of stanzas to test against importance algoritm"); + return 1; + end + -- luacheck: ignore 212/self + local xmppstream = require "util.xmppstream"; + local input_session = { notopen = true } + local stream_callbacks = { stream_ns = "jabber:client", default_ns = "jabber:client" }; + function stream_callbacks:handlestanza(stanza) + local important, because = is_important(stanza); + print("--"); + print(stanza:indent(nil, " ")); + -- :pretty_print() maybe? + if important then + print((because or "unspecified reason").. " -> important"); + else + print((because or "unspecified reason").. " -> unimportant"); + end + end + local input_stream = xmppstream.new(input_session, stream_callbacks); + input_stream:reset(); + input_stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag()); + input_session.notopen = nil; + + for line in io.lines() do + input_stream:feed(line); + end +end