|
1 local verse = require "verse"; |
|
2 |
|
3 return function (opts, arg) |
|
4 if opts.short_help then |
|
5 print("Watches PEP notifications from all contacts") |
|
6 print("clix watch_pep [--node PEP-NODE] [--noempty]") |
|
7 return; |
|
8 end |
|
9 |
|
10 local function onconnect(conn) |
|
11 conn:hook_pep(opts.node or "urn:xmpp:microblog:0", function (event) |
|
12 local payload = event.item; |
|
13 if not payload then return 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 |
|
27 conn:send(verse.presence()); |
|
28 end |
|
29 end |
|
30 |
|
31 clix_connect(opts, onconnect, {"pep"}) |
|
32 end; |