mirror of
https://github.com/ShadowNinja/LuaIRC.git
synced 2024-11-16 15:30:30 +01:00
Add support for arbritrary status modes via the ISUPPORT PREFIX value
This commit is contained in:
parent
7e2c85764b
commit
b5646fd64a
|
@ -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 the boolean fields 'op', 'halfop', and 'voice'.</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>
|
||||||
-- </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
|
||||||
|
|
19
handlers.lua
19
handlers.lua
|
@ -109,7 +109,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(nick)
|
local access, name = parseNick(o, nick)
|
||||||
users[name] = {access = access}
|
users[name] = {access = access}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -161,18 +161,17 @@ 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 c == "o" then
|
elseif o.modeprefix[c] then
|
||||||
local user = table.remove(optList, 1)
|
local nick = table.remove(optList, 1)
|
||||||
o.channels[target].users[user].access.op = add
|
local access = o.channels[target].users[nick].access
|
||||||
elseif c == "h" then
|
access[o.modeprefix[c]] = add
|
||||||
local user = table.remove(optList, 1)
|
if c == "o" then access.op = add
|
||||||
o.channels[target].users[user].access.halfop = add
|
elseif c == "v" then access.voice = add
|
||||||
elseif c == "v" then
|
end
|
||||||
local user = table.remove(optList, 1)
|
|
||||||
o.channels[target].users[user].access.voice = add
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
48
util.lua
48
util.lua
|
@ -50,29 +50,51 @@ function parse(line)
|
||||||
return prefix, cmd, params
|
return prefix, cmd, params
|
||||||
end
|
end
|
||||||
|
|
||||||
function parseNick(nick)
|
function parseNick(conn, nick)
|
||||||
local access, name = nick:match("^([%+@]*)(.+)$")
|
local access = {}
|
||||||
return parseAccess(access or ""), name
|
updatePrefixModes(conn)
|
||||||
|
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.access, user.nick, user.username, user.host = prefix:match("^([%+@]*)(.+)!(.+)@(.+)$")
|
user.nick, user.username, user.host = prefix:match("^(.+)!(.+)@(.+)$")
|
||||||
end
|
end
|
||||||
user.access = parseAccess(user.access or "")
|
|
||||||
return user
|
return user
|
||||||
end
|
end
|
||||||
|
|
||||||
function parseAccess(accessString)
|
function updatePrefixModes(conn)
|
||||||
local access = {op = false, halfop = false, voice = false}
|
if conn.prefixmode and conn.modeprefix then
|
||||||
for c in accessString:gmatch(".") do
|
return
|
||||||
if c == "@" then access.op = true
|
end
|
||||||
elseif c == "%" then access.halfop = true
|
conn.prefixmode = {}
|
||||||
elseif c == "+" then access.voice = true
|
conn.modeprefix = {}
|
||||||
end
|
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
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user