Sat, 03 Dec 2011 16:27:36 +0000
verse.plugins.groupchat: Make last commit (7802a048) more concise
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!"); |
168
7285e04a4797
plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
37 | c:send(verse.presence()); |
128
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | 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
|
39 | 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
|
40 | :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
|
41 | :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
|
42 | :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
|
43 | :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
|
44 | ); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | 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
|
47 | 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
|
48 | end); |
168
7285e04a4797
plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
49 | |
7285e04a4797
plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
50 | c:hook_pep("http://jabber.org/protocol/tune", function (event) |
243
20842f98f9ff
doc/example_pep.lua: get_child_text()
Kim Alvefur <zash@zash.se>
parents:
168
diff
changeset
|
51 | print(event.from.." is listening to "..event.item:get_child_text("title")); |
168
7285e04a4797
plugins.pep: Update for new disco/caps code
Matthew Wild <mwild1@gmail.com>
parents:
128
diff
changeset
|
52 | end); |
128
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | end); |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | print("Starting loop...") |
720b9ccd7ea4
doc/example_pep.lua: Example script to use the PEP plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | verse.loop() |