examples/xep0077.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Tue, 24 Feb 2009 19:42:48 +0200
changeset 7 eb6d89bf1fbf
parent 5 cba039bd6f13
child 8 fc9060b9b7cc
permissions -rw-r--r--
Commands and init improvements * 'lua' command in C * add_command and del_command merged * de-hardcoded initialization file name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     2
function parse_iq_register ( node )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     3
	local form = { title = 'jabber:iq:register', exp = '', val = { } }
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     4
	if node:child ( 'instructions' ) then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     5
		form.exp = form.exp .. 'Instructions: ' .. node:child( 'instructions' ):value () .. '\n'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     6
	end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     7
	if node:child ( 'registered' ) then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     8
		form.exp = form.exp .. 'Registered: yes\n'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     9
	end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    10
	form.exp = form.exp .. 'Fields:\n'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    11
	local field = node:children ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    12
	while field do
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    13
		local name = field:name ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    14
		if name ~= 'instructions' and name ~= 'registered' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    15
			form.exp = form.exp .. ' - ' .. name .. '\n'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    16
			if field:value () and field:value () ~= '' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    17
				form.exp = form.exp .. '   Default value: ' .. field:value () .. '\n'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    18
			end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    19
			table.insert ( form.val, { type = 'text-single', var = name, value = { field:value () or '' } } )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    20
		end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    21
		field = field:next ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
	end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
	table.insert ( forms, form )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
	return #forms
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
function format_iq_register ( fields )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
	local result = { xmlns = 'jabber:iq:register' }
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
	for index, field in ipairs ( fields ) do
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
		result[field.var] = field.value
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
	end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
	return result
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    34
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    35
function register_to ( who )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    36
	lm.connection.bless( main.connection () ):send (
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    37
		lm.message.create { mtype = 'iq-get', to = who,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
			query = { xmlns = 'jabber:iq:register' }
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
		},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
		function ( conn, mess )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
			local node = mess:child ( 'query' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
			if node and node:attribute ( 'xmlns' ) == 'jabber:iq:register' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
				main.print_info ( who, 'D: Got:\n' .. mess:xml () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    44
				local x = node:child ( 'x' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
				local id
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
				local finalizer =
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
					function ( conn, mess )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
						local mt, st = mess:type ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
						if st == 'result' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
							main.print_info ( who, 'Now you can run /form del ' .. id .. ' to delete form from list' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    51
							forms[id].status = 'acquired'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
						else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    53
							main.print_info ( who, 'Got non-successful response to form:\n' .. mess:xml () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    54
							forms[id].status = 'rejected'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    55
						end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    56
						return true
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
					end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
				if x and x:attribute ( 'xmlns' ) == 'jabber:x:data' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    59
					id = parse_form ( x )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
					-- local sid = mess:child( 'command' ):attribute ( 'sessionid' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
					forms[id].send =
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
						function ( form )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
							conn:send (
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
								lm.message.create { mtype = 'iq-set', to = who,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65
									query = { xmlns = 'jabber:iq:register',
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
										x = { xmlns = 'jabber:x:data', type = 'submit',
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    67
											field = form.val,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    68
										},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    69
									},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    70
								}, finalizer )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    71
						end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
					forms[id].status = 'filling'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
					main.print_info ( who, 'You have new form. To fill it, use /form ' .. id .. ' fieldname value' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
				else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    75
					id = parse_iq_register ( mess:child ( 'query' ) )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    76
					forms[id].send =
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
						function ( form )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
							conn:send (
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    79
								lm.message.create { mtype = 'iq-set', to = who,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    80
									query = format_iq_register ( form.val ),
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    81
								}, finalizer )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    82
						end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    83
					forms[id].status = 'filling'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    84
					main.print_info ( who, 'You have new form. To fill it, use /form ' .. id .. ' fieldname value' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    85
				end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    86
			else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    87
				main.print_info ( who, 'Error response:\n' .. mess:xml () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    88
			end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
			return true
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    90
		end )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    91
end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    93
function unregister_from ( who )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    94
	lm.connection.bless( main.connection () ):send (
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    95
		lm.message.create { mtype = 'iq-set', to = who,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    96
			query = { xmlns = 'jabber:iq:register',
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    97
				remove = { },
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    98
			},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    99
		},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   100
		function ( conn, mess )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   101
			local mt, st = mess:type ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   102
			if st == 'result' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   103
				main.print_info ( who, 'Registration cancelled' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   104
			elseif st == 'error' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   105
				if mess:child ( 'error' ) then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   106
					main.print_info ( who, 'Error response: ' .. mess:child( 'error' ):children():name () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   107
				else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   108
					local query = mess:child ( 'query' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
					if query and query:child ( 'x' ) then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   110
						local id = parse_form ( query:child ( 'x' ) )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   111
						forms[id].send =
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   112
							function ( form )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   113
								conn:send (
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   114
									lm.message.create { mtype = 'iq-set', to = who,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   115
										query = { xmlns = 'jabber:iq:register',
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   116
											x = { xmlns = 'jabber:x:data', type = 'submit',
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   117
												field = form.val,
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   118
											},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   119
										},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   120
									},
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   121
									function ( conn, mess )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   122
										local mt, st = mess:type ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   123
										if st == 'result' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   124
											main.print_info ( who, 'Now you can run /form del ' .. id .. ' to delete form from list' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   125
											forms[id].status = 'acquired'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   126
										else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   127
											main.print_info ( who, 'Got non-successful response to form:\n' .. mess:xml () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   128
											forms[id].status = 'rejected'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   129
										end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   130
										return true
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   131
									end )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   132
							end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   133
						forms[id].status = 'filling'
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   134
						main.print_info ( who, 'You have new form. To fill it, use /form ' .. id .. ' fieldname value' )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   135
					else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   136
						main.print_info ( who, 'Got non-successful response to form:\n' .. mess:xml () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   137
					end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   138
				end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   139
			else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   140
				main.print_info ( who, 'Got non-successful response to form:\n' .. mess:xml () )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   141
			end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   142
			return true
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   143
		end )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   144
end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   145
7
eb6d89bf1fbf Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents: 5
diff changeset
   146
main.command ( 'register',
5
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   147
	function ( args )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   148
		local who
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   149
		if args[1] then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   150
			who = rebuild_args_string ( args )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   151
		else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   152
			who = full_current_jid ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   153
		end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   154
		register_to ( who )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   155
	end )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   156
7
eb6d89bf1fbf Commands and init improvements
Myhailo Danylenko <isbear@ukrpost.net>
parents: 5
diff changeset
   157
main.command ( 'cancel',
5
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   158
	function ( args )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   159
		local who
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   160
		if args and args ~= '' then
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   161
			who = args
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   162
		else
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   163
			who = full_current_jid ()
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   164
		end
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   165
		unregister_from ( who )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   166
	end )
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   167
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   168
commands_help['register'] = "[jid]\n\nSends registration request to jid (or current buddy). You, probably, then will need to fill and send some form."
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   169
commands_help['cancel'] = "[jid]\n\nSends registration cancellation request to jid (or current buddy). May require a form filling."
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   170
cba039bd6f13 Included sample configuration into package
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   171
-- vim: se ts=4: --