Annotate

doc/example_adhoc.lua @ 131:1c30dd51ca6b

squishy: Add util.hashes [libs/hashes.lua]
author Matthew Wild <mwild1@gmail.com>
date Mon, 13 Sep 2010 14:48:10 +0100
parent 117:f523516196ce
child 260:7f6df45a3d1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
117
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Change these:
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local jid, password = "user@example.com", "secret";
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 -- This line squishes verse each time you run,
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- handy if you're hacking on Verse itself
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 --os.execute("squish --minify-level=none");
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 require "verse" -- Verse main library
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 require "verse.client" -- XMPP client library
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 c = verse.new(verse.logger());
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 c:add_plugin("version");
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 c:add_plugin("disco");
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 c:add_plugin("adhoc");
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 -- Add some hooks for debugging
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 c:hook("opened", function () print("Stream opened!") end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 c:hook("closed", function () print("Stream closed!") end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 c:hook("stanza", function (stanza) print("Stanza:", stanza) end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 -- This one prints all received data
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 c:hook("incoming-raw", print, 1000);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 -- Print a message after authentication
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 c:hook("authentication-success", function () print("Logged in!"); end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 c:hook("authentication-failure", function (err) print("Failed to log in! Error: "..tostring(err.condition)); end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 -- Print a message and exit when disconnected
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 -- Now, actually start the connection:
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 c:connect_client(jid, password);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 -- Catch the "ready" event to know when the stream is ready to use
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 c:hook("ready", function ()
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 print("Stream ready!");
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 c.version:set{ name = "verse example client" };
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local function random_handler()
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 return { info = tostring(math.random(1,100)), status = "completed" };
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 c:add_adhoc_command("Get random number", "random", random_handler);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 c:send(verse.presence():add_child(c:caps()));
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end);
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 print("Starting loop...")
f523516196ce doc/example_adhoc.lua: Example of using ad-hoc commands
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 verse.loop()