clix/presence.lua

Sun, 15 Nov 2020 20:45:50 +0100

author
Kim Alvefur <zash@zash.se>
date
Sun, 15 Nov 2020 20:45:50 +0100
changeset 140
8815232cbbeb
parent 101
956242b7d5df
child 164
fafdcde2e2eb
permissions
-rw-r--r--

clix.watch_pep: Take PEP node as positional argument

Thanks MattJ

99
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local presence_values = { online = "1", chat = "2", away = "3", xa = "4", dnd = "5", offline = "6" };
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 return function (opts)
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 if opts.short_help then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 print("Display Presence Status");
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 return;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local DELIM = opts.delim or "\t";
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local function on_presence(presence)
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local pres_num = presence_values.offline;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local pres_str;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 if presence.attr.type then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 if presence.attr.type == "unavailable" then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 pres_str = "show=" .. presence.attr.type .. DELIM .. DELIM;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 else
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 return; -- Ignore all other presence type's
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 else
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local show = presence:get_child("show");
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local priority = presence:get_child("priority");
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local status = presence:get_child("status");
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local show_str = show and show:get_text():lower() or "online";
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 pres_str = "show=" .. show_str;
101
956242b7d5df clix/presence: Handle invalid <show> values (thanks Lonnie Abelbeck)
Matthew Wild <mwild1@gmail.com>
parents: 99
diff changeset
24 pres_num = presence_values[show_str] or pres_num;
99
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 if priority then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 pres_str = pres_str .. DELIM .. "priority=" .. priority:get_text();
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 else
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 pres_str = pres_str .. DELIM;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 if status then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local status_str = status:get_text();
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 -- sanitize status string
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 status_str = status_str:gsub("\n", " "):gsub("[\r"..DELIM.."]", "");
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 pres_str = pres_str .. DELIM .. "status=" .. status_str;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 else
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 pres_str = pres_str .. DELIM;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 if presence.attr.from then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 if opts.to then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 if opts.to:find("/", 1, true) and opts.to ~= presence.attr.from then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 return; -- Ignore non-exact match when --to= is defined with a resource
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 elseif opts.to ~= presence.attr.from:sub(1, #opts.to) then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 return; -- Ignore non-matching JID when --to= is defined without a resource
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 pres_str = pres_str .. DELIM .. "from=" .. presence.attr.from;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 else
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 pres_str = pres_str .. DELIM;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 pres_str = pres_num .. DELIM .. pres_str .. DELIM;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 print(pres_str);
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 local function on_connect(conn)
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 conn:hook("presence", on_presence);
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 if opts.to then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 conn:send(verse.presence{to=opts.to, type="probe"});
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 if not tonumber(opts.close_delay) then
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 opts.close_delay = 1;
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 conn:close();
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 end
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 clix_connect(opts, on_connect);
c51402a40e41 Add clix/presence.lua: list the presence of your contacts (or probe one with --to). Contributed by Lonnie Abelbeck
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 end

mercurial