1 |
|
2 function remote_command ( who, command ) |
|
3 lm.connection.bless( main.connection () ):send ( |
|
4 lm.message.create { mtype = 'iq-set', to = who, |
|
5 command = { xmlns = 'http://jabber.org/protocol/commands', action = 'execute', node = command } |
|
6 }, |
|
7 function ( conn, mess ) |
|
8 if mess:child ( 'command' ) and mess:child( 'command' ):child ( 'x' ) then |
|
9 local id = parse_form ( mess:child( 'command' ):child ( 'x' ) ) |
|
10 local sid = mess:child( 'command' ):attribute ( 'sessionid' ) |
|
11 forms[id].send = |
|
12 function ( form ) |
|
13 conn:send ( |
|
14 lm.message.create { mtype = 'iq-set', to = who, |
|
15 command = { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid, |
|
16 x = { xmlns = 'jabber:x:data', type = 'form', |
|
17 field = form.val, |
|
18 }, |
|
19 }, |
|
20 }, |
|
21 function ( conn, mess ) |
|
22 if mess:child ( 'command' ) and mess:child( 'command' ):attribute ( 'status' ) == 'completed' then |
|
23 main.print_info ( who, 'Now you can run /form del ' .. id .. ' to delete form from list' ) |
|
24 forms.status = 'acquired' |
|
25 else |
|
26 main.print_info ( who, 'Got non-successful response to form:\n' .. mess:xml () ) |
|
27 forms.status = 'rejected' |
|
28 end |
|
29 return true |
|
30 end ) |
|
31 form.status = 'sent' |
|
32 end |
|
33 forms[id].status = 'filling' |
|
34 main.print_info ( who, 'You have new form. To fill it, use /form ' .. id .. ' fieldname value' ) |
|
35 else |
|
36 main.print_info ( who, 'Got response to command request:\n' .. mess:xml () ) |
|
37 end |
|
38 return true |
|
39 end ) |
|
40 end |
|
41 |
|
42 main.command ( 'remote', |
|
43 function ( args ) |
|
44 local who |
|
45 if args.t then |
|
46 who = args.t |
|
47 else |
|
48 who = main.full_jid () |
|
49 end |
|
50 local action = args[1] |
|
51 if not action then |
|
52 disco_items ( lm.connection.bless ( main.connection () ), |
|
53 function ( items ) |
|
54 if type ( items ) == 'string' then |
|
55 main.print_info ( who, string.format ( "Service items discovery for %s (http://jabber.org/protocol/commands) failed: %s", who, items ) ) |
|
56 else |
|
57 local text = '' |
|
58 for index, item in ipairs ( items ) do |
|
59 text = text .. '\n - ' .. item.node |
|
60 end |
|
61 if text ~= '' then |
|
62 main.print_info ( who, 'Available commands:' .. text ) |
|
63 else |
|
64 main.print_info ( who, 'No commands available.' ) |
|
65 end |
|
66 end |
|
67 end, who, 'http://jabber.org/protocol/commands' ) |
|
68 elseif action then |
|
69 remote_command ( who, action ) |
|
70 end |
|
71 end, true, 'jid' ) |
|
72 |
|
73 commands_help['remote'] = "[-t target_jid] [remote_command]\n\nPrints list of available remote command or requests execution of specified command." |
|
74 |
|
75 -- vim: se ts=4: -- |
|