plugins/commands.lua

changeset 14
3df63aaba9e3
parent 0
7d84f4403d67
child 16
ae69cea97598
--- a/plugins/commands.lua	Fri May 14 14:23:03 2010 +0100
+++ b/plugins/commands.lua	Thu May 20 14:32:21 2010 +0100
@@ -1,16 +1,12 @@
 require "util.xstanza"
 
 function riddim.plugins.commands(bot)
-	local function handle_message(message)
-		-- Parse message body
-	end
-	
 	local command_pattern = "^%"..(bot.config.command_prefix or "@").."([%a%-%_%d]+)(%s?)(.*)$";
 
 	local function process_command(event)
-		local body, sender = event.body, event.sender;
+		local body = event.body;
 		if not body then return; end
-		if event.delay then return; end -- Don't process old messages
+		if event.delay then return; end -- Don't process old messages from groupchat
 
 		local command, hasparam, param = body:match(command_pattern);
 	
@@ -24,10 +20,10 @@
 			local command_event = {
 						command = command,
 						param = param,
-						sender = sender,
+						sender = event.sender,
 						stanza = event.stanza,
 						reply = event.reply,
-						room = event.room,
+						room = event.room, -- groupchat support
 					};
 			local ret = bot:event("commands/"..command, command_event);
 			if type(ret) == "string" then
@@ -37,9 +33,10 @@
 		end
 	end
 	
-	-- Hook messages to bot and from rooms, fire a command event on the bot
+	-- Hook messages sent to bot, fire a command event on the bot
 	bot:hook("message", process_command);
 	
+	-- Support groupchat plugin: Hook messages from rooms that the bot joins
 	bot:hook("groupchat/joining", function (room)
 		room:hook("message", process_command);
 	end);

mercurial