examples/transports.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Mon, 23 Mar 2009 08:15:47 +0200
changeset 62 fb81aeb45e00
parent 58 aa3376776cf2
child 99 ed4676536ed9
permissions -rw-r--r--
Vcard and Evil


-- TRANSPORTED BUDDIES AVAILABILITY INDICATION

-- XXX: to option?
transport_jids = { 'icq.jabber.kiev.ua', 'mrim.unixzone.org.ua' }

function online ( jid )
	local info = main.buddy_info ( jid )
	if not info then
		return false
	end
	for resource, params in pairs ( info.resources ) do
		if params.status ~= '_' then
			return true
		end
	end
	return false
end

hooks_d['hook-status-change'].transports =
	function ( args )
		for k, jid in pairs ( transport_jids ) do
			if args.jid == jid then
				if args.new_status == '_' then
					main.run ( ("color roster * *@%s red"):format ( jid ) )
					main.run ( ("color roster dn_? *@%s red"):format ( jid ) )
				else
					main.run ( ("color roster * *@%s white"):format ( jid ) )
					main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
				end
			end
		end
	end

hooks_d['hook-start'].transports =
	function ( args )
		for k, jid in pairs ( transport_jids ) do
			if not online ( jid ) then
				main.run ( ("color roster * *@%s red"):format ( jid ) )
				main.run ( ("color roster dn_? *@%s red"):format ( jid ) )
			else
				main.run ( ("color roster * *@%s white"):format ( jid ) )
				main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
			end
		end
	end

hooks_d['hook-post-connect'].transports = hooks_d['hook-start'].transports

hooks_d['hook-pre-disconnect'].transports =
	function ( args )
		for k, jid in pairs ( transport_jids ) do
			-- when disconnected, all buddies are inaccessible, so, make them the same
			main.run ( ("color roster * *@%s white"):format ( jid ) )
			main.run ( ("color roster dn_? *@%s brightblack"):format ( jid ) )
		end
	end

-- vim: se ts=4: --