aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-02-23 19:52:57 +0100
committerKim Alvefur <zash@zash.se>2021-02-23 19:52:57 +0100
commit40252c2cc7e127eea7a87de095f75b84689d6b37 (patch)
tree702b4167998da597750f87c7fe614b276e784e53 /plugins
parent4ed5700a1910ee95897b0df3b2f1e5eaf0343b6e (diff)
downloadprosody-40252c2cc7e127eea7a87de095f75b84689d6b37.tar.gz
prosody-40252c2cc7e127eea7a87de095f75b84689d6b37.zip
mod_csi_simple: Add command to test importance algorithm on stream of stanzas
This won't include behavior provided by extra modules tho.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_csi_simple.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/mod_csi_simple.lua b/plugins/mod_csi_simple.lua
index 48aca5ff..e635909a 100644
--- a/plugins/mod_csi_simple.lua
+++ b/plugins/mod_csi_simple.lua
@@ -218,3 +218,35 @@ function module.unload()
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