diff --git a/doc/irc.luadoc b/doc/irc.luadoc
index c8c5d8e..58a320a 100644
--- a/doc/irc.luadoc
+++ b/doc/irc.luadoc
@@ -25,8 +25,9 @@
module "irc"
--- Create a new IRC object. Use irc:connect
to connect to a server.
--- @param user Table with fields nick
, username
and realname
.
+-- @param user Table with fields nick
, username
, realname
, and nick_generator
.
-- The nick
field is required.
+-- The nick_generator
field is a fuction that should return a new nick name given the old one.
--
-- @return Returns a new irc
object.
function new(user)
diff --git a/handlers.lua b/handlers.lua
index 6b892f9..4d4a28b 100644
--- a/handlers.lua
+++ b/handlers.lua
@@ -96,6 +96,18 @@ handlers["366"] = function(o, prefix, me, channel, msg)
end
end
+local function handle_bad_nick(o, prefix, x, badnick)
+ o.nick = o.nick_generator(badnick)
+ o.send("NICK %s", o.nick)
+ o.send("USER %s 0 * :%s", o.username, o.realname)
+end
+
+-- ERR_ERRONEOUSNICKNAME
+handlers["432"] = handle_bad_nick
+
+-- ERR_NICKNAMEINUSE
+handlers["433"] = handle_bad_nick
+
--no topic
handlers["331"] = function(o, prefix, me, channel)
o:invoke("OnTopic", channel, nil)
diff --git a/init.lua b/init.lua
index e94aa24..1b43e5b 100644
--- a/init.lua
+++ b/init.lua
@@ -38,6 +38,8 @@ function new(user)
realname = user.realname or "Lua owns";
hooks = {};
track_users = true;
+ nick_generator = user.nick_generator or
+ function(oldnick) error("Nick already in use.") end
}
return setmetatable(o, meta_preconnect)
end