--- 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"
module "irc"
--- Create a new IRC object. Use
--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
--irc:connect
to connect to a server.
-- @param user Table with fields nick
, username
and realname
.
-- The nick
field is required.
--
-- @return Returns a new irc
object.
function new(user)
--- Hook a function to an event.
-- @param name Name of event.
-- @param id Unique tag.
-- @param f Callback function. [defaults to id
]
-- @see Hooks
function irc:hook(name, id, f)
--- Remove previous hooked callback.
-- @param name Name of event.
-- @param id Unique tag.
function irc:unhook(name, id)
--- Connect irc
to an IRC server.
-- @param server Server address.
-- @param port Server port. [default 6667]
-- @param timeout Connection timeout value in seconds. [default 30]
function irc:connect(server, port, timeout)
--- Disconnect irc
from the server.
-- @param message Quit message.
function irc:disconnect(message)
--- Handle incoming data for irc
, 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.
function irc:think()
--- Look up user info.
-- @param nick Nick of user to query.
-- @return Table with fields userinfo
, node
, channels
and account
.
function irc:whois(nick)
--- Send a raw line of IRC to the server.
-- @param fmt Line to be sent, excluding newline characters.
-- @param ... Format parameters for fmt
, with string.format
semantics.
function irc:send(fmt, ...)
--- 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)
--- 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)
--- Join a channel.
-- @param channel Channel to join.
-- @param key Channel password. [optional]
function irc:join(channel, key)
--- Leave a channel.
-- @param channel Channel to leave.
function irc:part(channel)
--- Turn user information tracking on or off. User tracking is enabled by default.
-- @param b Boolean whether or not to track user information.
function irc:trackUsers(b)
--- Add/remove modes for a channel or nick.
-- @param t Table with fields target, nick, add
and/or rem
. target
or nick
-- specifies the user or channel to add/remove modes. add
is a list of modes to add to the user or channel.
-- rem
is a list of modes to remove from the user or channel.
-- @usage Example which sets +m (moderated) for #channel:
-- irc:setMode{target = "#channel", add = "m"}
function irc:setMode(t)
--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.
--
OnDisconnect(message, errorOccurred)
OnChat(user, channel, message)
OnNotice(user, channel, message)
OnJoin(user, channel)
*OnPart(user, channel)
*OnQuit(user, message)
NickChange(user, newnick)
*NameList(channel, names)
nick
- User nickname. Always present.username
- User username.host
- User hostname.realname
- User real name.access
- User access, available in channel-oriented callbacks. Can be '+', '@', and others, depending on the server.nick
, fields may be missing. To fill them in, enable user tracking and use irc:whois.
-- @name User
-- @class table