clix/watch_pep.lua

Mon, 23 Nov 2020 23:52:31 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 23 Nov 2020 23:52:31 +0100
changeset 145
6e05b25c2669
parent 144
febc3992bee6
permissions
-rw-r--r--

clix.watch_pep: Move invocation syntax out of short help

So it doesn't clutter the command listing

139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local verse = require "verse";
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
142
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
3 local well_known = {
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
4 geoloc = "http://jabber.org/protocol/geoloc"; -- XEP-0080
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
5 avatar = "urn:xmpp:avatar:metadata"; -- XEP-0084
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
6 mood = "http://jabber.org/protocol/mood"; -- XEP-0107
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
7 activity = "http://jabber.org/protocol/activity"; -- XEP-0108
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
8 tune = "http://jabber.org/protocol/tune"; -- XEP-0118
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
9 nick = "http://jabber.org/protocol/nick"; -- XEP-0172
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
10 chatting = "urn:xmpp:chatting:0"; -- XEP-0194
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
11 browsing = "urn:xmpp:browsing:0"; -- XEP-0195
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
12 gaming = "urn:xmpp:gaming:0"; -- XEP-0196
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
13 viewing = "urn:xmpp:viewing:0"; -- XEP-0197
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
14 vcard4 = "urn:xmpp:vcard4"; -- XEP-0292
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
15 };
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
16
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 return function (opts, arg)
145
6e05b25c2669 clix.watch_pep: Move invocation syntax out of short help
Kim Alvefur <zash@zash.se>
parents: 144
diff changeset
18 if opts.short_help then
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 print("Watches PEP notifications from all contacts")
145
6e05b25c2669 clix.watch_pep: Move invocation syntax out of short help
Kim Alvefur <zash@zash.se>
parents: 144
diff changeset
20 return;
6e05b25c2669 clix.watch_pep: Move invocation syntax out of short help
Kim Alvefur <zash@zash.se>
parents: 144
diff changeset
21 end
6e05b25c2669 clix.watch_pep: Move invocation syntax out of short help
Kim Alvefur <zash@zash.se>
parents: 144
diff changeset
22 if opts.help or not arg[1] then
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
23 print("clix watch_pep [--noempty] PEP-NODE+")
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 return;
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
27 local function handle_notification(event)
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
28 local payload = event.item;
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
29 if not payload then return end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
30 if opts.noempty and not payload[1] then return end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
31 if event.from then
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
32 io.stderr:write("# From "..event.from.."\n");
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
33 end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
34 if payload.attr.xmlns == "urn:xmpp:json:0" then
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
35 print(payload:get_tex())
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
36 elseif opts.pretty then
144
febc3992bee6 clix.watch_pep: Handle being built without stanza indentation support
Kim Alvefur <zash@zash.se>
parents: 143
diff changeset
37 if payload.indent then
febc3992bee6 clix.watch_pep: Handle being built without stanza indentation support
Kim Alvefur <zash@zash.se>
parents: 143
diff changeset
38 print(payload:indent(nil, " "):pretty_print());
febc3992bee6 clix.watch_pep: Handle being built without stanza indentation support
Kim Alvefur <zash@zash.se>
parents: 143
diff changeset
39 else
febc3992bee6 clix.watch_pep: Handle being built without stanza indentation support
Kim Alvefur <zash@zash.se>
parents: 143
diff changeset
40 print(payload:pretty_print());
febc3992bee6 clix.watch_pep: Handle being built without stanza indentation support
Kim Alvefur <zash@zash.se>
parents: 143
diff changeset
41 end
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
42 else
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
43 print(payload);
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
44 end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
45 end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
46
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 local function onconnect(conn)
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
48 for _, node in ipairs(arg) do
142
05ec7103c0f7 clix.watch_pep: Include short names for some common PEP nodes
Kim Alvefur <zash@zash.se>
parents: 141
diff changeset
49 conn:hook_pep(well_known[node] or node, handle_notification);
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
50 end
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 if not opts.presence then
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 conn:send(verse.presence());
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 end
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 clix_connect(opts, onconnect, {"pep"})
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 end;

mercurial