Fix some example scripts
authorMyhailo Danylenko <isbear@ukrpost.net>
Wed, 14 Apr 2010 11:21:02 +0300
changeset 111 5bcdb71ef2f2
parent 110 bd9f24178d67
child 112 15f4c09ffb86
Fix some example scripts * Unregister LM message handlers on module unload * Fix muc room-config command
examples/attention.lua
examples/evil.lua
examples/lm/muc.lua
examples/muc.lua
examples/oob.lua
examples/privacy.lua
--- a/examples/attention.lua	Mon Apr 12 00:41:23 2010 +0300
+++ b/examples/attention.lua	Wed Apr 14 11:21:02 2010 +0300
@@ -48,8 +48,7 @@
 			attention_handler_registered = true
 		end
 	end
-main.hook ( 'hook-post-connect', attention_pc_handler )
-main.hook ( 'hook-pre-disconnect',
+local attention_pd_handler = 
 	function ( args )
 		if attention_handler_registered then
 			local connection = main.connection ()
@@ -58,7 +57,9 @@
 			end
 			attention_handler_registered = false
 		end
-	end )
+	end
+main.hook ( 'hook-post-connect',   attention_pc_handler )
+main.hook ( 'hook-pre-disconnect', attention_pd_handler )
 
 -- register handler, if we are already connected
 main.hook ( 'hook-lua-start',
@@ -69,6 +70,7 @@
 main.hook ('hook-lua-quit',
 	function ( args )
 		main.del_feature ( 'urn:xmpp:attention:0' )
+		attention_pd_handler ()
 	end )
 
 -- vim: se ts=4 sw=4: --
--- a/examples/evil.lua	Mon Apr 12 00:41:23 2010 +0300
+++ b/examples/evil.lua	Wed Apr 14 11:21:02 2010 +0300
@@ -86,8 +86,7 @@
 			evil_handler_registered = true
 		end
 	end
-main.hook ( 'hook-post-connect', evil_pc_handler )
-main.hook ( 'hook-pre-disconnect',
+local evil_pd_handler = 
 	function ( args )
 		if evil_handler_registered then
 			local connection = main.connection ()
@@ -98,7 +97,9 @@
 			end
 			evil_handler_registered = false
 		end
-	end )
+	end
+main.hook ( 'hook-post-connect',   evil_pc_handler )
+main.hook ( 'hook-pre-disconnect', evil_pd_handler )
 
 main.hook ( 'hook-lua-start',
 	function ( args )
@@ -108,6 +109,7 @@
 main.hook ( 'hook-lua-quit',
 	function ( args )
 		main.del_feature ( 'http://jabber.org/protocol/evil' )
+		evil_pd_handler ()
 	end )
 
 local char2xmpp = {
--- a/examples/lm/muc.lua	Mon Apr 12 00:41:23 2010 +0300
+++ b/examples/lm/muc.lua	Wed Apr 14 11:21:02 2010 +0300
@@ -23,13 +23,13 @@
 					function ( form, success, fail )
 						iq.send ( conn, to, 'set',
 							{
-								command = form:format ( { xmlns = 'http://jabber.org/protocol/muc#owner' }, 'submit' ),
+								query = form:format ( { xmlns = 'http://jabber.org/protocol/muc#owner' }, 'submit' ),
 							}, success, fail )
 					end,
 					function ( form, success, fail )
 						iq.send ( conn, to, 'set',
 							{
-								command = form:format ( { xmlns = 'http://jabber.org/protocol/muc#owner' }, 'cancel' ),
+								query = form:format ( { xmlns = 'http://jabber.org/protocol/muc#owner' }, 'cancel' ),
 							}, success, fail )
 					end )
 			end
--- a/examples/muc.lua	Mon Apr 12 00:41:23 2010 +0300
+++ b/examples/muc.lua	Wed Apr 14 11:21:02 2010 +0300
@@ -10,7 +10,7 @@
 			return
 		end
 		local who
-		if args then
+		if args and args ~= "" then
 			who = args
 		else
 			who = main.current_buddy ()
--- a/examples/oob.lua	Mon Apr 12 00:41:23 2010 +0300
+++ b/examples/oob.lua	Wed Apr 14 11:21:02 2010 +0300
@@ -44,38 +44,39 @@
 		local connection = main.connection ()
 		if connection then
 			local conn = lm.connection.bless ( connection )
-			conn:handler ( oob_iq_handler, 'iq', 'normal' )
-			conn:handler ( oob_message_handler, 'message', 'normal' )
+			conn:handler ( oob_iq_handler,      'iq',       'normal' )
+			conn:handler ( oob_message_handler, 'message',  'normal' )
 			conn:handler ( oob_message_handler, 'presence', 'normal' )
 			oob_handler_registered = true
 		end
 	end
-main.hook ( 'hook-post-connect', oob_pc_handler )
-main.hook ( 'hook-pre-disconnect',
+local oob_pd_handler = 
 	function ( args )
 		if oob_handler_registered then
 			local connection = main.connection ()
 			if connection then
 				local conn = lm.connection.bless ( connection )
-				conn:handler ( oob_iq_handler, 'iq' )
-				conn:handler ( oob_message_handler, 'message' )
+				conn:handler ( oob_iq_handler,      'iq'       )
+				conn:handler ( oob_message_handler, 'message'  )
 				conn:handler ( oob_message_handler, 'presence' )
 			end
 			oob_handler_registered = false
 		end
-	end )
-
+	end
+main.hook ( 'hook-post-connect',   oob_pc_handler )
+main.hook ( 'hook-pre-disconnect', oob_pd_handler )
 
 main.hook ( 'hook-lua-start',
 	function ( args )
 		main.add_feature ( 'jabber:iq:oob' )
-		main.add_feature ( 'jabber:x:oob' )
+		main.add_feature ( 'jabber:x:oob'  )
 		oob_pc_handler ()
 	end )
 main.hook ( 'hook-lua-quit',
 	function ( args )
 		main.del_feature ( 'jabber:iq:oob' )
-		main.del_feature ( 'jabber:x:oob' )
+		main.del_feature ( 'jabber:x:oob'  )
+		oob_pd_handler ()
 	end )
 
 -- vim: se ts=4 sw=4: --
--- a/examples/privacy.lua	Mon Apr 12 00:41:23 2010 +0300
+++ b/examples/privacy.lua	Wed Apr 14 11:21:02 2010 +0300
@@ -86,8 +86,7 @@
 			privacy_handler_registered = true
 		end
 	end
-main.hook ( 'hook-post-connect', privacy_pc_handler )
-main.hook ( 'hook-pre-disconnect',
+privacy_pd_handler = 
 	function ( args )
 		if privacy_handler_registered then
 			local connection = main.connection ()
@@ -96,6 +95,9 @@
 			end
 			privacy_handler_registered = false
 		end
-	end )
+	end
+main.hook ( 'hook-post-connect',   privacy_pc_handler )
+main.hook ( 'hook-pre-disconnect', privacy_pd_handler )
+main.hook ( 'hook-lua-quit',       privacy_pd_handler )
 
 -- vim: se ts=4 sw=4: --