-
-
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) |
- Connect irc to an IRC server. |
-
-
-
- irc:disconnect (message) |
- Disconnect irc from the server. |
-
-
-
- irc:hook (name, id, f) |
- Hook a function to an event. |
-
-
-
- irc:join (channel, key) |
- Join a channel. |
-
-
-
- irc:part (channel) |
- Leave a channel. |
-
-
-
- irc:send (fmt, ...) |
- Send a raw line of IRC to the server. |
-
-
-
- irc:sendChat (target, message) |
- Send a message to a channel or user. |
-
-
-
- irc:sendNotice (target, message) |
- Send a notice to a channel or user. |
-
-
-
- irc:setMode (t) |
- Add/remove modes for a channel or nick. |
-
-
-
- irc:think () |
- Handle incoming data for irc , and invoke previously hooked callbacks based on new server input. |
-
-
-
- irc:trackUsers (b) |
- Turn user information tracking on or off. |
-
-
-
- irc:unhook (name, id) |
- Remove previous hooked callback. |
-
-
-
- irc:whois (nick) |
- Look up user info. |
-
-
-
- new (user) |
- Create a new IRC object. |
-
-
-
-
-
-
-
-
Tables
-
-
-
- Hooks |
- List of hooks you can use with irc:hook. |
-
-
-
- User |
- Table with information about a user. |
-
-
-
-
-
-
-
-
-
-
-
-
Functions
-
-
-
-
-- irc:connect (server, port, timeout)
--
-Connect
irc
to an IRC server.
-
-
-Parameters
-
-
- -
- server: Server address.
-
-
- -
- port: Server port. [default 6667]
-
-
- -
- timeout: Connection timeout value in seconds. [default 30]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:disconnect (message)
--
-Disconnect
irc
from the server.
-
-
-Parameters
-
-
- -
- message: Quit message.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:hook (name, id, f)
--
-Hook a function to an event.
-
-
-
Parameters
-
-
- -
- name: Name of event.
-
-
- -
- id: Unique tag.
-
-
- -
- f: Callback function. [defaults to
id
]
-
-
-
-
-
-
-
-
-
-
-
-See also:
-
-
-
-
-
-
-
-- irc:join (channel, key)
--
-Join a channel.
-
-
-
Parameters
-
-
- -
- channel: Channel to join.
-
-
- -
- key: Channel password. [optional]
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:part (channel)
--
-Leave a channel.
-
-
-
Parameters
-
-
- -
- channel: Channel to leave.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:send (fmt, ...)
--
-Send a raw line of IRC to the server.
-
-
-
Parameters
-
-
- -
- fmt: Line to be sent, excluding newline characters.
-
-
- -
- ...: Format parameters for
fmt
, with string.format
semantics.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:sendChat (target, message)
--
-Send a message to a channel or user.
-
-
-
Parameters
-
-
- -
- target: Nick or channel to send to.
-
-
- -
- message: Message to send.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:sendNotice (target, message)
--
-Send a notice to a channel or user.
-
-
-
Parameters
-
-
- -
- target: Nick or channel to send to.
-
-
- -
- message: Notice to send.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:setMode (t)
--
-Add/remove modes for a channel or nick.
-
-
-
Parameters
-
-
- -
- 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"}
-
-
-
-
-
-
-
-
-
-
-- irc:think ()
--
-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.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:trackUsers (b)
--
-Turn user information tracking on or off. User tracking is enabled by default.
-
-
-
Parameters
-
-
- -
- b: Boolean whether or not to track user information.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:unhook (name, id)
--
-Remove previous hooked callback.
-
-
-
Parameters
-
-
- -
- name: Name of event.
-
-
- -
- id: Unique tag.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-- irc:whois (nick)
--
-Look up user info.
-
-
-
Parameters
-
-
- -
- nick: Nick of user to query.
-
-
-
-
-
-
-
-
-
-Return value:
-Table with fields userinfo
, node
, channels
and account
.
-
-
-
-
-
-
-
-
-- new (user)
--
-Create a new IRC object. Use
irc:connect
to connect to a server.
-
-
-Parameters
-
-
- -
- user: Table with fields
nick
, username
and realname
. The nick
field is required.
-
-
-
-
-
-
-
-
-
-Return value:
-Returns a new irc
object.
-
-
-
-
-
-
-
-
-
-
-
-
Tables
-
-
-- Hooks
-- 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)
* Event also invoked for yourself.
-
-
-
-
-
-
-- User
-- Table with information about a user.
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.
Apart from nick
, fields may be missing. To fill them in, enable user tracking and use irc:whois.
-
-
-
-
-
-
-
-
-
-
-