| 1 | local verse = require "verse"; |
| 2 | |
| 3 | local well_known = { |
| 4 | geoloc = "http://jabber.org/protocol/geoloc"; -- XEP-0080 |
| 5 | avatar = "urn:xmpp:avatar:metadata"; -- XEP-0084 |
| 6 | mood = "http://jabber.org/protocol/mood"; -- XEP-0107 |
| 7 | activity = "http://jabber.org/protocol/activity"; -- XEP-0108 |
| 8 | tune = "http://jabber.org/protocol/tune"; -- XEP-0118 |
| 9 | nick = "http://jabber.org/protocol/nick"; -- XEP-0172 |
| 10 | chatting = "urn:xmpp:chatting:0"; -- XEP-0194 |
| 11 | browsing = "urn:xmpp:browsing:0"; -- XEP-0195 |
| 12 | gaming = "urn:xmpp:gaming:0"; -- XEP-0196 |
| 13 | viewing = "urn:xmpp:viewing:0"; -- XEP-0197 |
| 14 | vcard4 = "urn:xmpp:vcard4"; -- XEP-0292 |
| 15 | }; |
| 16 | |
| 17 | return function (opts, arg) |
| 18 | if opts.short_help then |
| 19 | print("Watches PEP notifications from all contacts") |
| 20 | return; |
| 21 | end |
| 22 | if opts.help or not arg[1] then |
| 23 | print("clix watch_pep [--noempty] PEP-NODE+") |
| 24 | return; |
| 25 | end |
| 26 | |
| 27 | local function handle_notification(event) |
| 28 | local payload = event.item; |
| 29 | if not payload then return end |
| 30 | if opts.noempty and not payload[1] then return end |
| 31 | if event.from then |
| 32 | io.stderr:write("# From "..event.from.."\n"); |
| 33 | end |
| 34 | if payload.attr.xmlns == "urn:xmpp:json:0" then |
| 35 | print(payload:get_tex()) |
| 36 | elseif opts.pretty then |
| 37 | if payload.indent then |
| 38 | print(payload:indent(nil, " "):pretty_print()); |
| 39 | else |
| 40 | print(payload:pretty_print()); |
| 41 | end |
| 42 | else |
| 43 | print(payload); |
| 44 | end |
| 45 | end |
| 46 | |
| 47 | local function onconnect(conn) |
| 48 | for _, node in ipairs(arg) do |
| 49 | conn:hook_pep(well_known[node] or node, handle_notification); |
| 50 | end |
| 51 | if not opts.presence then |
| 52 | conn:send(verse.presence()); |
| 53 | end |
| 54 | end |
| 55 | |
| 56 | clix_connect(opts, onconnect, {"pep"}) |
| 57 | end; |