Module irc

LuaIRC is a low-level IRC library for Lua. All functions raise Lua exceptions on error. Use new to create a new IRC object.
Example:

require "irc"
local sleep = require "socket".sleep

local s = irc.new{nick = "example"}

s:hook("OnChat", function(user, channel, message)
print(("[%s] %s: %s"):format(channel, user.nick, message))
end)

s:connect("irc.example.net")
s:join("#example")

while true do
s:think()
sleep(0.5)
end

Functions

irc:connect (server, port, timeout) Connects irc to server:port, with the connection timeout value timeout.
irc:disconnect (message) Disconnects irc from the server, with the quit message message.
irc:hook (name, id, f) Hooks function f to event name, with the unique tag id.
irc:join (channel, key) Joins channel, optionally with the channel password key.
irc:part (channel) Leaves channel.
irc:send (fmt, ...) Sends a raw line of IRC to the server.
irc:sendChat (target, msg) Sends the message msg to target.
irc:sendNotice (target, msg) Sends the notice msg to target.
irc:setMode (t) Adds and/or removes modes for a channel or nick.
irc:think () Handles incoming data for irc, and invokes previously hooked callbacks based on the new server input.
irc:trackUsers (b) Specifies whether to cache user information or not with the boolean b.
irc:unhook (name, id) Removes previous hooked callback with the tag id from event name.
irc:whois (nick) Sends a WHOIS lookup request for nick.
new (user) Create a new IRC object.


Functions

irc:connect (server, port, timeout)
Connects irc to server:port, with the connection timeout value timeout.

Parameters

  • server:
  • port:
  • timeout:
irc:disconnect (message)
Disconnects irc from the server, with the quit message message.

Parameters

  • message:
irc:hook (name, id, f)
Hooks function f to event name, with the unique tag id. If parameter f is absent, id is assumed to be both the callback function and unique tag.

Parameters

  • name:
  • id:
  • f:
irc:join (channel, key)
Joins channel, optionally with the channel password key.

Parameters

  • channel:
  • key:
irc:part (channel)
Leaves channel.

Parameters

  • channel:
irc:send (fmt, ...)
Sends a raw line of IRC to the server. fmt is the line to be sent, without the newline characters. fmt can be a format string taking the parameters ..., with string.format semantics.

Parameters

  • fmt:
  • ...:
irc:sendChat (target, msg)
Sends the message msg to target. target should be either a channel or nick.

Parameters

  • target:
  • msg:
irc:sendNotice (target, msg)
Sends the notice msg to target. target should be either a channel or nick.

Parameters

  • target:
  • msg:
irc:setMode (t)
Adds and/or removes modes for a channel or nick. Either t.target or t.nick specifies the channel or nick to add/remove modes. t.add is a list of modes to add to the target. t.rem is a list of modes to remove from the target. Example which sets +m (moderated) for #channel: irc:setMode{target = "#channel", add = "m"}

Parameters

  • t:
irc:think ()
Handles incoming data for irc, and invokes previously hooked callbacks based on the new server input. You should call this in some kind of main loop, or at least often enough not to time out.
irc:trackUsers (b)
Specifies whether to cache user information or not with the boolean b.

Parameters

  • b:
irc:unhook (name, id)
Removes previous hooked callback with the tag id from event name.

Parameters

  • name:
  • id:
irc:whois (nick)
Sends a WHOIS lookup request for nick. Returns a table with the fields userinfo, node, channels and account.

Parameters

  • nick:
new (user)
Create a new IRC object. The user parameter can contain fields nick, username and realname. The nick field is required. Returns a new irc object.

Parameters

  • user:

Valid XHTML 1.0!