Mon, 08 Nov 2010 22:41:24 +0100
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