mirror of
https://github.com/ShadowNinja/LuaIRC.git
synced 2025-01-09 17:40:29 +01:00
Generate a new nick if it is used or erroneous
This commit is contained in:
parent
bc79606de0
commit
a79c9451f6
@ -25,8 +25,9 @@
|
|||||||
module "irc"
|
module "irc"
|
||||||
|
|
||||||
--- Create a new IRC object. Use <code>irc:connect</code> to connect to a server.
|
--- Create a new IRC object. Use <code>irc:connect</code> to connect to a server.
|
||||||
-- @param user Table with fields <code>nick</code>, <code>username</code> and <code>realname</code>.
|
-- @param user Table with fields <code>nick</code>, <code>username</code>, <code>realname</code>, and <code>nick_generator</code>.
|
||||||
-- The <code>nick</code> field is required.
|
-- The <code>nick</code> field is required.
|
||||||
|
-- The <code>nick_generator</code> field is a fuction that should return a new nick name given the old one.
|
||||||
--
|
--
|
||||||
-- @return Returns a new <code>irc</code> object.
|
-- @return Returns a new <code>irc</code> object.
|
||||||
function new(user)
|
function new(user)
|
||||||
|
12
handlers.lua
12
handlers.lua
@ -96,6 +96,18 @@ handlers["366"] = function(o, prefix, me, channel, msg)
|
|||||||
end
|
end
|
||||||
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
|
--no topic
|
||||||
handlers["331"] = function(o, prefix, me, channel)
|
handlers["331"] = function(o, prefix, me, channel)
|
||||||
o:invoke("OnTopic", channel, nil)
|
o:invoke("OnTopic", channel, nil)
|
||||||
|
2
init.lua
2
init.lua
@ -38,6 +38,8 @@ function new(user)
|
|||||||
realname = user.realname or "Lua owns";
|
realname = user.realname or "Lua owns";
|
||||||
hooks = {};
|
hooks = {};
|
||||||
track_users = true;
|
track_users = true;
|
||||||
|
nick_generator = user.nick_generator or
|
||||||
|
function(oldnick) error("Nick already in use.") end
|
||||||
}
|
}
|
||||||
return setmetatable(o, meta_preconnect)
|
return setmetatable(o, meta_preconnect)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user