1 local verse = require "verse"; |
1 local verse = require "verse"; |
2 |
2 |
3 return function (opts, arg) |
3 return function (opts, arg) |
4 if opts.short_help or not arg[1] then |
4 if opts.short_help or not arg[1] then |
5 print("Watches PEP notifications from all contacts") |
5 print("Watches PEP notifications from all contacts") |
6 print("clix watch_pep [--noempty] PEP-NODE") |
6 print("clix watch_pep [--noempty] PEP-NODE+") |
7 return; |
7 return; |
8 end |
8 end |
9 |
9 |
|
10 local function handle_notification(event) |
|
11 local payload = event.item; |
|
12 if not payload then return end |
|
13 if opts.noempty and not payload[1] then return end |
|
14 if event.from then |
|
15 io.stderr:write("# From "..event.from.."\n"); |
|
16 end |
|
17 if payload.attr.xmlns == "urn:xmpp:json:0" then |
|
18 print(payload:get_tex()) |
|
19 elseif opts.pretty then |
|
20 print(payload:indent(nil, " ")); |
|
21 else |
|
22 print(payload); |
|
23 end |
|
24 end |
|
25 |
10 local function onconnect(conn) |
26 local function onconnect(conn) |
11 conn:hook_pep(arg[1], function (event) |
27 for _, node in ipairs(arg) do |
12 local payload = event.item; |
28 conn:hook_pep(node, handle_notification); |
13 if not payload then return end |
29 end |
14 if opts.noempty and not payload[1] then return end |
|
15 if event.from then |
|
16 io.stderr:write("# From "..event.from.."\n"); |
|
17 end |
|
18 if payload.attr.xmlns == "urn:xmpp:json:0" then |
|
19 print(payload:get_tex()) |
|
20 elseif opts.pretty then |
|
21 print(payload:indent(nil, " ")); |
|
22 else |
|
23 print(payload); |
|
24 end |
|
25 end); |
|
26 if not opts.presence then |
30 if not opts.presence then |
27 conn:send(verse.presence()); |
31 conn:send(verse.presence()); |
28 end |
32 end |
29 end |
33 end |
30 |
34 |