examples/privacy.lua
changeset 99 ed4676536ed9
parent 68 742878c74b8e
child 100 521c27baa387
equal deleted inserted replaced
98:59aeae623ac6 99:ed4676536ed9
     7 		print ( 'Privacy list changed: ' .. name )
     7 		print ( 'Privacy list changed: ' .. name )
     8 	end )
     8 	end )
     9 
     9 
    10 main.command ( 'blocklist',
    10 main.command ( 'blocklist',
    11 	function ( args )
    11 	function ( args )
       
    12 		local connection = main.connection ()
       
    13 		if not connection then
       
    14 			print "You are not online!"
       
    15 			return
       
    16 		end
    12 		local action = args[1]
    17 		local action = args[1]
    13 		local conn   = lm.connection.bless ( main.connection () )
    18 		local conn   = lm.connection.bless ( connection )
    14 		local who    = main.current_buddy ()
    19 		local who    = main.current_buddy ()
    15 		privacy.list ( conn, 'mcabber',
    20 		privacy.list ( conn, 'mcabber',
    16 			function ( list )
    21 			function ( list )
    17 				if action == 'add' then
    22 				if action == 'add' then
    18 					for i, item in ipairs ( list ) do
    23 					for i, item in ipairs ( list ) do
    64 commands_help['blocklist'] = '[[add | del] [jid]]\n\nRetrieves list, adds or removes buddies to/from mcabber\'s server blocklist.\nAny stanzas from buddy in list are blocked by server.'
    69 commands_help['blocklist'] = '[[add | del] [jid]]\n\nRetrieves list, adds or removes buddies to/from mcabber\'s server blocklist.\nAny stanzas from buddy in list are blocked by server.'
    65 
    70 
    66 local privacy_handler            = lm.message_handler.new ( privacy.iq_handler )
    71 local privacy_handler            = lm.message_handler.new ( privacy.iq_handler )
    67 local privacy_handler_registered = false
    72 local privacy_handler_registered = false
    68 
    73 
    69 hooks_d['hook-post-connect'].privacy =
    74 privacy_pc_handler =
    70 	function ( args )
    75 	function ( args )
    71 		privacy.active ( lm.connection.bless ( main.connection () ), 'mcabber',
    76 		local connection = main.connection ()
    72 			function ()
    77 		if connection then
    73 				print ( 'Server blocklist activated' )
    78 			privacy.active ( lm.connection.bless ( connection ), 'mcabber',
    74 			end,
    79 				function ()
    75 			function ()
    80 					print ( 'Server blocklist activated' )
    76 				-- list may be absent, so, we will not pollute log with errors
    81 				end,
    77 			end )
    82 				function ()
    78 		lm.connection.bless( main.connection () ):handler ( privacy_handler, 'iq', 'normal' )
    83 					-- list may be absent, so, we will not pollute log with errors
    79 		privacy_handler_registered = true
    84 				end )
    80 		hooks_d['hook-post-connect'].privacy =
    85 			lm.connection.bless( connection ):handler ( privacy_handler, 'iq', 'normal' )
    81 			function ( args )
    86 			privacy_handler_registered = true
    82 				privacy.active ( lm.connection.bless ( main.connection () ), 'mcabber',
    87 		end
    83 					function ()
    88 	end
    84 						print ( 'Server blocklist activated' )
    89 main.hook ( 'hook-post-connect', privacy_pc_handler )
    85 					end,
    90 main.hook ( 'hook-pre-disconnect',
    86 					function ()
    91 	function ( args )
    87 						-- list may be absent, so, we will not pollute log with errors
    92 		if privacy_handler_registered then
    88 					end )
    93 			local connection = main.connection ()
       
    94 			if connection then
       
    95 				lm.connection.bless( connection ):handler ( privacy_handler, 'iq' )
    89 			end
    96 			end
    90 		hooks_d['hook-quit'].privacy =
    97 			privacy_handler_registered = false
    91 			function ( args )
    98 		end
    92 				if privacy_handler_registered then
       
    93 					lm.connection.bless( main.connection () ):handler ( privacy_handler, 'iq' )
       
    94 				end
       
    95 			end
       
    96 	end
    99 	end
    97 
   100 
    98 -- vim: se ts=4: --
   101 -- vim: se ts=4 sw=4: --