# HG changeset patch # User Matthew Wild # Date 1262903128 0 # Node ID db6e92989c411cf239b4bd52cc187d7ddbcfac4b # Parent 8e157125957d11d4b8c8e1ff83bdbdded2c2d141 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom) diff -r 8e157125957d -r db6e92989c41 clix/bounce.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clix/bounce.lua Thu Jan 07 22:25:28 2010 +0000 @@ -0,0 +1,32 @@ +short_opts.h = "history"; + +return function (opts, arg) + 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