PageRenderTime 30ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/doc/irc.luadoc

http://github.com/JakobOvrum/LuaIRC
Unknown | 161 lines | 140 code | 21 blank | 0 comment | 0 complexity | c24e041e22e362b6f209e48b15f0c60d MD5 | raw file
  1. --- LuaIRC is a low-level IRC library for Lua.
  2. -- All functions raise Lua exceptions on error.
  3. --
  4. -- Use <code>new</code> to create a new IRC object.<br/>
  5. -- Example:<br/><br/>
  6. --<code>
  7. --require "irc"<br/>
  8. --local sleep = require "socket".sleep<br/>
  9. --<br/>
  10. --local s = irc.new{nick = "example"}<br/>
  11. --<br/>
  12. --s:hook("OnChat", function(user, channel, message)<br/>
  13. -- print(("[%s] %s: %s"):format(channel, user.nick, message))<br/>
  14. --end)<br/>
  15. --<br/>
  16. --s:connect("irc.example.net")<br/>
  17. --s:join("#example")<br/>
  18. --<br/>
  19. --while true do<br/>
  20. -- s:think()<br/>
  21. -- sleep(0.5)<br/>
  22. --end<br/>
  23. --</code>
  24. module "irc"
  25. --- Create a new IRC object. Use <code>irc:connect</code> to connect to a server.
  26. -- @param user Table with fields <code>nick</code>, <code>username</code> and <code>realname</code>.
  27. -- The <code>nick</code> field is required.
  28. --
  29. -- @return Returns a new <code>irc</code> object.
  30. function new(user)
  31. --- Hook a function to an event.
  32. -- @param name Name of event.
  33. -- @param id Unique tag.
  34. -- @param f Callback function. [defaults to <code>id</code>]
  35. -- @see Hooks
  36. function irc:hook(name, id, f)
  37. --- Remove previous hooked callback.
  38. -- @param name Name of event.
  39. -- @param id Unique tag.
  40. function irc:unhook(name, id)
  41. --- Connect <code>irc</code> to an IRC server.
  42. -- @param host Host address.
  43. -- @param port Server port. [default 6667]
  44. function irc:connect(host, port)
  45. -- @param table Table of connection details
  46. -- @see Connection
  47. function irc:connect(table)
  48. --- Disconnect <code>irc</code> from the server.
  49. -- @param message Quit message.
  50. function irc:disconnect(message)
  51. --- Handle incoming data for <code>irc</code>, and invoke previously hooked callbacks based on new server input.
  52. -- You should call this in some kind of main loop, or at least often enough to not time out.
  53. function irc:think()
  54. --- Look up user info.
  55. -- @param nick Nick of user to query.
  56. -- @return Table with fields <code>userinfo</code>, <code>node</code>, <code>channels</code> and <code>account</code>.
  57. function irc:whois(nick)
  58. --- Look up topic.
  59. -- Use this to invoke the hooks OnTopic and OnTopicInfo at any time.
  60. -- @param channel Channel to query.
  61. function irc:topic(channel)
  62. --- Send a raw line of IRC to the server.
  63. -- @param msg Line to be sent, excluding newline characters.
  64. -- @param ... Format parameters for <code>msg</code>, with <code>string.format</code> semantics. [optional]
  65. function irc:send(msg, ...)
  66. --- Send a message to a channel or user.
  67. -- @param target Nick or channel to send to.
  68. -- @param message Message to send.
  69. function irc:sendChat(target, message)
  70. --- Send a notice to a channel or user.
  71. -- @param target Nick or channel to send to.
  72. -- @param message Notice to send.
  73. function irc:sendNotice(target, message)
  74. --- Join a channel.
  75. -- @param channel Channel to join.
  76. -- @param key Channel password. [optional]
  77. function irc:join(channel, key)
  78. --- Leave a channel.
  79. -- @param channel Channel to leave.
  80. function irc:part(channel)
  81. --- Turn user information tracking on or off. User tracking is enabled by default.
  82. -- @param b Boolean whether or not to track user information.
  83. function irc:trackUsers(b)
  84. --- Add/remove modes for a channel or nick.
  85. -- @param t Table with fields <code>target, nick, add</code> and/or <code>rem</code>. <code>target</code> or <code>nick</code>
  86. -- specifies the user or channel to add/remove modes. <code>add</code> is a list of modes to add to the user or channel.
  87. -- <code>rem</code> is a list of modes to remove from the user or channel.
  88. -- @usage Example which sets +m (moderated) for #channel: <br/>
  89. -- <code>irc:setMode{target = "#channel", add = "m"}</code>
  90. function irc:setMode(t)
  91. --internal
  92. function irc:invoke(name, ...)
  93. function irc:handle(prefix, cmd, params)
  94. function irc:shutdown()
  95. --- Table with connection information.
  96. -- <ul>
  97. -- <li><code>host</code> - Server host name.</li>
  98. -- <li><code>port</code> - Server port. [defaults to <code>6667</code>]</li>
  99. -- <li><code>timeout</code> - Connect timeout. [defaults to <code>30</code>]</li>
  100. -- <li><code>password</code> - Server password.</li>
  101. -- <li><code>secure</code> - Boolean to enable TLS connection, pass a params table (described, [luasec]) to control</li>
  102. -- </ul>
  103. -- [luasec]: http://www.inf.puc-rio.br/~brunoos/luasec/reference.html
  104. -- @name Connection
  105. -- @class table
  106. --- List of hooks you can use with irc:hook. The parameter list describes the parameters passed to the callback function.
  107. -- <ul>
  108. -- <li><code>PreRegister(connection)</code>Useful for CAP commands and SASL.</li>
  109. -- <li><code>OnRaw(line) - (any non false/nil return value assumes line handled and will not be further processed)</code></li>
  110. -- <li><code>OnSend(line)</code></li>
  111. -- <li><code>OnDisconnect(message, errorOccurred)</code></li>
  112. -- <li><code>OnChat(user, channel, message)</code></li>
  113. -- <li><code>OnNotice(user, channel, message)</code></li>
  114. -- <li><code>OnJoin(user, channel)</code>*</li>
  115. -- <li><code>OnPart(user, channel)</code>*</li>
  116. -- <li><code>OnQuit(user, message)</code></li>
  117. -- <li><code>NickChange(user, newnick, channel)</code>*†</li>
  118. -- <li><code>NameList(channel, names)</code></li>
  119. -- <li><code>OnTopic(channel, topic)</code></li>
  120. -- <li><code>OnTopicInfo(channel, creator, timeCreated)</code></li>
  121. -- <li><code>OnKick(channel, nick, kicker, reason)</code>* (kicker is a <code>user</code> table)</li>
  122. -- <li><code>OnUserMode(modes)</code></li>
  123. -- <li><code>OnChannelMode(user, channel, modes)</code></li>
  124. -- <li><code>OnModeChange(user, target, modes, ...)</code>* ('...' contains mode options such as banmasks)</li>
  125. -- </ul>
  126. -- * Event also invoked for yourself.
  127. -- † Channel passed only when user tracking is enabled
  128. -- @name Hooks
  129. -- @class table
  130. --- Table with information about a user.
  131. -- <ul>
  132. -- <li><code>nick</code> - User nickname. Always present.</li>
  133. -- <li><code>username</code> - User username.</li>
  134. -- <li><code>host</code> - User hostname.</li>
  135. -- <li><code>realname</code> - User real name.</li>
  136. -- <li><code>access</code> - User access, available in channel-oriented callbacks. A table containing the boolean fields 'op', 'halfop', and 'voice'.</li>
  137. -- </ul>
  138. -- Apart from <code>nick</code>, fields may be missing. To fill them in, enable user tracking and use irc:whois.
  139. -- @name User
  140. -- @class table