clix/bounce.lua

Mon, 16 Nov 2020 17:16:01 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 16 Nov 2020 17:16:01 +0100
changeset 142
05ec7103c0f7
parent 27
5b58c002d6ad
permissions
-rw-r--r--

clix.watch_pep: Include short names for some common PEP nodes

short_opts.h = "history";

return function (opts, arg)
	if opts.short_help then
		print("Bounce received messages to another JID");
		return;
	end
	local function on_connect(conn)
		-- Allow selective bouncing
		local only_node, only_server, only_resource;
		if opts.only_from then
			only_node, only_server, only_resource = jid.split(opts.only_from);
		end
		local function should_bounce(stanza)
			local node, server, resource = jid.split(stanza.attr.from);
			if only_node and (node ~= only_node)
				or only_server and (server ~= only_server)
				or only_resource and (resource ~= only_resource) then
				return false;
			end
			return true;
		end
		local function on_message(message)
			local delay = message:get_child("delay", "urn:xmpp:delay");
			if (delay and not opts.history) or not should_bounce(message) then
				return;
			end
			message.attr.from = nil;
			message.attr.to = opts.to;
			message.attr.type = opts.type or (opts.chatroom and "groupchat") or "chat";
			conn:send(message);
		end
		conn:hook("message", on_message);
	end
	return clix_connect(opts, on_connect);
end

mercurial