summaryrefslogtreecommitdiffstats
blob: 9e83f0c7acb88f82dc542ffecd76333875851524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)