<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Reference</title> <link rel="stylesheet" href="../luadoc.css" type="text/css" /> <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/--> </head> <body> <div id="container"> <div id="product"> <div id="product_logo"></div> <div id="product_name"><big><b></b></big></div> <div id="product_description"></div> </div> <!-- id="product" --> <div id="main"> <div id="navigation"> <h1>LuaDoc</h1> <ul> <li><a href="../index.html">Index</a></li> </ul> <!-- Module list --> <h1>Modules</h1> <ul> <li><strong>irc</strong></li> </ul> <!-- File list --> </div><!-- id="navigation" --> <div id="content"> <h1>Module <code>irc</code></h1> <p>LuaIRC is a low-level IRC library for Lua. All functions raise Lua exceptions on error. 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></p> <h2>Functions</h2> <table class="function_list"> <tr> <td class="name" nowrap><a href="#irc:connect">irc:connect</a> (server, port, timeout)</td> <td class="summary">Connect <code>irc</code> to an IRC server.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:disconnect">irc:disconnect</a> (message)</td> <td class="summary">Disconnect <code>irc</code> from the server.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:hook">irc:hook</a> (name, id, f)</td> <td class="summary">Hook a function to an event.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:join">irc:join</a> (channel, key)</td> <td class="summary">Join a channel.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:part">irc:part</a> (channel)</td> <td class="summary">Leave a channel.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:send">irc:send</a> (fmt, ...)</td> <td class="summary">Send a raw line of IRC to the server.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:sendChat">irc:sendChat</a> (target, message)</td> <td class="summary">Send a message to a channel or user.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:sendNotice">irc:sendNotice</a> (target, message)</td> <td class="summary">Send a notice to a channel or user.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:setMode">irc:setMode</a> (t)</td> <td class="summary">Add/remove modes for a channel or nick.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:think">irc:think</a> ()</td> <td class="summary">Handle incoming data for <code>irc</code>, and invoke previously hooked callbacks based on new server input.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:trackUsers">irc:trackUsers</a> (b)</td> <td class="summary">Turn user information tracking on or off.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:unhook">irc:unhook</a> (name, id)</td> <td class="summary">Remove previous hooked callback.</td> </tr> <tr> <td class="name" nowrap><a href="#irc:whois">irc:whois</a> (nick)</td> <td class="summary">Look up user info.</td> </tr> <tr> <td class="name" nowrap><a href="#new">new</a> (user)</td> <td class="summary">Create a new IRC object.</td> </tr> </table> <h2>Tables</h2> <table class="table_list"> <tr> <td class="name" nowrap><a href="#Hooks">Hooks</a></td> <td class="summary">List of hooks you can use with irc:hook.</td> </tr> <tr> <td class="name" nowrap><a href="#User">User</a></td> <td class="summary">Table with information about a user.</td> </tr> </table> <br/> <br/> <h2><a name="functions"></a>Functions</h2> <dl class="function"> <dt><a name="irc:connect"></a><strong>irc:connect</strong> (server, port, timeout)</dt> <dd> Connect <code>irc</code> to an IRC server. <h3>Parameters</h3> <ul> <li> server: Server address. </li> <li> port: Server port. [default 6667] </li> <li> timeout: Connection timeout value in seconds. [default 30] </li> </ul> </dd> <dt><a name="irc:disconnect"></a><strong>irc:disconnect</strong> (message)</dt> <dd> Disconnect <code>irc</code> from the server. <h3>Parameters</h3> <ul> <li> message: Quit message. </li> </ul> </dd> <dt><a name="irc:hook"></a><strong>irc:hook</strong> (name, id, f)</dt> <dd> Hook a function to an event. <h3>Parameters</h3> <ul> <li> name: Name of event. </li> <li> id: Unique tag. </li> <li> f: Callback function. [defaults to <code>id</code>] </li> </ul> <h3>See also:</h3> <ul> <li><a href="../modules/irc.html#Hooks"> Hooks </a> </ul> </dd> <dt><a name="irc:join"></a><strong>irc:join</strong> (channel, key)</dt> <dd> Join a channel. <h3>Parameters</h3> <ul> <li> channel: Channel to join. </li> <li> key: Channel password. [optional] </li> </ul> </dd> <dt><a name="irc:part"></a><strong>irc:part</strong> (channel)</dt> <dd> Leave a channel. <h3>Parameters</h3> <ul> <li> channel: Channel to leave. </li> </ul> </dd> <dt><a name="irc:send"></a><strong>irc:send</strong> (fmt, ...)</dt> <dd> Send a raw line of IRC to the server. <h3>Parameters</h3> <ul> <li> fmt: Line to be sent, excluding newline characters. </li> <li> ...: Format parameters for <code>fmt</code>, with <code>string.format</code> semantics. </li> </ul> </dd> <dt><a name="irc:sendChat"></a><strong>irc:sendChat</strong> (target, message)</dt> <dd> Send a message to a channel or user. <h3>Parameters</h3> <ul> <li> target: Nick or channel to send to. </li> <li> message: Message to send. </li> </ul> </dd> <dt><a name="irc:sendNotice"></a><strong>irc:sendNotice</strong> (target, message)</dt> <dd> Send a notice to a channel or user. <h3>Parameters</h3> <ul> <li> target: Nick or channel to send to. </li> <li> message: Notice to send. </li> </ul> </dd> <dt><a name="irc:setMode"></a><strong>irc:setMode</strong> (t)</dt> <dd> Add/remove modes for a channel or nick. <h3>Parameters</h3> <ul> <li> 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. </li> </ul> <h3>Usage:</h3> Example which sets +m (moderated) for #channel: <br/> <code>irc:setMode{target = "#channel", add = "m"}</code> </dd> <dt><a name="irc:think"></a><strong>irc:think</strong> ()</dt> <dd> 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. </dd> <dt><a name="irc:trackUsers"></a><strong>irc:trackUsers</strong> (b)</dt> <dd> Turn user information tracking on or off. User tracking is enabled by default. <h3>Parameters</h3> <ul> <li> b: Boolean whether or not to track user information. </li> </ul> </dd> <dt><a name="irc:unhook"></a><strong>irc:unhook</strong> (name, id)</dt> <dd> Remove previous hooked callback. <h3>Parameters</h3> <ul> <li> name: Name of event. </li> <li> id: Unique tag. </li> </ul> </dd> <dt><a name="irc:whois"></a><strong>irc:whois</strong> (nick)</dt> <dd> Look up user info. <h3>Parameters</h3> <ul> <li> nick: Nick of user to query. </li> </ul> <h3>Return value:</h3> Table with fields <code>userinfo</code>, <code>node</code>, <code>channels</code> and <code>account</code>. </dd> <dt><a name="new"></a><strong>new</strong> (user)</dt> <dd> Create a new IRC object. Use <code>irc:connect</code> to connect to a server. <h3>Parameters</h3> <ul> <li> user: Table with fields <code>nick</code>, <code>username</code> and <code>realname</code>. The <code>nick</code> field is required. </li> </ul> <h3>Return value:</h3> Returns a new <code>irc</code> object. </dd> </dl> <h2><a name="tables"></a>Tables</h2> <dl class="table"> <dt><a name="Hooks"></a><strong>Hooks</strong></dt> <dd>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. </dd> <dt><a name="User"></a><strong>User</strong></dt> <dd>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. </dd> </dl> </div> <!-- id="content" --> </div> <!-- id="main" --> <div id="about"> <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p> </div> <!-- id="about" --> </div> <!-- id="container" --> </body> </html>