examples/remote.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Sat, 01 Aug 2009 23:05:11 +0300
changeset 79 05328c643696
parent 68 742878c74b8e
child 99 ed4676536ed9
permissions -rw-r--r--
Mcabber-lm includes moved into a project tree


local lm     = require 'lm'
local remote = require 'lm.remote'

main.command ( 'remote',
	function ( args )
		local who
		if args.t then
			who = args.t
		else
			who = main.full_jid ()
		end
		local action = args[1]
		local conn   = lm.connection.bless ( main.connection () )
		if action then
			remote.command ( conn, who, action,
				function ( form, submit, reject )
					if not form then
						main.print_info ( who, ('Command %s completed'):format ( action ) )
					else
						insert_form ( form, -- XXX
							function ( form )
								submit ( form,
									function ()
										main.print_info ( who, ('Command %s completed'):format ( action ) )
									end,
									function ( mesg )
										main.print_info ( who, ('Command %s execution failed: %s'):format ( action, mesg ) )
									end )
							end,
							function ( form )
								reject ( form,
									function ()
										main.print_info ( who, ('Command %s execution cancelled'):format ( action ) )
									end,
									function ( mesg )
										main.print_info ( who, ('Command %s execution cancellation failed: %s'):format ( action, mesg ) )
									end )
							end )
					end
				end,
				function ( mesg )
					main.print_info ( who, ('Command %s execution failed: %s'):format ( action, mesg ) )
				end )
		else
			remote.list ( conn, who,
				function ( items )
					local text = ''
					for index, item in ipairs ( items ) do
						text = text .. '\n - ' .. item.node
					end
					if text ~= '' then
						main.print_info ( who, 'Available commands:' .. text )
					else
						main.print_info ( who, 'No commands available.' )
					end
				end,
				function ( mesg )
					main.print_info ( who, ("Remote commands list for %s failed: %s"):format ( who, mesg ) )
				end )
		end
	end, true, 'jid' )

commands_help['remote'] = "[-t target_jid] [remote_command]\n\nPrints list of available remote command or requests execution of specified command."

-- vim: se ts=4: --