clix/bounce.lua

Sun, 15 Nov 2020 20:45:50 +0100

author
Kim Alvefur <zash@zash.se>
date
Sun, 15 Nov 2020 20:45:50 +0100
changeset 140
8815232cbbeb
parent 27
5b58c002d6ad
permissions
-rw-r--r--

clix.watch_pep: Take PEP node as positional argument

Thanks MattJ

25
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 short_opts.h = "history";
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 return function (opts, arg)
27
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
4 if opts.short_help then
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
5 print("Bounce received messages to another JID");
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
6 return;
5b58c002d6ad clix.*: Add --short-help and make sure they are working correctly
Matthew Wild <mwild1@gmail.com>
parents: 25
diff changeset
7 end
25
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local function on_connect(conn)
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 -- Allow selective bouncing
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local only_node, only_server, only_resource;
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 if opts.only_from then
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 only_node, only_server, only_resource = jid.split(opts.only_from);
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local function should_bounce(stanza)
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local node, server, resource = jid.split(stanza.attr.from);
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 if only_node and (node ~= only_node)
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 or only_server and (server ~= only_server)
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 or only_resource and (resource ~= only_resource) then
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 return false;
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 return true;
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local function on_message(message)
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local delay = message:get_child("delay", "urn:xmpp:delay");
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 if (delay and not opts.history) or not should_bounce(message) then
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 return;
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 end
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 message.attr.from = nil;
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 message.attr.to = opts.to;
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 message.attr.type = opts.type or (opts.chatroom and "groupchat") or "chat";
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 conn:send(message);
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 conn:hook("message", on_message);
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 return clix_connect(opts, on_connect);
db6e92989c41 clix.bounce: Bounce stanzas from all or certain JIDs to another JID (which may be a chatroom)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end

mercurial