From 03070e41c4dc1378c8379d655af51dd89febd0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Mon, 28 Nov 2016 01:05:46 -0300 Subject: [PATCH] Check nickname using RFC1459 rules in `botcmds.lua`. --- botcmds.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/botcmds.lua b/botcmds.lua index 42ff8b0..16f7f50 100644 --- a/botcmds.lua +++ b/botcmds.lua @@ -1,15 +1,30 @@ irc.bot_commands = {} +-- From RFC1459: +-- "Because of IRC’s scandanavian origin, the characters {}| are +-- considered to be the lower case equivalents of the characters +-- []\, respectively." +local irctolower = { ["["]="{", ["\\"]="|", ["]"]="}" } + +local function irclower(s) + return (s:lower():gsub("[%[%]\\]", irctolower)) +end + +local function nickequals(nick1, nick2) + return irclower(nick1) == irclower(nick2) +end + function irc:check_botcmd(msg) local prefix = irc.config.command_prefix - local nick = irc.conn.nick:lower() + local nick = irc.conn.nick local text = msg.args[2] - local nickpart = text:sub(1, #nick + 2):lower() + local nickpart = text:sub(1, #nick) + local suffix = text:sub(#nick+1, #nick+2) -- First check for a nick prefix - if nickpart == nick..": " or - nickpart == nick..", " then + if nickequals(nickpart, nick) + and (suffix == ": " or suffix == ", ") then self:bot_command(msg, text:sub(#nick + 3)) return true -- Then check for the configured prefix