This library provides IRC client functionality
This object is the base of everything, it represents a single nick connected to a single IRC server.
The first two arguments are the server to connect to, and the nickname to attempt to use. The third optional argument is an options object with default values:
{
userName: 'nodebot',
realName: 'nodeJS IRC client',
port: 6667,
debug: false,
showErrors: false,
autoRejoin: true,
autoConnect: true,
channels: [],
secure: false,
selfSigned: false,
certExpired: false,
floodProtection: false,
floodProtectionDelay: 1000,
stripColors: false,
channelPrefixes: "&#",
messageSplit: 512
}
secure (SSL connection) can be a true value or an object (the kind of object returned from crypto.createCredentials()) specifying cert etc for validation. If you set selfSigned to true SSL accepts certificates from a non trusted CA. If you set certExpired to true, the bot connects even if the ssl cert has expired.
floodProtection queues all your messages and slowly unpacks it to make sure that we won’t get kicked out because for Excess Flood. You can also use Client.activateFloodProtection() to activate flood protection after instantiating the client.
floodProtectionDelay sets the amount of time that the client will wait between sending subsequent messages when floodProtection is enabled.
messageSplit will split up large messages sent with the say method into multiple messages of length fewer than messageSplit characters.
stripColors removes mirc colors (0x03 followed by one or two ascii numbers for foreground,background) and ircII “effect” codes (0x02 bold, 0x1f underline, 0x16 reverse, 0x0f reset) from the entire message before parsing it and passing it along.
Setting autoConnect to false prevents the Client from connecting on instantiation. You will need to call connect() on the client instance:
var client = new irc.Client({ autoConnect: false, ... });
client.connect();
Sends a raw message to the server; generally speaking, it’s best not to use this method unless you know what you’re doing. Instead, use one of the methods below.
Joins the specified channel.
| Arguments: |
|
|---|
Parts the specified channel.
| Arguments: |
|
|---|
Sends a message to the specified target.
| Arguments: |
|
|---|
Sends a CTCP message to the specified target.
| Arguments: |
|
|---|
Sends an action to the specified target.
Sends a notice to the specified target.
| Arguments: |
|
|---|
Request a whois for the specified nick.
| Arguments: |
|
|---|
Request a channel listing from the server. The arguments for this method are fairly server specific, this method just passes them through exactly as specified.
Responses from the server are available via the channellist_start, channellist_item, and channellist events.
Connects to the server. Used when autoConnect in the options is set to false. If retryCount is a function it will be treated as the callback (i.e. both arguments to this function are optional).
param integer retryCount: Optional number of times to attempt reconnection param function callback: Optional callback
Disconnects from the IRC server. If message if a function it will be treated as the callback (i.e. both arguments to this function are optional).
| Arguments: |
|
|---|
Activates flood protection “after the fact”. You can also use floodProtection while instantiating the Client to enable flood protection, and floodProtectionDelay to set the default message interval.
| Arguments: |
|
|---|
irc.Client instances are EventEmitters with the following events:
function (message) { }
Emitted when the server sends the initial 001 line, indicating you’ve connected to the server. See the raw event for details on the message object.
function (motd) { }
Emitted when the server sends the message of the day to clients.
function (channel, nicks) { }
Emitted when the server sends a list of nicks for a channel (which happens immediately after joining and on request. The nicks object passed to the callback is keyed by nick names, and has values ‘’, ‘+’, or ‘@’ depending on the level of that nick in the channel.
function (nicks) { }
As per ‘names’ event but only emits for the subscribed channel.
function (channel, topic, nick, message) { }
Emitted when the server sends the channel topic on joining a channel, or when a user changes the topic on a channel. See the raw event for details on the message object.
function (channel, nick, message) { }
Emitted when a user joins a channel (including when the client itself joins a channel). See the raw event for details on the message object.
function (nick, message) { }
As per ‘join’ event but only emits for the subscribed channel. See the raw event for details on the message object.
function (channel, nick, reason, message) { }
Emitted when a user parts a channel (including when the client itself parts a channel). See the raw event for details on the message object.
function (nick, reason, message) { }
As per ‘part’ event but only emits for the subscribed channel. See the raw event for details on the message object.
function (nick, reason, channels, message) { }
Emitted when a user disconnects from the IRC, leaving the specified array of channels. See the raw event for details on the message object.
function (channel, nick, by, reason, message) { }
Emitted when a user is kicked from a channel. See the raw event for details on the message object.
function (nick, by, reason, message) { }
As per ‘kick’ event but only emits for the subscribed channel. See the raw event for details on the message object.
function (nick, reason, channels, message) { }
Emitted when a user is killed from the IRC server. channels is an array of channels the killed user was in which are known to the client. See the raw event for details on the message object.
function (nick, to, text, message) { }
Emitted when a message is sent. to can be either a nick (which is most likely this clients nick and means a private message), or a channel (which means a message to that channel). See the raw event for details on the message object.
function (nick, to, text, message) { }
Emitted when a message is sent to any channel (i.e. exactly the same as the message event but excluding private messages. See the raw event for details on the message object.
function (nick, text, message) { }
As per ‘message’ event but only emits for the subscribed channel. See the raw event for details on the message object.
function (nick, to, text, message) { }
Emitted when a notice is sent. to can be either a nick (which is most likely this clients nick and means a private message), or a channel (which means a message to that channel). nick is either the senders nick or null which means that the notice comes from the server. See the raw event for details on the message object.
function (server) { }
Emitted when a server PINGs the client. The client will automatically send a PONG request just before this is emitted.
function (nick, text, message) { }
As per ‘message’ event but only emits when the message is direct to the client. See the raw event for details on the message object.
function (from, to, text, type) { }
Emitted when a CTCP notice or privmsg was received (type is either ‘notice’ or ‘privmsg’).
function (from, to, text) { }
Emitted when a CTCP notice was received.
function (from, to, text) { }
Emitted when a CTCP privmsg was received.
function (from, to) { }
Emitted when a CTCP VERSION request was received.
function (oldnick, newnick, channels, message) { }
Emitted when a user changes nick along with the channels the user is in. See the raw event for details on the message object.
function (channel, from, message) { }
Emitted when the client recieves an /invite. See the raw event for details on the message object.
function (channel, by, mode, argument, message) { }
Emitted when a mode is added to a user or channel. channel is the channel which the mode is being set on/in. by is the user setting the mode. mode is the single character mode indentifier. If the mode is being set on a user, argument is the nick of the user. If the mode is being set on a channel, argument is the argument to the mode. If a channel mode doesn’t have any arguments, argument will be ‘undefined’. See the raw event for details on the message object.
function (channel, by, mode, argument, message) { }
Emitted when a mode is removed from a user or channel. channel is the channel which the mode is being set on/in. by is the user setting the mode. mode is the single character mode indentifier. If the mode is being set on a user, argument is the nick of the user. If the mode is being set on a channel, argument is the argument to the mode. If a channel mode doesn’t have any arguments, argument will be ‘undefined’. See the raw event for details on the message object.
function (info) { }
Emitted whenever the server finishes outputting a WHOIS response. The information should look something like:
{
nick: "Ned",
user: "martyn",
host: "10.0.0.18",
realname: "Unknown",
channels: ["@#purpledishwashers", "#blah", "#mmmmbacon"],
server: "*.dollyfish.net.nz",
serverinfo: "The Dollyfish Underworld",
operator: "is an IRC Operator"
}
function () {}
Emitted whenever the server starts a new channel listing
function (channel_info) {}
Emitted for each channel the server returns. The channel_info object contains keys ‘name’, ‘users’ (number of users on the channel), and ‘topic’.
function (channel_list) {}
Emitted when the server has finished returning a channel list. The channel_list array is simply a list of the objects that were returned in the intervening channellist_item events.
This data is also available via the Client.channellist property after this event has fired.
function (message) { }
Emitted when ever the client receives a “message” from the server. A message is basically a single line of data from the server, but the parameter to the callback has already been parsed and contains:
message = {
prefix: "The prefix for the message (optional)",
nick: "The nickname portion of the prefix (optional)",
user: "The username portion of the prefix (optional)",
host: "The hostname portion of the prefix (optional)",
server: "The servername (if the prefix was a servername)",
rawCommand: "The command exactly as sent from the server",
command: "Human readable version of the command",
commandType: "normal, error, or reply",
args: ['arguments', 'to', 'the', 'command'],
}
You can read more about the IRC protocol by reading RFC 1459
function (message) { }
Emitted when ever the server responds with an error-type message. The message parameter is exactly as in the ‘raw’ event.
Takes a color by name, text, and optionally what color to return.
| Arguments: |
|
|---|
This contains the set of colors available and a function to wrap text in a color.
The following color choices are available:
}
Socket to the server. Rarely, if ever needed. Use Client.send instead.
Channels joined. Updated after the server recognizes the join.
Buffer of whois data as whois is sent over multiple lines.
Self-explanatory.
Self-explanatory.