1
0
mirror of https://github.com/minetest-mods/irc.git synced 2024-12-27 01:10:17 +01:00

Check nickname using RFC1459 rules in botcmds.lua.

This commit is contained in:
Diego Martínez 2016-11-28 01:05:46 -03:00
parent b5786979ab
commit 03070e41c4

View File

@ -1,15 +1,30 @@
irc.bot_commands = {} irc.bot_commands = {}
-- From RFC1459:
-- "Because of IRCs 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) function irc:check_botcmd(msg)
local prefix = irc.config.command_prefix local prefix = irc.config.command_prefix
local nick = irc.conn.nick:lower() local nick = irc.conn.nick
local text = msg.args[2] 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 -- First check for a nick prefix
if nickpart == nick..": " or if nickequals(nickpart, nick)
nickpart == nick..", " then and (suffix == ": " or suffix == ", ") then
self:bot_command(msg, text:sub(#nick + 3)) self:bot_command(msg, text:sub(#nick + 3))
return true return true
-- Then check for the configured prefix -- Then check for the configured prefix