Software /
code /
verse
Annotate
doc/example_pep.lua @ 162:2950079d4319
verse: Consider a plugin as failed to load only if it returns false
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 15 Dec 2010 11:57:23 +0000 |
parent | 128:720b9ccd7ea4 |
child | 168:7285e04a4797 |
rev | line source |
---|---|
128
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Change these: |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid, password = "user@example.com", "secret"; |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- This line squishes verse each time you run, |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- handy if you're hacking on Verse itself |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 --os.execute("squish --minify-level=none"); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 require "verse" -- Verse main library |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 require "verse.client" -- XMPP client library |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 c = verse.new(); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 c:add_plugin("version"); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 c:add_plugin("disco"); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 c:add_plugin("pep"); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 -- Add some hooks for debugging |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 c:hook("opened", function () print("Stream opened!") end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 c:hook("closed", function () print("Stream closed!") end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 c:hook("stanza", function (stanza) print("Stanza:", stanza) end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 -- This one prints all received data |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 c:hook("incoming-raw", print, 1000); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 -- Print a message after authentication |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 c:hook("authentication-success", function () print("Logged in!"); end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
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); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 -- Print a message and exit when disconnected |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 c:hook("disconnected", function () print("Disconnected!"); os.exit(); end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 -- Now, actually start the connection: |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 c:connect_client(jid, password); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 -- Catch the "ready" event to know when the stream is ready to use |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 c:hook("ready", function () |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 print("Stream ready!"); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 c.version:set{ name = "verse example client" }; |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 c:publish_pep(verse.stanza("tune", { xmlns = "http://jabber.org/protocol/tune" }) |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 :tag("title"):text("Beautiful Cedars"):up() |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 :tag("artist"):text("The Spinners"):up() |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 :tag("source"):text("Not Quite Folk"):up() |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 :tag("track"):text("4"):up() |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 ); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 c:hook_pep("http://jabber.org/protocol/mood", function (event) |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 print(event.from.." is "..event.item.tags[1].name); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 c:send(verse.presence():add_child(c:caps())); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 print("Starting loop...") |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 verse.loop() |