diff options
author | Remko Tronçon <git@el-tramo.be> | 2013-09-20 20:32:57 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-09-21 06:41:34 (GMT) |
commit | 33f9dc5337f1a59932b7ac117b0dea56e1dafe1a (patch) | |
tree | 8aeae2309c1a1770313bca0797cb92f8bcee4721 /Sluift/Examples | |
parent | 577c0c8fd30ffc0df718a8958eb7b8784ec3b0ac (diff) | |
download | swift-33f9dc5337f1a59932b7ac117b0dea56e1dafe1a.zip swift-33f9dc5337f1a59932b7ac117b0dea56e1dafe1a.tar.bz2 |
Sluift: Add support for ad-hoc commands
Change-Id: I4ac2d0b07841b03086d9dbd9fa06d1f030f4e1ca
Diffstat (limited to 'Sluift/Examples')
-rw-r--r-- | Sluift/Examples/AdHocCommands.lua | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Sluift/Examples/AdHocCommands.lua b/Sluift/Examples/AdHocCommands.lua new file mode 100644 index 0000000..9e83f0c --- /dev/null +++ b/Sluift/Examples/AdHocCommands.lua @@ -0,0 +1,48 @@ +--[[ + Copyright (c) 2013 Remko Tronçon + Licensed under the GNU General Public License v3. + See Documentation/Licenses/GPLv3.txt for more information. +--]] + +--[[ + + Ad-hoc command example. + + This script logs into an XMPP server, and executes a + multi-step ad-hoc command. + + The following environment variables are used: + * SLUIFT_JID, SWIFT_PASS: JID and password to log in with + * SLUIFT_DEBUG: Sets whether debugging should be turned on + +--]] + +require "sluift" + +sluift.debug = os.getenv("SLUIFT_DEBUG") or false + +c = sluift.new_client(os.getenv("SLUIFT_JID"), os.getenv("SLUIFT_PASS")) +c:connect(function () + to = sluift.jid.domain(os.getenv("SLUIFT_JID")) + + -- Get the list of commands + commands = assert(c:get_disco_items{ to = to, disco_items = { + node = sluift.disco.features.COMMANDS }}) + print(commands) + + -- Get the initial form + result = assert(c:set_command{ to = to, command = { + action = 'execute', node = 'http://jabber.org/protocol/admin#get-user-roster'}}) + + -- Fill in the form + submission = result.form:create_submission() + submission.accountjid = os.getenv("SLUIFT_JID") + + -- Submit the form + result = assert(c:set_command{ to = to, command = { + action = 'complete', node = 'http://jabber.org/protocol/admin#get-user-roster', + session_id = result.session_id, form = submission}}) + for _, v in ipairs(result.form.roster.values) do + print(v) + end +end) |