1
0
mirror of https://github.com/ShadowNinja/LuaIRC.git synced 2025-07-20 16:40:26 +02:00

1 Commits

Author SHA1 Message Date
8a31f5d7e7 Allow hooking to any IRC command 2014-02-26 14:24:25 -05:00
4 changed files with 23 additions and 61 deletions

View File

@ -155,7 +155,7 @@ function irc:shutdown()
-- <li><code>username</code> - User username.</li> -- <li><code>username</code> - User username.</li>
-- <li><code>host</code> - User hostname.</li> -- <li><code>host</code> - User hostname.</li>
-- <li><code>realname</code> - User real name.</li> -- <li><code>realname</code> - User real name.</li>
-- <li><code>access</code> - User access, available in channel-oriented callbacks. A table containing boolean fields for each access mode that the server supports. Eg: 'o', and 'v'.</li> -- <li><code>access</code> - User access, available in channel-oriented callbacks. A table containing the boolean fields 'op', 'halfop', and 'voice'.</li>
-- </ul> -- </ul>
-- Apart from <code>nick</code>, fields may be missing. To fill them in, enable user tracking and use irc:whois. -- Apart from <code>nick</code>, fields may be missing. To fill them in, enable user tracking and use irc:whois.
-- @name User -- @name User

View File

@ -86,22 +86,6 @@ handlers["432"] = needNewNick
-- ERR_NICKNAMEINUSE -- ERR_NICKNAMEINUSE
handlers["433"] = needNewNick handlers["433"] = needNewNick
-- RPL_ISUPPORT
handlers["005"] = function(o, prefix, nick, ...)
local list = {...}
local listlen = #list
-- Skip last parameter (info)
for i = 1, listlen - 1 do
local item = list[i]
local pos = item:find("=")
if pos then
o.supports[item:sub(1, pos - 1)] = item:sub(pos + 1)
else
o.supports[item] = true
end
end
end
--NAMES list --NAMES list
handlers["353"] = function(o, user, me, chanType, channel, names) handlers["353"] = function(o, user, me, chanType, channel, names)
if o.track_users then if o.track_users then
@ -109,7 +93,7 @@ handlers["353"] = function(o, user, me, chanType, channel, names)
local users = o.channels[channel].users local users = o.channels[channel].users
for nick in names:gmatch("(%S+)") do for nick in names:gmatch("(%S+)") do
local access, name = parseNick(o, nick) local access, name = parseNick(nick)
users[name] = {access = access} users[name] = {access = access}
end end
end end
@ -161,17 +145,18 @@ handlers["MODE"] = function(o, user, target, modes, ...)
if o.track_users and target ~= o.nick then if o.track_users and target ~= o.nick then
local add = true local add = true
local optList = {...} local optList = {...}
updatePrefixModes(o)
for c in modes:gmatch(".") do for c in modes:gmatch(".") do
if c == "+" then add = true if c == "+" then add = true
elseif c == "-" then add = false elseif c == "-" then add = false
elseif o.modeprefix[c] then elseif c == "o" then
local nick = table.remove(optList, 1) local user = table.remove(optList, 1)
local access = o.channels[target].users[nick].access o.channels[target].users[user].access.op = add
access[o.modeprefix[c]] = add elseif c == "h" then
if c == "o" then access.op = add local user = table.remove(optList, 1)
elseif c == "v" then access.voice = add o.channels[target].users[user].access.halfop = add
end elseif c == "v" then
local user = table.remove(optList, 1)
o.channels[target].users[user].access.voice = add
end end
end end
end end

View File

@ -39,7 +39,6 @@ function new(data)
nickGenerator = data.nickGenerator or defaultNickGenerator; nickGenerator = data.nickGenerator or defaultNickGenerator;
hooks = {}; hooks = {};
track_users = true; track_users = true;
supports = {};
} }
assert(checkNick(o.nick), "Erroneous nickname passed to irc.new") assert(checkNick(o.nick), "Erroneous nickname passed to irc.new")
return setmetatable(o, meta_preconnect) return setmetatable(o, meta_preconnect)

View File

@ -50,51 +50,29 @@ function parse(line)
return prefix, cmd, params return prefix, cmd, params
end end
function parseNick(conn, nick) function parseNick(nick)
local access = {} local access, name = nick:match("^([%+@]*)(.+)$")
updatePrefixModes(conn) return parseAccess(access or ""), name
local namestart = 1
for i = 1, #nick - 1 do
local c = nick:sub(i, i)
if conn.prefixmode[c] then
access[conn.prefixmode[c]] = true
else
namestart = i
break
end
end
access.op = access.o
access.voice = access.v
local name = nick:sub(namestart)
return access, name
end end
function parsePrefix(prefix) function parsePrefix(prefix)
local user = {} local user = {}
if prefix then if prefix then
user.nick, user.username, user.host = prefix:match("^(.+)!(.+)@(.+)$") user.access, user.nick, user.username, user.host = prefix:match("^([%+@]*)(.+)!(.+)@(.+)$")
end end
user.access = parseAccess(user.access or "")
return user return user
end end
function updatePrefixModes(conn) function parseAccess(accessString)
if conn.prefixmode and conn.modeprefix then local access = {op = false, halfop = false, voice = false}
return for c in accessString:gmatch(".") do
end if c == "@" then access.op = true
conn.prefixmode = {} elseif c == "%" then access.halfop = true
conn.modeprefix = {} elseif c == "+" then access.voice = true
if conn.supports.PREFIX then
local modes, prefixes = conn.supports.PREFIX:match("%(([^%)]*)%)(.*)")
for i = 1, #modes do
conn.prefixmode[prefixes:sub(i, i)] = modes:sub(i, i)
conn.modeprefix[ modes:sub(i, i)] = prefixes:sub(i, i)
end end
else
conn.prefixmode['@'] = 'o'
conn.prefixmode['+'] = 'v'
conn.modeprefix['o'] = '@'
conn.modeprefix['v'] = '+'
end end
return access
end end
--mIRC markup scheme (de-facto standard) --mIRC markup scheme (de-facto standard)