examples/evil.lua
changeset 111 5bcdb71ef2f2
parent 99 ed4676536ed9
child 121 75a7d595817c
equal deleted inserted replaced
110:bd9f24178d67 111:5bcdb71ef2f2
    84 			lm.connection.bless( main.connection () ):handler ( evil_handler, 'message',  'first' )
    84 			lm.connection.bless( main.connection () ):handler ( evil_handler, 'message',  'first' )
    85 			lm.connection.bless( main.connection () ):handler ( evil_handler, 'presence', 'first' )
    85 			lm.connection.bless( main.connection () ):handler ( evil_handler, 'presence', 'first' )
    86 			evil_handler_registered = true
    86 			evil_handler_registered = true
    87 		end
    87 		end
    88 	end
    88 	end
    89 main.hook ( 'hook-post-connect', evil_pc_handler )
    89 local evil_pd_handler = 
    90 main.hook ( 'hook-pre-disconnect',
       
    91 	function ( args )
    90 	function ( args )
    92 		if evil_handler_registered then
    91 		if evil_handler_registered then
    93 			local connection = main.connection ()
    92 			local connection = main.connection ()
    94 			if connection then
    93 			if connection then
    95 				lm.connection.bless( main.connection () ):handler ( evil_handler, 'iq'       )
    94 				lm.connection.bless( main.connection () ):handler ( evil_handler, 'iq'       )
    96 				lm.connection.bless( main.connection () ):handler ( evil_handler, 'message'  )
    95 				lm.connection.bless( main.connection () ):handler ( evil_handler, 'message'  )
    97 				lm.connection.bless( main.connection () ):handler ( evil_handler, 'presence' )
    96 				lm.connection.bless( main.connection () ):handler ( evil_handler, 'presence' )
    98 			end
    97 			end
    99 			evil_handler_registered = false
    98 			evil_handler_registered = false
   100 		end
    99 		end
   101 	end )
   100 	end
       
   101 main.hook ( 'hook-post-connect',   evil_pc_handler )
       
   102 main.hook ( 'hook-pre-disconnect', evil_pd_handler )
   102 
   103 
   103 main.hook ( 'hook-lua-start',
   104 main.hook ( 'hook-lua-start',
   104 	function ( args )
   105 	function ( args )
   105 		main.add_feature ( 'http://jabber.org/protocol/evil' )
   106 		main.add_feature ( 'http://jabber.org/protocol/evil' )
   106 		evil_pc_handler ()
   107 		evil_pc_handler ()
   107 	end
   108 	end
   108 main.hook ( 'hook-lua-quit',
   109 main.hook ( 'hook-lua-quit',
   109 	function ( args )
   110 	function ( args )
   110 		main.del_feature ( 'http://jabber.org/protocol/evil' )
   111 		main.del_feature ( 'http://jabber.org/protocol/evil' )
       
   112 		evil_pd_handler ()
   111 	end )
   113 	end )
   112 
   114 
   113 local char2xmpp = {
   115 local char2xmpp = {
   114 	f = 'chat',
   116 	f = 'chat',
   115 	o = '',
   117 	o = '',