Annotate

doc/example_carbons.lua @ 482:4c4f3dd62c54

squishy: Comment legacy protocol plugins by default
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Mar 2023 12:31:28 +0000
parent 287:762511350532
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local xmlns_carbons = "urn:xmpp:carbons:1";
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local xmlns_forward = "urn:xmpp:forward:0";
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
287
762511350532 doc/example_carbons.lua: Update to reflect timestamp change in carbons plugin.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
4 local function datetime(t) return os_date("!%Y-%m-%dT%H:%M:%SZ", t); end
762511350532 doc/example_carbons.lua: Update to reflect timestamp change in carbons plugin.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
5
226
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- This line squishes verse each time you run,
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- handy if you're hacking on Verse itself
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 --os.execute("squish --minify-level=none verse");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
260
7f6df45a3d1f doc/example*.lua: Update to use new .init() method
Matthew Wild <mwild1@gmail.com>
parents: 226
diff changeset
10 require "verse".init("client");
226
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 c = verse.new();--verse.logger());
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 c:add_plugin "carbons"
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 c:hook("disconnected", verse.quit);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local jid, password = unpack(arg);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 assert(jid and password, "You need to supply JID and password as arguments");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 c:connect_client(jid, password);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 -- Print a message after authentication
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 c:hook("authentication-success", function () c:debug("Logged in!"); end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 c:hook("authentication-failure", function (err)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 c:error("Failed to log in! Error: "..tostring(err.condition));
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 c:close();
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 c:hook("carbon", function(carbon)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local dir, ts, st = carbon.dir, carbon.timestamp, carbon.stanza;
287
762511350532 doc/example_carbons.lua: Update to reflect timestamp change in carbons plugin.
Kim Alvefur <zash@zash.se>
parents: 260
diff changeset
29 print("", datetime(ts), dir:upper());
226
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 print(st);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 -- Catch the "ready" event to know when the stream is ready to use
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 c:hook("ready", function ()
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 c:debug("Connected");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 c.carbons:enable(function(ok)
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 if ok then
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 c:debug("Carbons enabled")
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 else
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 c:error("Could not enable carbons, aborting");
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 c:close();
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end);
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
efd66bcc62c1 doc: Add Carbons example
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 verse.loop()