examples/transports.lua
changeset 99 ed4676536ed9
parent 58 aa3376776cf2
equal deleted inserted replaced
98:59aeae623ac6 99:ed4676536ed9
    15 		end
    15 		end
    16 	end
    16 	end
    17 	return false
    17 	return false
    18 end
    18 end
    19 
    19 
    20 hooks_d['hook-status-change'].transports =
    20 local transports_pc_handler =
    21 	function ( args )
    21 	function ( args )
    22 		for k, jid in pairs ( transport_jids ) do
    22 		for k, jid in pairs ( transport_jids ) do
    23 			if args.jid == jid then
    23 			if args.jid == jid then
    24 				if args.new_status == '_' then
    24 				if args.new_status == '_' then
    25 					main.run ( ("color roster * *@%s red"):format ( jid ) )
    25 					main.run ( ("color roster * *@%s red"):format ( jid ) )
    30 				end
    30 				end
    31 			end
    31 			end
    32 		end
    32 		end
    33 	end
    33 	end
    34 
    34 
    35 hooks_d['hook-start'].transports =
    35 main.hook ( 'hook-lua-start',
    36 	function ( args )
    36 	function ( args )
    37 		for k, jid in pairs ( transport_jids ) do
    37 		for k, jid in pairs ( transport_jids ) do
    38 			if not online ( jid ) then
    38 			if not online ( jid ) then
    39 				main.run ( ("color roster * *@%s red"):format ( jid ) )
    39 				main.run ( ("color roster * *@%s red"):format ( jid ) )
    40 				main.run ( ("color roster dn_? *@%s red"):format ( jid ) )
    40 				main.run ( ("color roster dn_? *@%s red"):format ( jid ) )
    41 			else
    41 			else
    42 				main.run ( ("color roster * *@%s white"):format ( jid ) )
    42 				main.run ( ("color roster * *@%s white"):format ( jid ) )
    43 				main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
    43 				main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
    44 			end
    44 			end
    45 		end
    45 		end
    46 	end
    46 	end )
       
    47 main.hook ( 'hook-status-change', transports_pc_handler )
       
    48 main.hook ( 'hook-post-connect',  transports_pc_handler )
    47 
    49 
    48 hooks_d['hook-post-connect'].transports = hooks_d['hook-start'].transports
    50 main.hook ( 'hook-pre-disconnect',
    49 
       
    50 hooks_d['hook-pre-disconnect'].transports =
       
    51 	function ( args )
    51 	function ( args )
    52 		for k, jid in pairs ( transport_jids ) do
    52 		for k, jid in pairs ( transport_jids ) do
    53 			-- when disconnected, all buddies are inaccessible, so, make them the same
    53 			-- when disconnected, all buddies are inaccessible, so, make them the same
    54 			main.run ( ("color roster * *@%s white"):format ( jid ) )
    54 			main.run ( ("color roster * *@%s white"):format ( jid ) )
    55 			main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
    55 			main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
    56 		end
    56 		end
    57 	end
    57 	end )
    58 
    58 
    59 -- vim: se ts=4: --
    59 -- vim: se ts=4 sw=4: --