# HG changeset patch # User Kim Alvefur # Date 1364844599 -7200 # Node ID 67ff8f55db4a483c3ecc848e7757c5c6a95aa8ab # Parent c33848e79bfc627b46a8658457219c2a54793be7# Parent 956242b7d5dfe9f099304b9a7121662d8d204c5e Merge with MattJ diff -r c33848e79bfc -r 67ff8f55db4a clix/presence.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clix/presence.lua Mon Apr 01 21:29:59 2013 +0200 @@ -0,0 +1,65 @@ +local presence_values = { online = "1", chat = "2", away = "3", xa = "4", dnd = "5", offline = "6" }; + +return function (opts) + if opts.short_help then + print("Display Presence Status"); + return; + end + local DELIM = opts.delim or "\t"; + local function on_presence(presence) + local pres_num = presence_values.offline; + local pres_str; + if presence.attr.type then + if presence.attr.type == "unavailable" then + pres_str = "show=" .. presence.attr.type .. DELIM .. DELIM; + else + return; -- Ignore all other presence type's + end + else + local show = presence:get_child("show"); + local priority = presence:get_child("priority"); + local status = presence:get_child("status"); + local show_str = show and show:get_text():lower() or "online"; + pres_str = "show=" .. show_str; + pres_num = presence_values[show_str] or pres_num; + if priority then + pres_str = pres_str .. DELIM .. "priority=" .. priority:get_text(); + else + pres_str = pres_str .. DELIM; + end + if status then + local status_str = status:get_text(); + -- sanitize status string + status_str = status_str:gsub("\n", " "):gsub("[\r"..DELIM.."]", ""); + pres_str = pres_str .. DELIM .. "status=" .. status_str; + else + pres_str = pres_str .. DELIM; + end + end + if presence.attr.from then + if opts.to then + if opts.to:find("/", 1, true) and opts.to ~= presence.attr.from then + return; -- Ignore non-exact match when --to= is defined with a resource + elseif opts.to ~= presence.attr.from:sub(1, #opts.to) then + return; -- Ignore non-matching JID when --to= is defined without a resource + end + end + pres_str = pres_str .. DELIM .. "from=" .. presence.attr.from; + else + pres_str = pres_str .. DELIM; + end + pres_str = pres_num .. DELIM .. pres_str .. DELIM; + print(pres_str); + end + local function on_connect(conn) + conn:hook("presence", on_presence); + if opts.to then + conn:send(verse.presence{to=opts.to, type="probe"}); + end + if not tonumber(opts.close_delay) then + opts.close_delay = 1; + end + conn:close(); + end + clix_connect(opts, on_connect); +end diff -r c33848e79bfc -r 67ff8f55db4a squishy --- a/squishy Fri Feb 15 20:46:10 2013 +0100 +++ b/squishy Mon Apr 01 21:29:59 2013 +0200 @@ -12,6 +12,7 @@ "publish_atom"; "sendfile"; "archive"; + "presence"; } for _, cmd in ipairs(commands) do