plugins.commands: Enable commands to be directed to the bots nick

Mon, 08 Nov 2010 22:41:24 +0100

author
Kim Alvefur <zash@zash.se>
date
Mon, 08 Nov 2010 22:41:24 +0100
changeset 35
0f17e574b6bb
parent 34
23e17e64ca25
child 36
ccce42f781de

plugins.commands: Enable commands to be directed to the bots nick

plugins/commands.lua file | annotate | diff | comparison | revisions
--- a/plugins/commands.lua	Mon Nov 08 21:27:44 2010 +0100
+++ b/plugins/commands.lua	Mon Nov 08 22:41:24 2010 +0100
@@ -1,6 +1,11 @@
 function riddim.plugins.commands(bot)
 	local command_pattern = "^%"..(bot.config.command_prefix or "@").."([%a%-%_%d]+)(%s?)(.*)$";
 
+	local direct_address_pattern = false;
+	if bot.config.nick then
+		direct_address_pattern = "^"..bot.config.nick.."[,: ]+([%a%-%_%d]+)(%s?)(.*)";
+	end
+
 	local function process_command(event)
 		local body = event.body;
 		if not body then return; end
@@ -8,6 +13,10 @@
 
 		local command, hasparam, param = body:match(command_pattern);
 	
+		if not command and direct_address_pattern then
+			command, hasparam, param = body:match(direct_address_pattern);
+		end
+	
 		if not command then
 			command, hasparam, param = body:match("%[([%a%-%_%d]+)(%s?)(.*)%]");
 		end

mercurial