mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
Updated IRC Mod
- (Finally) Updated the IRC mod : new dependencies, new LuaIRC module
This commit is contained in:
parent
696f96b0f0
commit
b9d45b2164
@ -45,6 +45,10 @@ minetest.register_chatcommand("irc_names", {
|
|||||||
params = "",
|
params = "",
|
||||||
description = "List the users in IRC.",
|
description = "List the users in IRC.",
|
||||||
func = function(name, params)
|
func = function(name, params)
|
||||||
|
if not irc.connected then
|
||||||
|
minetest.chat_send_player(name, "Not connected to IRC. Use /irc_connect to connect.")
|
||||||
|
return
|
||||||
|
end
|
||||||
local users = { }
|
local users = { }
|
||||||
for k, v in pairs(irc.conn.channels[irc.config.channel].users) do
|
for k, v in pairs(irc.conn.channels[irc.config.channel].users) do
|
||||||
table.insert(users, k)
|
table.insert(users, k)
|
||||||
|
@ -104,6 +104,14 @@ end
|
|||||||
function irc.hooks.channelChat(msg)
|
function irc.hooks.channelChat(msg)
|
||||||
local text = normalize(msg.args[2])
|
local text = normalize(msg.args[2])
|
||||||
|
|
||||||
|
irc:check_botcmd(msg)
|
||||||
|
|
||||||
|
-- Don't let a user impersonate someone else by using the nick "IRC"
|
||||||
|
if msg.user.nick == "IRC" then
|
||||||
|
irc:sendLocal("<IRC@IRC> "..text)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Support multiple servers in a channel better by converting:
|
-- Support multiple servers in a channel better by converting:
|
||||||
-- "<server@IRC> <player> message" into "<player@server> message"
|
-- "<server@IRC> <player> message" into "<player@server> message"
|
||||||
-- "<server@IRC> *** player joined/left the game" into "*** player joined/left server"
|
-- "<server@IRC> *** player joined/left the game" into "*** player joined/left server"
|
||||||
@ -117,8 +125,6 @@ function irc.hooks.channelChat(msg)
|
|||||||
local foundaction, _, actionnick, actionmessage =
|
local foundaction, _, actionnick, actionmessage =
|
||||||
text:find("^%* ([^%s]+) (.*)$")
|
text:find("^%* ([^%s]+) (.*)$")
|
||||||
|
|
||||||
irc:check_botcmd(msg)
|
|
||||||
|
|
||||||
if text:sub(1, 5) == "[off]" then
|
if text:sub(1, 5) == "[off]" then
|
||||||
return
|
return
|
||||||
elseif foundchat then
|
elseif foundchat then
|
||||||
|
@ -17,9 +17,8 @@ if not rawget(_G,"jit") and package.config:sub(1, 1) == "/" then
|
|||||||
package.path = package.path..
|
package.path = package.path..
|
||||||
";/usr/share/lua/5.1/?.lua"..
|
";/usr/share/lua/5.1/?.lua"..
|
||||||
";/usr/share/lua/5.1/?/init.lua"
|
";/usr/share/lua/5.1/?/init.lua"
|
||||||
package.cpath = package.cpath..
|
package.cpath = package.cpath..
|
||||||
-- ";/usr/lib/lua/5.1/?.so"
|
";/usr/lib/lua/5.1/?.so"
|
||||||
";/usr/lib/x86_64-linux-gnu/lua/5.1/?.so"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
irc = {
|
irc = {
|
||||||
|
2
mods/irc/irc/.gitignore
vendored
2
mods/irc/irc/.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
|
/gh-pages/
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
15
mods/irc/irc/.travis.yml
Normal file
15
mods/irc/irc/.travis.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
language: lua
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
email: false
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- secure: "kFhU+DZjhq/KbDt0DIDWnlskXMa12miNelmhhy30fQGgVIdiibDGKMNGyLahWp8CnPu1DARb5AZWK2TDfARdnURT2pgcsG83M7bYIY6cR647BWjL7oAhJ6CYEzTWJTBjeUjpN/o4vIgfXSDR0c7vboDi7Xz8ilfrBujPL2Oi/og="
|
||||||
|
|
||||||
|
install:
|
||||||
|
- sudo apt-get -y update
|
||||||
|
- sudo apt-get -y install lua5.1 luadoc
|
||||||
|
|
||||||
|
script:
|
||||||
|
- ./push-luadoc.sh
|
@ -1,7 +1,8 @@
|
|||||||
|
[![Build Status](https://travis-ci.org/JakobOvrum/LuaIRC.svg?branch=master)](https://travis-ci.org/JakobOvrum/LuaIRC)
|
||||||
LuaIRC
|
LuaIRC
|
||||||
============
|
============
|
||||||
|
|
||||||
IRC library for Lua.
|
IRC client library for Lua.
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
-------------
|
-------------
|
||||||
|
@ -36,26 +36,26 @@ end
|
|||||||
function meta:sendChat(target, msg)
|
function meta:sendChat(target, msg)
|
||||||
-- Split the message into segments if it includes newlines.
|
-- Split the message into segments if it includes newlines.
|
||||||
for line in msg:gmatch("([^\r\n]+)") do
|
for line in msg:gmatch("([^\r\n]+)") do
|
||||||
self:queue(irc.msgs.privmsg(verify(target, 3), line))
|
self:queue(msgs.privmsg(verify(target, 3), line))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function meta:sendNotice(target, msg)
|
function meta:sendNotice(target, msg)
|
||||||
-- Split the message into segments if it includes newlines.
|
-- Split the message into segments if it includes newlines.
|
||||||
for line in msg:gmatch("([^\r\n]+)") do
|
for line in msg:gmatch("([^\r\n]+)") do
|
||||||
self:queue(irc.msgs.notice(verify(target, 3), line))
|
self:queue(msgs.notice(verify(target, 3), line))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function meta:join(channel, key)
|
function meta:join(channel, key)
|
||||||
self:queue(irc.msgs.join(
|
self:queue(msgs.join(
|
||||||
verify(channel, 3),
|
verify(channel, 3),
|
||||||
key and verify(key, 3) or nil))
|
key and verify(key, 3) or nil))
|
||||||
end
|
end
|
||||||
|
|
||||||
function meta:part(channel, reason)
|
function meta:part(channel, reason)
|
||||||
channel = verify(channel, 3)
|
channel = verify(channel, 3)
|
||||||
self:queue(irc.msgs.part(channel, reason))
|
self:queue(msgs.part(channel, reason))
|
||||||
if self.track_users then
|
if self.track_users then
|
||||||
self.channels[channel] = nil
|
self.channels[channel] = nil
|
||||||
end
|
end
|
||||||
@ -85,6 +85,8 @@ function meta:setMode(t)
|
|||||||
mode = table.concat{mode, "-", verify(rem, 3)}
|
mode = table.concat{mode, "-", verify(rem, 3)}
|
||||||
end
|
end
|
||||||
|
|
||||||
self:queue(irc.msgs.mode(verify(target, 3), mode))
|
self:queue(msgs.mode(verify(target, 3), mode))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return meta
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
--- LuaIRC is a low-level IRC library for Lua.
|
--- LuaIRC is a low-level IRC library for Lua.
|
||||||
-- All functions raise Lua exceptions on error.
|
-- All functions raise Lua exceptions on error.
|
||||||
--
|
--
|
||||||
-- Use <code>new</code> to create a new IRC object.<br/>
|
-- Use <code>new</code> to create a new Connection object.<br/>
|
||||||
-- Example:<br/><br/>
|
-- Example:<br/><br/>
|
||||||
--<code>
|
--<code>
|
||||||
--require "irc"<br/>
|
--require "irc"<br/>
|
||||||
@ -24,11 +24,12 @@
|
|||||||
|
|
||||||
module "irc"
|
module "irc"
|
||||||
|
|
||||||
--- Create a new IRC object. Use <code>irc:connect</code> to connect to a server.
|
--- Create a new Connection 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> and <code>realname</code>.
|
||||||
-- The <code>nick</code> field is required.
|
-- The <code>nick</code> field is required.
|
||||||
--
|
--
|
||||||
-- @return Returns a new <code>irc</code> object.
|
-- @return Returns a new Connection object.
|
||||||
|
-- @see Connection
|
||||||
function new(user)
|
function new(user)
|
||||||
|
|
||||||
--- Hook a function to an event.
|
--- Hook a function to an event.
|
||||||
@ -46,10 +47,10 @@ function irc:unhook(name, id)
|
|||||||
--- Connect <code>irc</code> to an IRC server.
|
--- Connect <code>irc</code> to an IRC server.
|
||||||
-- @param host Host address.
|
-- @param host Host address.
|
||||||
-- @param port Server port. [default 6667]
|
-- @param port Server port. [default 6667]
|
||||||
function irc:connect(server, port)
|
function irc:connect(host, port)
|
||||||
|
|
||||||
-- @param table Table of connection details
|
-- @param table Table of connection details
|
||||||
-- @see Connection
|
-- @see ConnectOptions
|
||||||
function irc:connect(table)
|
function irc:connect(table)
|
||||||
|
|
||||||
--- Disconnect <code>irc</code> from the server.
|
--- Disconnect <code>irc</code> from the server.
|
||||||
@ -116,16 +117,26 @@ function irc:handle(msg)
|
|||||||
function irc:shutdown()
|
function irc:shutdown()
|
||||||
|
|
||||||
--- Table with connection information.
|
--- Table with connection information.
|
||||||
-- <ul>
|
-- @name ConnectOptions
|
||||||
-- <li><code>host</code> - Server host name.</li>
|
-- @class table
|
||||||
-- <li><code>port</code> - Server port. [defaults to <code>6667</code>]</li>
|
-- @field host Server host name.
|
||||||
-- <li><code>timeout</code> - Connect timeout. [defaults to <code>30</code>]</li>
|
-- @field port Server port. [defaults to <code>6667</code>]
|
||||||
-- <li><code>password</code> - Server password.</li>
|
-- @field timeout Connect timeout. [defaults to <code>30</code>]
|
||||||
-- <li><code>secure</code> - Boolean to enable TLS connection, pass a params table (described, [luasec]) to control</li>
|
-- @field password Server password.
|
||||||
-- </ul>
|
-- @field secure Boolean to enable TLS connection, pass a params table (described, [luasec]) to control
|
||||||
-- [luasec]: http://www.inf.puc-rio.br/~brunoos/luasec/reference.html
|
-- [luasec]: http://www.inf.puc-rio.br/~brunoos/luasec/reference.html
|
||||||
|
|
||||||
|
--- Class representing a connection.
|
||||||
-- @name Connection
|
-- @name Connection
|
||||||
-- @class table
|
-- @class table
|
||||||
|
-- @field authed Boolean indicating whether the connection has completed registration.
|
||||||
|
-- @field connected Whether the connection is currently connected.
|
||||||
|
-- @field motd The server's message of the day. Can be nil.
|
||||||
|
-- @field nick The current nickname.
|
||||||
|
-- @field realname The real name sent to the server.
|
||||||
|
-- @field username The username/ident sent to the server.
|
||||||
|
-- @field socket Raw socket used by the library.
|
||||||
|
-- @field supports What the server claims to support in it's ISUPPORT message.
|
||||||
|
|
||||||
--- Class representing an IRC message.
|
--- Class representing an IRC message.
|
||||||
-- @name Message
|
-- @name Message
|
||||||
@ -145,8 +156,8 @@ function irc:shutdown()
|
|||||||
--- List of hooks you can use with irc:hook.
|
--- List of hooks you can use with irc:hook.
|
||||||
-- The parameter list describes the parameters passed to the callback function.
|
-- The parameter list describes the parameters passed to the callback function.
|
||||||
-- <ul>
|
-- <ul>
|
||||||
-- <li><code>PreRegister(connection)</code>Useful for CAP commands and SASL.</li>
|
-- <li><code>PreRegister()</code> - Usefull for requesting capabilities.</li>
|
||||||
-- <li><code>OnRaw(line) - (any non false/nil return value assumes line handled and will not be further processed)</code></li>
|
-- <li><code>OnRaw(line)</code> - Any non false/nil return value assumes line handled and will not be further processed.</li>
|
||||||
-- <li><code>OnSend(line)</code></li>
|
-- <li><code>OnSend(line)</code></li>
|
||||||
-- <li><code>OnDisconnect(message, errorOccurred)</code></li>
|
-- <li><code>OnDisconnect(message, errorOccurred)</code></li>
|
||||||
-- <li><code>OnChat(user, channel, message)</code></li>
|
-- <li><code>OnChat(user, channel, message)</code></li>
|
||||||
@ -162,7 +173,10 @@ function irc:shutdown()
|
|||||||
-- <li><code>OnUserMode(modes)</code></li>
|
-- <li><code>OnUserMode(modes)</code></li>
|
||||||
-- <li><code>OnChannelMode(user, channel, modes)</code></li>
|
-- <li><code>OnChannelMode(user, channel, modes)</code></li>
|
||||||
-- <li><code>OnModeChange(user, target, modes, ...)</code>* ('...' contains mode options such as banmasks)</li>
|
-- <li><code>OnModeChange(user, target, modes, ...)</code>* ('...' contains mode options such as banmasks)</li>
|
||||||
-- <li><code>DoX(msg)</code>'X' is any IRC command or numeric with the first letter capitalized (eg, DoPing and Do001)</li>
|
-- <li><code>OnCapabilityList(caps)</code></li>
|
||||||
|
-- <li><code>OnCapabilityAvailable(cap, value)</code> Called only when a capability becomes available or changes.</li>
|
||||||
|
-- <li><code>OnCapabilitySet(cap, enabled)</code>*</li>
|
||||||
|
-- <li><code>DoX(msg)</code>* - 'X' is any IRC command or numeric with the first letter capitalized (eg, DoPing and Do001)</li>
|
||||||
-- </ul>
|
-- </ul>
|
||||||
-- * Event also invoked for yourself.
|
-- * Event also invoked for yourself.
|
||||||
-- † Channel passed only when user tracking is enabled
|
-- † Channel passed only when user tracking is enabled
|
||||||
|
@ -1,10 +1,72 @@
|
|||||||
local irc = require("irc.main")
|
local util = require("irc.util")
|
||||||
|
local msgs = require("irc.messages")
|
||||||
|
local Message = msgs.Message
|
||||||
|
|
||||||
irc.handlers = {}
|
local handlers = {}
|
||||||
local handlers = irc.handlers
|
|
||||||
|
|
||||||
handlers["PING"] = function(conn, msg)
|
handlers["PING"] = function(conn, msg)
|
||||||
conn:send(irc.Message({command="PONG", args=msg.args}))
|
conn:send(Message({command="PONG", args=msg.args}))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function requestWanted(conn, wanted)
|
||||||
|
local args = {}
|
||||||
|
for cap, value in pairs(wanted) do
|
||||||
|
if type(value) == "string" then
|
||||||
|
cap = cap .. "=" .. value
|
||||||
|
end
|
||||||
|
if not conn.capabilities[cap] then
|
||||||
|
table.insert(args, cap)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
conn:queue(Message({
|
||||||
|
command = "CAP",
|
||||||
|
args = {"REQ", table.concat(args, " ")}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
handlers["CAP"] = function(conn, msg)
|
||||||
|
local cmd = msg.args[2]
|
||||||
|
if not cmd then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if cmd == "LS" then
|
||||||
|
local list = msg.args[3]
|
||||||
|
local last = false
|
||||||
|
if list == "*" then
|
||||||
|
list = msg.args[4]
|
||||||
|
else
|
||||||
|
last = true
|
||||||
|
end
|
||||||
|
local avail = conn.availableCapabilities
|
||||||
|
local wanted = conn.wantedCapabilities
|
||||||
|
for item in list:gmatch("(%S+)") do
|
||||||
|
local eq = item:find("=", 1, true)
|
||||||
|
local k, v
|
||||||
|
if eq then
|
||||||
|
k, v = item:sub(1, eq - 1), item:sub(eq + 1)
|
||||||
|
else
|
||||||
|
k, v = item, true
|
||||||
|
end
|
||||||
|
if not avail[k] or avail[k] ~= v then
|
||||||
|
wanted[k] = conn:invoke("OnCapabilityAvailable", k, v)
|
||||||
|
end
|
||||||
|
avail[k] = v
|
||||||
|
end
|
||||||
|
if last then
|
||||||
|
if next(wanted) then
|
||||||
|
requestWanted(conn, wanted)
|
||||||
|
end
|
||||||
|
conn:invoke("OnCapabilityList", conn.availableCapabilities)
|
||||||
|
end
|
||||||
|
elseif cmd == "ACK" then
|
||||||
|
for item in msg.args[3]:gmatch("(%S+)") do
|
||||||
|
local enabled = (item:sub(1, 1) ~= "-")
|
||||||
|
local name = enabled and item or item:sub(2)
|
||||||
|
conn:invoke("OnCapabilitySet", name, enabled)
|
||||||
|
conn.capabilities[name] = enabled
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
handlers["001"] = function(conn, msg)
|
handlers["001"] = function(conn, msg)
|
||||||
@ -16,7 +78,6 @@ handlers["PRIVMSG"] = function(conn, msg)
|
|||||||
conn:invoke("OnChat", msg.user, msg.args[1], msg.args[2])
|
conn:invoke("OnChat", msg.user, msg.args[1], msg.args[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
handlers["NOTICE"] = function(conn, msg)
|
handlers["NOTICE"] = function(conn, msg)
|
||||||
conn:invoke("OnNotice", msg.user, msg.args[1], msg.args[2])
|
conn:invoke("OnNotice", msg.user, msg.args[1], msg.args[2])
|
||||||
end
|
end
|
||||||
@ -71,13 +132,13 @@ handlers["NICK"] = function(conn, msg)
|
|||||||
conn:invoke("NickChange", msg.user, newNick)
|
conn:invoke("NickChange", msg.user, newNick)
|
||||||
end
|
end
|
||||||
if msg.user.nick == conn.nick then
|
if msg.user.nick == conn.nick then
|
||||||
conn.nick = newnick
|
conn.nick = newNick
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function needNewNick(conn, msg)
|
local function needNewNick(conn, msg)
|
||||||
local newnick = conn.nickGenerator(msg.args[2])
|
local newnick = conn.nickGenerator(msg.args[2])
|
||||||
conn:queue(msgs.nick(newnick))
|
conn:queue(irc.msgs.nick(newnick))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ERR_ERRONEUSNICKNAME (Misspelt but remains for historical reasons)
|
-- ERR_ERRONEUSNICKNAME (Misspelt but remains for historical reasons)
|
||||||
@ -86,6 +147,13 @@ handlers["432"] = needNewNick
|
|||||||
-- ERR_NICKNAMEINUSE
|
-- ERR_NICKNAMEINUSE
|
||||||
handlers["433"] = needNewNick
|
handlers["433"] = needNewNick
|
||||||
|
|
||||||
|
-- ERR_UNAVAILRESOURCE
|
||||||
|
handlers["437"] = function(conn, msg)
|
||||||
|
if not conn.authed then
|
||||||
|
needNewNick(conn, msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- RPL_ISUPPORT
|
-- RPL_ISUPPORT
|
||||||
handlers["005"] = function(conn, msg)
|
handlers["005"] = function(conn, msg)
|
||||||
local arglen = #msg.args
|
local arglen = #msg.args
|
||||||
@ -122,7 +190,7 @@ handlers["353"] = function(conn, msg)
|
|||||||
|
|
||||||
local users = conn.channels[channel].users
|
local users = conn.channels[channel].users
|
||||||
for nick in names:gmatch("(%S+)") do
|
for nick in names:gmatch("(%S+)") do
|
||||||
local access, name = irc.parseNick(conn, nick)
|
local access, name = util.parseNick(conn, nick)
|
||||||
users[name] = {access = access}
|
users[name] = {access = access}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -179,7 +247,7 @@ handlers["MODE"] = function(conn, msg)
|
|||||||
if conn.track_users and target ~= conn.nick then
|
if conn.track_users and target ~= conn.nick then
|
||||||
local add = true
|
local add = true
|
||||||
local argNum = 1
|
local argNum = 1
|
||||||
irc.updatePrefixModes(conn)
|
util.updatePrefixModes(conn)
|
||||||
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
|
||||||
@ -205,3 +273,5 @@ handlers["ERROR"] = function(conn, msg)
|
|||||||
error(msg.args[1], 3)
|
error(msg.args[1], 3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return handlers
|
||||||
|
|
||||||
|
@ -1,9 +1,257 @@
|
|||||||
|
local socket = require("socket")
|
||||||
|
local util = require("irc.util")
|
||||||
|
local handlers = require("irc.handlers")
|
||||||
|
local msgs = require("irc.messages")
|
||||||
|
local Message = msgs.Message
|
||||||
|
|
||||||
local irc = require("irc.main")
|
local meta = {}
|
||||||
require("irc.util")
|
meta.__index = meta
|
||||||
require("irc.asyncoperations")
|
|
||||||
require("irc.handlers")
|
|
||||||
require("irc.messages")
|
|
||||||
|
|
||||||
return irc
|
|
||||||
|
for k, v in pairs(require("irc.asyncoperations")) do
|
||||||
|
meta[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
local meta_preconnect = {}
|
||||||
|
function meta_preconnect.__index(o, k)
|
||||||
|
local v = rawget(meta_preconnect, k)
|
||||||
|
|
||||||
|
if v == nil and meta[k] ~= nil then
|
||||||
|
error(("field '%s' is not accessible before connecting"):format(k), 2)
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
meta.connected = true
|
||||||
|
meta_preconnect.connected = false
|
||||||
|
|
||||||
|
function new(data)
|
||||||
|
local o = {
|
||||||
|
nick = assert(data.nick, "Field 'nick' is required");
|
||||||
|
username = data.username or "lua";
|
||||||
|
realname = data.realname or "Lua owns";
|
||||||
|
nickGenerator = data.nickGenerator or util.defaultNickGenerator;
|
||||||
|
hooks = {};
|
||||||
|
track_users = true;
|
||||||
|
supports = {};
|
||||||
|
messageQueue = {};
|
||||||
|
lastThought = 0;
|
||||||
|
recentMessages = 0;
|
||||||
|
availableCapabilities = {};
|
||||||
|
wantedCapabilities = {};
|
||||||
|
capabilities = {};
|
||||||
|
}
|
||||||
|
assert(util.checkNick(o.nick), "Erroneous nickname passed to irc.new")
|
||||||
|
return setmetatable(o, meta_preconnect)
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta:hook(name, id, f)
|
||||||
|
f = f or id
|
||||||
|
self.hooks[name] = self.hooks[name] or {}
|
||||||
|
self.hooks[name][id] = f
|
||||||
|
return id or f
|
||||||
|
end
|
||||||
|
meta_preconnect.hook = meta.hook
|
||||||
|
|
||||||
|
|
||||||
|
function meta:unhook(name, id)
|
||||||
|
local hooks = self.hooks[name]
|
||||||
|
|
||||||
|
assert(hooks, "no hooks exist for this event")
|
||||||
|
assert(hooks[id], "hook ID not found")
|
||||||
|
|
||||||
|
hooks[id] = nil
|
||||||
|
end
|
||||||
|
meta_preconnect.unhook = meta.unhook
|
||||||
|
|
||||||
|
function meta:invoke(name, ...)
|
||||||
|
local hooks = self.hooks[name]
|
||||||
|
if hooks then
|
||||||
|
for id, f in pairs(hooks) do
|
||||||
|
local ret = f(...)
|
||||||
|
if ret then
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta_preconnect:connect(_host, _port)
|
||||||
|
local host, port, password, secure, timeout
|
||||||
|
|
||||||
|
if type(_host) == "table" then
|
||||||
|
host = _host.host
|
||||||
|
port = _host.port
|
||||||
|
timeout = _host.timeout
|
||||||
|
password = _host.password
|
||||||
|
secure = _host.secure
|
||||||
|
else
|
||||||
|
host = _host
|
||||||
|
port = _port
|
||||||
|
end
|
||||||
|
|
||||||
|
host = host or error("host name required to connect", 2)
|
||||||
|
port = port or 6667
|
||||||
|
|
||||||
|
local s = socket.tcp()
|
||||||
|
|
||||||
|
s:settimeout(timeout or 30)
|
||||||
|
assert(s:connect(host, port))
|
||||||
|
|
||||||
|
if secure then
|
||||||
|
local work, ssl = pcall(require, "ssl")
|
||||||
|
if not work then
|
||||||
|
error("LuaSec required for secure connections", 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local params
|
||||||
|
if type(secure) == "table" then
|
||||||
|
params = secure
|
||||||
|
else
|
||||||
|
params = {mode = "client", protocol = "tlsv1"}
|
||||||
|
end
|
||||||
|
|
||||||
|
s = ssl.wrap(s, params)
|
||||||
|
local success, errmsg = s:dohandshake()
|
||||||
|
if not success then
|
||||||
|
error(("could not make secure connection: %s"):format(errmsg), 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.socket = s
|
||||||
|
setmetatable(self, meta)
|
||||||
|
|
||||||
|
self:invoke("PreRegister", self)
|
||||||
|
|
||||||
|
if password then
|
||||||
|
self:queue(Message({command="PASS", args={password}}))
|
||||||
|
end
|
||||||
|
|
||||||
|
self:queue(msgs.nick(self.nick))
|
||||||
|
self:queue(Message({command="USER", args={self.username, "0", "*", self.realname}}))
|
||||||
|
|
||||||
|
self.channels = {}
|
||||||
|
|
||||||
|
s:settimeout(0)
|
||||||
|
|
||||||
|
repeat
|
||||||
|
self:think()
|
||||||
|
socket.sleep(0.1)
|
||||||
|
until self.authed
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta:disconnect(message)
|
||||||
|
message = message or "Bye!"
|
||||||
|
|
||||||
|
self:invoke("OnDisconnect", message, false)
|
||||||
|
self:send(msgs.quit(message))
|
||||||
|
|
||||||
|
self:shutdown()
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta:shutdown()
|
||||||
|
self.socket:close()
|
||||||
|
setmetatable(self, meta_preconnect)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getline(self, errlevel)
|
||||||
|
local line, err = self.socket:receive("*l")
|
||||||
|
|
||||||
|
if not line and err ~= "timeout" and err ~= "wantread" then
|
||||||
|
self:invoke("OnDisconnect", err, true)
|
||||||
|
self:shutdown()
|
||||||
|
error(err, errlevel)
|
||||||
|
end
|
||||||
|
|
||||||
|
return line
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta:think()
|
||||||
|
while true do
|
||||||
|
local line = getline(self, 3)
|
||||||
|
if line and #line > 0 then
|
||||||
|
if not self:invoke("OnRaw", line) then
|
||||||
|
self:handle(Message({raw=line}))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle outgoing message queue
|
||||||
|
local diff = socket.gettime() - self.lastThought
|
||||||
|
self.recentMessages = self.recentMessages - (diff * 2)
|
||||||
|
if self.recentMessages < 0 then
|
||||||
|
self.recentMessages = 0
|
||||||
|
end
|
||||||
|
for i = 1, #self.messageQueue do
|
||||||
|
if self.recentMessages > 4 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
self:send(table.remove(self.messageQueue, 1))
|
||||||
|
self.recentMessages = self.recentMessages + 1
|
||||||
|
end
|
||||||
|
self.lastThought = socket.gettime()
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta:handle(msg)
|
||||||
|
local handler = handlers[msg.command]
|
||||||
|
if handler then
|
||||||
|
handler(self, msg)
|
||||||
|
end
|
||||||
|
self:invoke("Do" .. util.capitalize(msg.command), msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
local whoisHandlers = {
|
||||||
|
["311"] = "userinfo";
|
||||||
|
["312"] = "node";
|
||||||
|
["319"] = "channels";
|
||||||
|
["330"] = "account"; -- Freenode
|
||||||
|
["307"] = "registered"; -- Unreal
|
||||||
|
}
|
||||||
|
|
||||||
|
function meta:whois(nick)
|
||||||
|
self:send(msgs.whois(nick))
|
||||||
|
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local line = getline(self, 3)
|
||||||
|
if line then
|
||||||
|
local msg = Message({raw=line})
|
||||||
|
|
||||||
|
local handler = whoisHandlers[msg.command]
|
||||||
|
if handler then
|
||||||
|
result[handler] = msg.args
|
||||||
|
elseif msg.command == "318" then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
self:handle(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if result.account then
|
||||||
|
result.account = result.account[3]
|
||||||
|
elseif result.registered then
|
||||||
|
result.account = result.registered[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function meta:topic(channel)
|
||||||
|
self:queue(msgs.topic(channel))
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
new = new;
|
||||||
|
|
||||||
|
Message = Message;
|
||||||
|
msgs = msgs;
|
||||||
|
|
||||||
|
color = util.color;
|
||||||
|
bold = util.bold;
|
||||||
|
underline = util.underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,241 +0,0 @@
|
|||||||
local socket = require "socket"
|
|
||||||
|
|
||||||
-- Module table
|
|
||||||
local irc = {}
|
|
||||||
|
|
||||||
local meta = {}
|
|
||||||
meta.__index = meta
|
|
||||||
irc.meta = meta
|
|
||||||
|
|
||||||
local meta_preconnect = {}
|
|
||||||
function meta_preconnect.__index(o, k)
|
|
||||||
local v = rawget(meta_preconnect, k)
|
|
||||||
|
|
||||||
if not v and meta[k] then
|
|
||||||
error(("field '%s' is not accessible before connecting"):format(k), 2)
|
|
||||||
end
|
|
||||||
return v
|
|
||||||
end
|
|
||||||
|
|
||||||
function irc.new(data)
|
|
||||||
local o = {
|
|
||||||
nick = assert(data.nick, "Field 'nick' is required");
|
|
||||||
username = data.username or "lua";
|
|
||||||
realname = data.realname or "Lua owns";
|
|
||||||
nickGenerator = data.nickGenerator or irc.defaultNickGenerator;
|
|
||||||
hooks = {};
|
|
||||||
track_users = true;
|
|
||||||
supports = {};
|
|
||||||
messageQueue = {};
|
|
||||||
lastThought = 0;
|
|
||||||
recentMessages = 0;
|
|
||||||
}
|
|
||||||
assert(irc.checkNick(o.nick), "Erroneous nickname passed to irc.new")
|
|
||||||
return setmetatable(o, meta_preconnect)
|
|
||||||
end
|
|
||||||
|
|
||||||
function meta:hook(name, id, f)
|
|
||||||
f = f or id
|
|
||||||
self.hooks[name] = self.hooks[name] or {}
|
|
||||||
self.hooks[name][id] = f
|
|
||||||
return id or f
|
|
||||||
end
|
|
||||||
meta_preconnect.hook = meta.hook
|
|
||||||
|
|
||||||
|
|
||||||
function meta:unhook(name, id)
|
|
||||||
local hooks = self.hooks[name]
|
|
||||||
|
|
||||||
assert(hooks, "no hooks exist for this event")
|
|
||||||
assert(hooks[id], "hook ID not found")
|
|
||||||
|
|
||||||
hooks[id] = nil
|
|
||||||
end
|
|
||||||
meta_preconnect.unhook = meta.unhook
|
|
||||||
|
|
||||||
function meta:invoke(name, ...)
|
|
||||||
local hooks = self.hooks[name]
|
|
||||||
if hooks then
|
|
||||||
for id, f in pairs(hooks) do
|
|
||||||
if f(...) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function meta_preconnect:connect(_host, _port)
|
|
||||||
local host, port, password, secure, timeout
|
|
||||||
|
|
||||||
if type(_host) == "table" then
|
|
||||||
host = _host.host
|
|
||||||
port = _host.port
|
|
||||||
timeout = _host.timeout
|
|
||||||
password = _host.password
|
|
||||||
secure = _host.secure
|
|
||||||
else
|
|
||||||
host = _host
|
|
||||||
port = _port
|
|
||||||
end
|
|
||||||
|
|
||||||
host = host or error("host name required to connect", 2)
|
|
||||||
port = port or 6667
|
|
||||||
|
|
||||||
local s = socket.tcp()
|
|
||||||
|
|
||||||
s:settimeout(timeout or 30)
|
|
||||||
assert(s:connect(host, port))
|
|
||||||
|
|
||||||
if secure then
|
|
||||||
local work, ssl = pcall(require, "ssl")
|
|
||||||
if not work then
|
|
||||||
error("LuaSec required for secure connections", 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
local params
|
|
||||||
if type(secure) == "table" then
|
|
||||||
params = secure
|
|
||||||
else
|
|
||||||
params = {mode = "client", protocol = "tlsv1"}
|
|
||||||
end
|
|
||||||
|
|
||||||
s = ssl.wrap(s, params)
|
|
||||||
local success, errmsg = s:dohandshake()
|
|
||||||
if not success then
|
|
||||||
error(("could not make secure connection: %s"):format(errmsg), 2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.socket = s
|
|
||||||
setmetatable(self, meta)
|
|
||||||
|
|
||||||
self:queue(irc.Message({command="CAP", args={"REQ", "multi-prefix"}}))
|
|
||||||
|
|
||||||
self:invoke("PreRegister", self)
|
|
||||||
self:queue(irc.Message({command="CAP", args={"END"}}))
|
|
||||||
|
|
||||||
if password then
|
|
||||||
self:queue(irc.Message({command="PASS", args={password}}))
|
|
||||||
end
|
|
||||||
|
|
||||||
self:queue(irc.msgs.nick(self.nick))
|
|
||||||
self:queue(irc.Message({command="USER", args={self.username, "0", "*", self.realname}}))
|
|
||||||
|
|
||||||
self.channels = {}
|
|
||||||
|
|
||||||
s:settimeout(0)
|
|
||||||
|
|
||||||
repeat
|
|
||||||
self:think()
|
|
||||||
socket.sleep(0.1)
|
|
||||||
until self.authed
|
|
||||||
end
|
|
||||||
|
|
||||||
function meta:disconnect(message)
|
|
||||||
message = message or "Bye!"
|
|
||||||
|
|
||||||
self:invoke("OnDisconnect", message, false)
|
|
||||||
self:send(irc.msgs.quit(message))
|
|
||||||
|
|
||||||
self:shutdown()
|
|
||||||
end
|
|
||||||
|
|
||||||
function meta:shutdown()
|
|
||||||
self.socket:close()
|
|
||||||
setmetatable(self, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function getline(self, errlevel)
|
|
||||||
local line, err = self.socket:receive("*l")
|
|
||||||
|
|
||||||
if not line and err ~= "timeout" and err ~= "wantread" then
|
|
||||||
self:invoke("OnDisconnect", err, true)
|
|
||||||
self:shutdown()
|
|
||||||
error(err, errlevel)
|
|
||||||
end
|
|
||||||
|
|
||||||
return line
|
|
||||||
end
|
|
||||||
|
|
||||||
function meta:think()
|
|
||||||
while true do
|
|
||||||
local line = getline(self, 3)
|
|
||||||
if line and #line > 0 then
|
|
||||||
if not self:invoke("OnRaw", line) then
|
|
||||||
self:handle(irc.Message({raw=line}))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Handle outgoing message queue
|
|
||||||
local diff = socket.gettime() - self.lastThought
|
|
||||||
self.recentMessages = self.recentMessages - (diff * 2)
|
|
||||||
if self.recentMessages < 0 then
|
|
||||||
self.recentMessages = 0
|
|
||||||
end
|
|
||||||
for i = 1, #self.messageQueue do
|
|
||||||
if self.recentMessages > 4 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
self:send(table.remove(self.messageQueue, 1))
|
|
||||||
self.recentMessages = self.recentMessages + 1
|
|
||||||
end
|
|
||||||
self.lastThought = socket.gettime()
|
|
||||||
end
|
|
||||||
|
|
||||||
local handlers = rawget(_G,"handlers")
|
|
||||||
|
|
||||||
function meta:handle(msg)
|
|
||||||
local handler = irc.handlers[msg.command]
|
|
||||||
if handler then
|
|
||||||
handler(self, msg)
|
|
||||||
end
|
|
||||||
self:invoke("Do" .. irc.capitalize(msg.command), msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
local whoisHandlers = {
|
|
||||||
["311"] = "userinfo";
|
|
||||||
["312"] = "node";
|
|
||||||
["319"] = "channels";
|
|
||||||
["330"] = "account"; -- Freenode
|
|
||||||
["307"] = "registered"; -- Unreal
|
|
||||||
}
|
|
||||||
|
|
||||||
function meta:whois(nick)
|
|
||||||
self:send(irc.msgs.whois(nick))
|
|
||||||
|
|
||||||
local result = {}
|
|
||||||
|
|
||||||
while true do
|
|
||||||
local line = getline(self, 3)
|
|
||||||
if line then
|
|
||||||
local msg = irc.Message({raw=line})
|
|
||||||
|
|
||||||
local handler = whoisHandlers[msg.command]
|
|
||||||
if handler then
|
|
||||||
result[handler] = msg.args
|
|
||||||
elseif msg.command == "318" then
|
|
||||||
break
|
|
||||||
else
|
|
||||||
self:handle(msg)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if result.account then
|
|
||||||
result.account = result.account[3]
|
|
||||||
elseif result.registered then
|
|
||||||
result.account = result.registered[2]
|
|
||||||
end
|
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
function meta:topic(channel)
|
|
||||||
self:queue(irc.msgs.topic(channel))
|
|
||||||
end
|
|
||||||
|
|
||||||
return irc
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
|||||||
local irc = require("irc.main")
|
|
||||||
|
|
||||||
irc.msgs = {}
|
-- Module table
|
||||||
local msgs = irc.msgs
|
local m = {}
|
||||||
|
|
||||||
local msg_meta = {}
|
local msg_meta = {}
|
||||||
msg_meta.__index = msg_meta
|
msg_meta.__index = msg_meta
|
||||||
|
|
||||||
function irc.Message(opts)
|
local function Message(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
setmetatable(opts, msg_meta)
|
setmetatable(opts, msg_meta)
|
||||||
if opts.raw then
|
if opts.raw then
|
||||||
@ -15,6 +14,8 @@ function irc.Message(opts)
|
|||||||
return opts
|
return opts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
m.Message = Message
|
||||||
|
|
||||||
local tag_escapes = {
|
local tag_escapes = {
|
||||||
[";"] = "\\:",
|
[";"] = "\\:",
|
||||||
[" "] = "\\s",
|
[" "] = "\\s",
|
||||||
@ -116,85 +117,91 @@ function msg_meta:fromRFC1459(line)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.privmsg(to, text)
|
function m.privmsg(to, text)
|
||||||
return irc.Message({command="PRIVMSG", args={to, text}})
|
return Message({command="PRIVMSG", args={to, text}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.notice(to, text)
|
function m.notice(to, text)
|
||||||
return irc.Message({command="NOTICE", args={to, text}})
|
return Message({command="NOTICE", args={to, text}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.action(to, text)
|
function m.action(to, text)
|
||||||
return irc.Message({command="PRIVMSG", args={to, ("\x01ACTION %s\x01"):format(text)}})
|
return Message({command="PRIVMSG", args={to, ("\x01ACTION %s\x01"):format(text)}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.ctcp(command, to, args)
|
function m.ctcp(command, to, args)
|
||||||
s = "\x01"..command
|
s = "\x01"..command
|
||||||
if args then
|
if args then
|
||||||
s = ' '..args
|
s = ' '..args
|
||||||
end
|
end
|
||||||
s = s..'\x01'
|
s = s..'\x01'
|
||||||
return irc.Message({command="PRIVMSG", args={to, s}})
|
return Message({command="PRIVMSG", args={to, s}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.kick(channel, target, reason)
|
function m.kick(channel, target, reason)
|
||||||
return irc.Message({command="KICK", args={channel, target, reason}})
|
return Message({command="KICK", args={channel, target, reason}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.join(channel, key)
|
function m.join(channel, key)
|
||||||
return irc.Message({command="JOIN", args={channel, key}})
|
return Message({command="JOIN", args={channel, key}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.part(channel, reason)
|
function m.part(channel, reason)
|
||||||
return irc.Message({command="PART", args={channel, reason}})
|
return Message({command="PART", args={channel, reason}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.quit(reason)
|
function m.quit(reason)
|
||||||
return irc.Message({command="QUIT", args={reason}})
|
return Message({command="QUIT", args={reason}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.kill(target, reason)
|
function m.kill(target, reason)
|
||||||
return irc.Message({command="KILL", args={target, reason}})
|
return Message({command="KILL", args={target, reason}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.kline(time, mask, reason, operreason)
|
function m.kline(time, mask, reason, operreason)
|
||||||
local args = nil
|
local args = nil
|
||||||
if time then
|
if time then
|
||||||
args = {time, mask, reason..'|'..operreason}
|
args = {time, mask, reason..'|'..operreason}
|
||||||
else
|
else
|
||||||
args = {mask, reason..'|'..operreason}
|
args = {mask, reason..'|'..operreason}
|
||||||
end
|
end
|
||||||
return irc.Message({command="KLINE", args=args})
|
return Message({command="KLINE", args=args})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.whois(nick, server)
|
function m.whois(nick, server)
|
||||||
local args = nil
|
local args = nil
|
||||||
if server then
|
if server then
|
||||||
args = {server, nick}
|
args = {server, nick}
|
||||||
else
|
else
|
||||||
args = {nick}
|
args = {nick}
|
||||||
end
|
end
|
||||||
return irc.Message({command="WHOIS", args=args})
|
return Message({command="WHOIS", args=args})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.topic(channel, text)
|
function m.topic(channel, text)
|
||||||
return irc.Message({command="TOPIC", args={channel, text}})
|
return Message({command="TOPIC", args={channel, text}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.invite(channel, target)
|
function m.invite(channel, target)
|
||||||
return irc.Message({command="INVITE", args={channel, target}})
|
return Message({command="INVITE", args={channel, target}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.nick(nick)
|
function m.nick(nick)
|
||||||
return irc.Message({command="NICK", args={nick}})
|
return Message({command="NICK", args={nick}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function msgs.mode(target, modes)
|
function m.mode(target, modes)
|
||||||
-- We have to split the modes parameter because the mode string and
|
-- We have to split the modes parameter because the mode string and
|
||||||
-- each parameter are seperate arguments (The first command is incorrect)
|
-- each parameter are seperate arguments (The first command is incorrect)
|
||||||
-- MODE foo :+ov Nick1 Nick2
|
-- MODE foo :+ov Nick1 Nick2
|
||||||
-- MODE foo +ov Nick1 Nick2
|
-- MODE foo +ov Nick1 Nick2
|
||||||
local mt = irc.split(modes)
|
local mt = util.split(modes)
|
||||||
return irc.Message({command="MODE", args={target, unpack(mt)}})
|
return Message({command="MODE", args={target, unpack(mt)}})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function m.cap(cmd, ...)
|
||||||
|
return Message({command="CAP", args={cmd, ...}})
|
||||||
|
end
|
||||||
|
|
||||||
|
return m
|
||||||
|
|
||||||
|
19
mods/irc/irc/push-luadoc.sh
Executable file
19
mods/irc/irc/push-luadoc.sh
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$TRAVIS_REPO_SLUG" == "JakobOvrum/LuaIRC" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
|
||||||
|
|
||||||
|
echo -e "Generating luadoc...\n"
|
||||||
|
|
||||||
|
git config --global user.email "travis@travis-ci.org"
|
||||||
|
git config --global user.name "travis-ci"
|
||||||
|
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} gh-pages > /dev/null
|
||||||
|
|
||||||
|
cd gh-pages
|
||||||
|
git rm -rf ./doc
|
||||||
|
sh ./generate.sh
|
||||||
|
git add -f ./doc
|
||||||
|
git commit -m "Lastest documentation on successful travis build $TRAVIS_BUILD_NUMBER auto-pushed to gh-pages"
|
||||||
|
git push -fq origin gh-pages > /dev/null
|
||||||
|
|
||||||
|
echo -e "Published luadoc to gh-pages.\n"
|
||||||
|
fi
|
@ -1,4 +1,4 @@
|
|||||||
local select = require "socket".select
|
local select = require("socket").select
|
||||||
|
|
||||||
local m = {}
|
local m = {}
|
||||||
local set = {}
|
local set = {}
|
||||||
|
@ -1,25 +1,8 @@
|
|||||||
local irc = require("irc.main")
|
|
||||||
|
|
||||||
function irc.parseNick(conn, nick)
|
-- Module table
|
||||||
local access = {}
|
local m = {}
|
||||||
irc.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
|
|
||||||
|
|
||||||
function irc.updatePrefixModes(conn)
|
function m.updatePrefixModes(conn)
|
||||||
if conn.prefixmode and conn.modeprefix then
|
if conn.prefixmode and conn.modeprefix then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -39,8 +22,27 @@ function irc.updatePrefixModes(conn)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function m.parseNick(conn, nick)
|
||||||
|
local access = {}
|
||||||
|
m.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
|
||||||
|
|
||||||
-- mIRC markup scheme (de-facto standard)
|
-- mIRC markup scheme (de-facto standard)
|
||||||
irc.color = {
|
m.color = {
|
||||||
black = 1,
|
black = 1,
|
||||||
blue = 2,
|
blue = 2,
|
||||||
green = 3,
|
green = 3,
|
||||||
@ -60,28 +62,28 @@ irc.color = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local colByte = string.char(3)
|
local colByte = string.char(3)
|
||||||
setmetatable(irc.color, {__call = function(_, text, colornum)
|
setmetatable(m.color, {__call = function(_, text, colornum)
|
||||||
colornum = (type(colornum) == "string" and
|
colornum = (type(colornum) == "string" and
|
||||||
assert(irc.color[colornum], "Invalid color '"..colornum.."'") or
|
assert(color[colornum], "Invalid color '"..colornum.."'") or
|
||||||
colornum)
|
colornum)
|
||||||
return table.concat{colByte, tostring(colornum), text, colByte}
|
return table.concat{colByte, tostring(colornum), text, colByte}
|
||||||
end})
|
end})
|
||||||
|
|
||||||
local boldByte = string.char(2)
|
local boldByte = string.char(2)
|
||||||
function irc.bold(text)
|
function m.bold(text)
|
||||||
return boldByte..text..boldByte
|
return boldByte..text..boldByte
|
||||||
end
|
end
|
||||||
|
|
||||||
local underlineByte = string.char(31)
|
local underlineByte = string.char(31)
|
||||||
function irc.underline(text)
|
function m.underline(text)
|
||||||
return underlineByte..text..underlineByte
|
return underlineByte..text..underlineByte
|
||||||
end
|
end
|
||||||
|
|
||||||
function irc.checkNick(nick)
|
function m.checkNick(nick)
|
||||||
return nick:find("^[a-zA-Z_%-%[|%]%^{|}`][a-zA-Z0-9_%-%[|%]%^{|}`]*$") ~= nil
|
return nick:find("^[a-zA-Z_%-%[|%]%^{|}`][a-zA-Z0-9_%-%[|%]%^{|}`]*$") ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function irc.defaultNickGenerator(nick)
|
function m.defaultNickGenerator(nick)
|
||||||
-- LuaBot -> LuaCot -> LuaCou -> ...
|
-- LuaBot -> LuaCot -> LuaCou -> ...
|
||||||
-- We change a random character rather than appending to the
|
-- We change a random character rather than appending to the
|
||||||
-- nickname as otherwise the new nick could exceed the ircd's
|
-- nickname as otherwise the new nick could exceed the ircd's
|
||||||
@ -100,13 +102,13 @@ function irc.defaultNickGenerator(nick)
|
|||||||
return nick
|
return nick
|
||||||
end
|
end
|
||||||
|
|
||||||
function irc.capitalize(text)
|
function m.capitalize(text)
|
||||||
-- Converts first character to upercase and the rest to lowercase.
|
-- Converts first character to upercase and the rest to lowercase.
|
||||||
-- "PING" -> "Ping" | "hello" -> "Hello" | "123" -> "123"
|
-- "PING" -> "Ping" | "hello" -> "Hello" | "123" -> "123"
|
||||||
return text:sub(1, 1):upper()..text:sub(2):lower()
|
return text:sub(1, 1):upper()..text:sub(2):lower()
|
||||||
end
|
end
|
||||||
|
|
||||||
function irc.split(str, sep)
|
function m.split(str, sep)
|
||||||
local t = {}
|
local t = {}
|
||||||
for s in str:gmatch("%S+") do
|
for s in str:gmatch("%S+") do
|
||||||
table.insert(t, s)
|
table.insert(t, s)
|
||||||
@ -114,3 +116,5 @@ function irc.split(str, sep)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return m
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user