clix/watch_pep.lua

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

author
Kim Alvefur <zash@zash.se>
date
Mon, 16 Nov 2020 17:17:54 +0100
changeset 143
6b1fc3238318
parent 142
05ec7103c0f7
child 144
febc3992bee6
permissions
-rw-r--r--

clix.watch_pep: Use colors with --pretty

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)
140
8815232cbbeb clix.watch_pep: Take PEP node as positional argument
Kim Alvefur <zash@zash.se>
parents: 139
diff changeset
18 if opts.short_help or not arg[1] 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")
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
20 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
21 return;
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 end
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
24 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
25 local payload = event.item;
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
26 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
27 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
28 if event.from then
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
29 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
30 end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
31 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
32 print(payload:get_tex())
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
33 elseif opts.pretty then
143
6b1fc3238318 clix.watch_pep: Use colors with --pretty
Kim Alvefur <zash@zash.se>
parents: 142
diff changeset
34 print(payload:indent(nil, " "):pretty_print());
141
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
35 else
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
36 print(payload);
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
37 end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
38 end
93eda3dd85f7 clix.watch_pep: Allow watching more than one PEP node
Kim Alvefur <zash@zash.se>
parents: 140
diff changeset
39
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 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
41 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
42 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
43 end
139
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 if not opts.presence then
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 conn:send(verse.presence());
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 end
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 clix_connect(opts, onconnect, {"pep"})
6909e479c56b clix.watch_pep: Subscribe to a PEP node
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 end;

mercurial