clix.archive: Add 'irc' output format, useful for MUC export default tip

Mon, 08 Feb 2021 22:59:49 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 08 Feb 2021 22:59:49 +0100
changeset 148
27a9f28724d3
parent 147
0bc82a318c45

clix.archive: Add 'irc' output format, useful for MUC export

clix/archive.lua file | annotate | diff | comparison | revisions
--- a/clix/archive.lua	Mon Feb 08 22:57:42 2021 +0100
+++ b/clix/archive.lua	Mon Feb 08 22:59:49 2021 +0100
@@ -1,3 +1,4 @@
+local jid_split = require"util.jid".split;
 local bare_jid = require"util.jid".bare;
 local parse_datetime = require"util.datetime".parse;
 return function (opts, arg)
@@ -39,6 +40,24 @@
 			:tag("delay", {xmlns="urn:xmpp:delay", stamp=datetime(i.stamp)}):up()
 			:add_child(i.message));
 		end
+	elseif opts.format == "irc" then
+		local date;
+		local os_date = os.date;
+		function print_message(i)
+			local m = i.message;
+			local body = m:get_child_text("body");
+			local a = m.attr;
+			local _, _, nick = jid_split(a.from);
+
+			local curdate = os_date("%F", i.stamp);
+			if date ~= curdate then
+				print("-!- "..curdate);
+				date = curdate;
+			end
+			if nick and body then
+				print(("%s <%s> %s"):format(os_date("%T", i.stamp), nick, body));
+			end
+		end
 	end
 
 	local function on_connect(conn)

mercurial