clix/watch_pep.lua

Mon, 16 Nov 2020 17:15:38 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 16 Nov 2020 17:15:38 +0100
changeset 141
93eda3dd85f7
parent 140
8815232cbbeb
child 142
05ec7103c0f7
permissions
-rw-r--r--

clix.watch_pep: Allow watching more than one PEP node

local verse = require "verse";

return function (opts, arg)
	if opts.short_help or not arg[1] then
		print("Watches PEP notifications from all contacts")
		print("clix watch_pep [--noempty] PEP-NODE+")
		return;
	end

	local function handle_notification(event)
		local payload = event.item;
		if not payload then return end
		if opts.noempty and not payload[1] then return end
		if event.from then
			io.stderr:write("# From "..event.from.."\n");
		end
		if payload.attr.xmlns == "urn:xmpp:json:0" then
			print(payload:get_tex())
		elseif opts.pretty then
			print(payload:indent(nil, "  "));
		else
			print(payload);
		end
	end

	local function onconnect(conn)
		for _, node in ipairs(arg) do
			conn:hook_pep(node, handle_notification);
		end
		if not opts.presence then
			conn:send(verse.presence());
		end
	end

	clix_connect(opts, onconnect, {"pep"})
end;

mercurial