diff mod_adhoc/adhoc/mod_adhoc.lua @ 244:e0802b2716c3

mod_adhoc: Code restructuring
author Florian Zeitz <florob@babelmonkeys.de>
date Sat, 21 Aug 2010 19:20:12 +0200
parents 1ae653712e37
children 84d03c44bdb9
line wrap: on
line diff
--- a/mod_adhoc/adhoc/mod_adhoc.lua	Fri Aug 13 20:21:39 2010 +0800
+++ b/mod_adhoc/adhoc/mod_adhoc.lua	Sat Aug 21 19:20:12 2010 +0200
@@ -16,11 +16,11 @@
 
 module:hook("iq/host/"..xmlns_disco.."#items:query", function (event)
 	local origin, stanza = event.origin, event.stanza;
-	-- Required for Prosody <= 0.7
-	local privileged = is_admin(stanza.attr.from)
-	    or is_admin(stanza.attr.from, stanza.attr.to); 
 	if stanza.attr.type == "get" and stanza.tags[1].attr.node
 	    and stanza.tags[1].attr.node == xmlns_cmd then
+		-- Required for Prosody <= 0.7
+		local privileged = is_admin(stanza.attr.from)
+		    or is_admin(stanza.attr.from, stanza.attr.to);
 		reply = st.reply(stanza);
 		reply:tag("query", { xmlns = xmlns_disco.."#items",
 		    node = xmlns_cmd });
@@ -37,15 +37,14 @@
 	end
 end, 500);
 
-module:hook("iq/host", function (event)
+module:hook("iq/host"..xmlns_cmd..":command", function (event)
 	local origin, stanza = event.origin, event.stanza;
-	if stanza.attr.type == "set" and stanza.tags[1]
-	    and stanza.tags[1].name == "command" then 
+	if stanza.attr.type == "set" then
 		local node = stanza.tags[1].attr.node
-		-- Required for Prosody <= 0.7
-		local privileged = is_admin(event.stanza.attr.from)
-		    or is_admin(stanza.attr.from, stanza.attr.to);
 		if commands[node] then
+			-- Required for Prosody <= 0.7
+			local privileged = is_admin(event.stanza.attr.from)
+			    or is_admin(stanza.attr.from, stanza.attr.to);
 			if commands[node].permission == "admin"
 			    and not privileged then
 				origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up()