local lm = require 'lm'
local disco = require 'disco'
main.command ( 'disco',
function ( args )
local who
local conn = lm.connection.bless ( main.connection () )
if args.t then
who = args.t
else
who = main.full_jid ()
end
if args[1] == 'items' then
local node = args[2]
disco.items ( conn, who,
function ( items )
local text = ''
for index, item in ipairs ( items ) do
text = text .. ("\n [%s (%s)] %s"):format ( item.jid or '', item.node or '', item.name or '' )
end
if text ~= '' then
main.print_info ( who, ("Items service discovery result for %s (%s):%s"):format ( who, node or '', text ) )
else
main.print_info ( who, ("No items in discovery result for %s (%s)"):format ( who, node or '' ) )
end
end,
function ( mesg )
main.print_info ( who, ("Items service discovery for %s (%s) failed: %s"):format ( who, node or '', mesg ) )
end, node )
else
disco.info ( conn, who,
function ( identities, features )
main.print_info ( who, ("Service info discovery result for %s:"):format ( who ) )
local text = ''
for index, identity in ipairs ( identities ) do
text = text .. ("\n [%s (%s)] %s"):format ( identity.category or '', identity.type or '', identity.name or '' )
end
if text ~= '' then
main.print_info ( who, " Identities:" .. text )
else
main.print_info ( who, " No identities" )
end
text = ''
for index, feature in ipairs ( features ) do
text = text .. ("\n [%s]"):format ( feature or '' )
end
if text ~= '' then
main.print_info ( who, " Features:" .. text )
else
main.print_info ( who, " No features" )
end
end,
function ( mesg )
main.print_info ( who, ("Info service discovery for %s failed: %s"):format ( who, mesg ) )
end )
end
end, true, 'jid' )
commands_help['disco'] = "[-t target_jid] [info | items] [node]\n\nService discovery request.\nInfo is sent if omitted."
-- vim: se ts=4: --