2010-06-14 15:57:08 +02:00
|
|
|
--- LuaIRC is a low-level IRC library for Lua.
|
|
|
|
-- All functions raise Lua exceptions on error.
|
2010-06-14 16:12:33 +02:00
|
|
|
--
|
|
|
|
-- Use <code>new</code> to create a new IRC object.<br/>
|
|
|
|
-- Example:<br/><br/>
|
|
|
|
--<code>
|
|
|
|
--require "irc"<br/>
|
|
|
|
--local sleep = require "socket".sleep<br/>
|
|
|
|
--<br/>
|
|
|
|
--local s = irc.new{nick = "example"}<br/>
|
|
|
|
--<br/>
|
|
|
|
--s:hook("OnChat", function(user, channel, message)<br/>
|
|
|
|
-- print(("[%s] %s: %s"):format(channel, user.nick, message))<br/>
|
|
|
|
--end)<br/>
|
|
|
|
--<br/>
|
|
|
|
--s:connect("irc.example.net")<br/>
|
|
|
|
--s:join("#example")<br/>
|
|
|
|
--<br/>
|
|
|
|
--while true do<br/>
|
|
|
|
-- s:think()<br/>
|
|
|
|
-- sleep(0.5)<br/>
|
|
|
|
--end<br/>
|
|
|
|
--</code>
|
|
|
|
|
2010-06-14 15:57:08 +02:00
|
|
|
module "irc"
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- 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>.
|
2010-06-14 15:57:08 +02:00
|
|
|
-- The <code>nick</code> field is required.
|
2010-06-15 09:48:19 +02:00
|
|
|
--
|
|
|
|
-- @return Returns a new <code>irc</code> object.
|
2010-06-14 15:57:08 +02:00
|
|
|
function new(user)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Hook a function to an event.
|
|
|
|
-- @param name Name of event.
|
|
|
|
-- @param id Unique tag.
|
|
|
|
-- @param f Callback function. [defaults to <code>id</code>]
|
|
|
|
-- @see Hooks
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:hook(name, id, f)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Remove previous hooked callback.
|
|
|
|
-- @param name Name of event.
|
|
|
|
-- @param id Unique tag.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:unhook(name, id)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Connect <code>irc</code> to an IRC server.
|
|
|
|
-- @param server Server address.
|
|
|
|
-- @param port Server port. [default 6667]
|
|
|
|
-- @param timeout Connection timeout value in seconds. [default 30]
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:connect(server, port, timeout)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Disconnect <code>irc</code> from the server.
|
|
|
|
-- @param message Quit message.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:disconnect(message)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Handle incoming data for <code>irc</code>, and invoke previously hooked callbacks based on new server input.
|
|
|
|
-- You should call this in some kind of main loop, or at least often enough to not time out.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:think()
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Look up user info.
|
|
|
|
-- @param nick Nick of user to query.
|
|
|
|
-- @return Table with fields <code>userinfo</code>, <code>node</code>, <code>channels</code> and <code>account</code>.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:whois(nick)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Send a raw line of IRC to the server.
|
|
|
|
-- @param fmt Line to be sent, excluding newline characters.
|
|
|
|
-- @param ... Format parameters for <code>fmt</code>, with <code>string.format</code> semantics.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:send(fmt, ...)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Send a message to a channel or user.
|
|
|
|
-- @param target Nick or channel to send to.
|
|
|
|
-- @param message Message to send.
|
|
|
|
function irc:sendChat(target, message)
|
2010-06-14 15:57:08 +02:00
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Send a notice to a channel or user.
|
|
|
|
-- @param target Nick or channel to send to.
|
|
|
|
-- @param message Notice to send.
|
|
|
|
function irc:sendNotice(target, message)
|
2010-06-14 15:57:08 +02:00
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Join a channel.
|
|
|
|
-- @param channel Channel to join.
|
|
|
|
-- @param key Channel password. [optional]
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:join(channel, key)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Leave a channel.
|
|
|
|
-- @param channel Channel to leave.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:part(channel)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Turn user information tracking on or off. User tracking is enabled by default.
|
|
|
|
-- @param b Boolean whether or not to track user information.
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:trackUsers(b)
|
|
|
|
|
2010-06-15 09:48:19 +02:00
|
|
|
--- Add/remove modes for a channel or nick.
|
|
|
|
-- @param t Table with fields <code>target, nick, add</code> and/or <code>rem</code>. <code>target</code> or <code>nick</code>
|
|
|
|
-- specifies the user or channel to add/remove modes. <code>add</code> is a list of modes to add to the user or channel.
|
|
|
|
-- <code>rem</code> is a list of modes to remove from the user or channel.
|
|
|
|
-- @usage Example which sets +m (moderated) for #channel: <br/>
|
|
|
|
-- <code>irc:setMode{target = "#channel", add = "m"}</code>
|
2010-06-14 15:57:08 +02:00
|
|
|
function irc:setMode(t)
|
2010-06-15 09:48:19 +02:00
|
|
|
|
|
|
|
--internal
|
|
|
|
function irc:invoke(name, ...)
|
|
|
|
function irc:handle(prefix, cmd, params)
|
|
|
|
function irc:shutdown()
|
|
|
|
|
|
|
|
--- List of hooks you can use with irc:hook. The parameter list describes the parameters passed to the callback function.
|
|
|
|
-- <ul>
|
|
|
|
-- <li><code>OnDisconnect(message, errorOccurred)</code></li>
|
|
|
|
-- <li><code>OnChat(user, channel, message)</code></li>
|
|
|
|
-- <li><code>OnNotice(user, channel, message)</code></li>
|
|
|
|
-- <li><code>OnJoin(user, channel)</code>*</li>
|
|
|
|
-- <li><code>OnPart(user, channel)</code>*</li>
|
|
|
|
-- <li><code>OnQuit(user, message)</code></li>
|
|
|
|
-- <li><code>NickChange(user, newnick)</code>*</li>
|
|
|
|
-- <li><code>NameList(channel, names)</code></li>
|
|
|
|
-- </ul>
|
|
|
|
-- * Event also invoked for yourself.
|
|
|
|
-- @name Hooks
|
|
|
|
-- @class table
|
|
|
|
|
|
|
|
--- Table with information about a user.
|
|
|
|
-- <ul>
|
|
|
|
-- <li><code>nick</code> - User nickname. Always present.</li>
|
|
|
|
-- <li><code>username</code> - User username.</li>
|
|
|
|
-- <li><code>host</code> - User hostname.</li>
|
|
|
|
-- <li><code>realname</code> - User real name.</li>
|
|
|
|
-- <li><code>access</code> - User access, available in channel-oriented callbacks. Can be '+', '@', and others, depending on the server.</li>
|
|
|
|
-- </ul>
|
|
|
|
-- Apart from <code>nick</code>, fields may be missing. To fill them in, enable user tracking and use irc:whois.
|
|
|
|
-- @name User
|
|
|
|
-- @class table
|