clix/archive.lua

changeset 148
27a9f28724d3
parent 147
0bc82a318c45
child 159
68e09745d928
--- 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