examples/register.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 31 Mar 2010 01:25:19 +0300
changeset 99 ed4676536ed9
parent 68 742878c74b8e
child 121 75a7d595817c
permissions -rw-r--r--
Update most useful scripts * new hooks interface * connection state checking


local lm          = require 'lm'
local iq_register = require 'lm.iq_register'

main.command ( 'register',
	function ( args )
		local connection = main.connection ()
		if not connection then
			print "You are not online!"
			return
		end
		local who
		if args and args ~= '' then
			who = args
		else
			who = main.full_jid ()
		end
		iq_register.register ( lm.connection.bless ( connection ), who,
			function ( form, submit, reject )
				insert_form ( form,
					function ( form )
						submit ( form,
							function ()
								main.print_info ( who, 'Successfully registered' )
							end,
							function ( mesg )
								main.print_info ( who, 'Registration failed: ' .. mesg )
							end )
					end,
					function ( form )
						reject ( form,
							function ()
								main.print_info ( who, 'Registration cancelled' )
							end,
							function ( mesg )
								main.print_info ( who, 'Registration cancellation failed: ' .. mesg )
							end )
					end )
			end,
			function ( mesg )
				main.print_info ( who, 'Registration failed: ' .. mesg )
			end )
	end, false, 'jid' )
main.command ( 'cancel',
	function ( args )
		local connection = main.connection ()
		if not connection then
			print "You are not online!"
			return
		end
		local who
		if args and args ~= '' then
			who = args
		else
			who = main.full_jid ()
		end
		iq_register.unregister ( lm.connection.bless ( connection ), who,
			function ( form, submit, reject )
				if not form then
					main.print_info ( who, 'Successfully unregistered' )
				else
					insert_form ( form,
						function ( form )
							submit ( form,
								function ()
									main.print_info ( who, 'Successfully unregistered' )
								end,
								function ( mesg )
									main.print_info ( who, 'Unregistrering failed: ' .. mesg )
								end )
						end,
						function ( form )
							reject ( form,
								function ()
									main.print_info ( who, 'Unregistration cancelled' )
								end,
								function ( mesg )
									main.print_info ( who, 'Unregistration cancellation failed: ' .. mesg )
								end )
						end )
				end
			end,
			function ( mesg )
				main.print_info ( who, 'Unregistering failed: ' .. mesg )
			end )
	end, false, 'jid' )

commands_help['register'] = "[jid]\n\nSends registration request to jid (or current buddy). You, probably, then will need to fill and send some form."
commands_help['cancel'] = "[jid]\n\nSends registration cancellation request to jid (or current buddy). May require a form filling."

-- vim: se ts=4 sw=4: --