Skip to content
Rahat Ahmed edited this page Sep 4, 2016 · 25 revisions

Client

An IRC Client. Client extends EventEmitter2, so you can use the typical on or once functions with the following events.

Events

All events have an event argument. The properties listed are properties of that object.

connect

Event Properties: {nick, server, port}

When the client successfully connects to the server. (Note: This is not just when the connection is made, but after the 001 welcome reply is received.)

disconnect

Event Properties: {reason}

When the client is disconnected from the server. This happens either by error or by explicitly calling the disconnect function. If the client is explicitly disconnected, then there will NOT be an error event emitted.

connecting

Event Properties: {server, port}

When the client is attempts to make a socket connection to the server.

reconnecting

Event Properties: {server, port, delay, triesLeft}

When the client decides to reconnect to the server after a delay. This event is triggered before the delay (so a connecting event will occur in delay milliseconds after this event).

connection-established

Event Properties: {server, port}

When the client has established a socket connection to the server, but hasn't yet been accepted/welcomed by the IRC server.

error

Event Properties: {raw, tags, prefix, command, params}

When an error occurs. This will disconnect the client and also emit a disconnect event.

nick

Event Properties: {oldNick, newNick, me}

When someone changes their nick and is visible in a channel the client is in. Can be the client itself. If it is the client, me will be true.

join

Event Properties: {chan, nick, me}

When a user joins any channel the client is in. Can be the client itself. If it is the client, me will be true.

part

Event Properties: {chan, nick, reason, me}

When a user parts any channel the client is in. Can be the client itself. If it is the client, me will be true.

kick

Event Properties: {chan, nick, kicker, reason, me}

When a user is kicked from a channel the client is in. Reason is optional. If it is the client, me will be true.

raw

Event Properties: {raw, tags, prefix, command, params}

When any raw message is received. parsedMsg will be the object that the irc-message module returns from parsing the message.

motd

Event Properties: {motd}

When the server's motd is received.

quit

Event Properties: {nick, reason}

When someone quits from the server. This will not trigger for the client itself.

action

Event Properties: {from, to, msg}

When someone sends an action in a channel the client is in.

msg

Event Properties: {from, to, msg}

When someone sends a message to the client or a channel the client is in.

notice

Event Properties: {from, to, msg}

When someone sends a notice to the client.

invite

Event Properties: {from, chan}

When someone invites the client to a channel.

mode

Event Properties: {chan, sender, mode}

When the mode is set on a channel. The mode parameter contains the entire mode string that was set by the sender. This is useful if you don't care what the modes actually are, but want to display the event anyway (or if you want to parse it yourself).

+mode

Event Properties: {chan, sender, mode, param}

When the mode is set in a channel. The mode parameter will only be a single mode. Param is optional, depending on the mode letter. The sender can be a nick or the server. This is useful if you wish to handle new modes individually.

-mode

Event Properties: {chan, sender, mode, param}

When the mode is removed in a channel. The mode parameter will only be a single mode. Param is optional, depending on the mode letter. The sender can be a nick or the server. This is useful if you wish to handle new modes individually.

usermode

Event Properties: {user, sender, mode}

When the mode is set on a user. The mode parameter contains the entire mode string that was set by the sender. This is useful if you don't care what the modes actually are, but want to display the event anyway (or if you want to parse it yourself).

+usermode

Event Properties: {user, mode, sender}

When the mode is set on a user. The mode parameter will only be a single mode. The sender can be a nick or the server. This is useful if you wish to handle new modes individually.

-usermode

Event Properties: {user, mode, sender}

When the mode is removed from a user. The mode parameter will only be a single mode. The sender can be a nick or the server. This is useful if you wish to handle new modes individually.

timeout

Event Properties: {seconds}

When the client times out, this event will be triggered right before disconnecting.

names

Event Properties: {chan}

When the client finishes receiving the list of names for a channel. Chan will be '*' if you sent the NAMES command without any channel parameter, as per the RFC. You may access the updated names by getting the channel object from getChannel(e.chan).

topic

Event Properties: {chan, topic}

When the client receives the topic for a channel. If a RPL_NOTOPIC is received, then topic will be empty.

topicwho

Event Properties: {chan, hostmask, time}

When the client receives information on who set the channel topic and when. time is a Date.

Options

server

String The server address to connect to

port

Integer The port to connect to. Default: 6667

nick

String The nickname to connect with. Default: NodeIRCClient

username

String The username to connect with. Default: NodeIRCClient

realname

String The real name to connect with. Default: NodeIRCClient

password

String The server password to connect with. Default: none

channels

Array The channels to autoconnect to on connect. Default: []

verbose

Boolean Whether this should output log messages to console or not. Default: false

verboseError

Boolean Whether this should output error messages to console or not. Default: true

autoNickChange

Boolean Whether this should try alternate nicks if the given one is taken, or give up and quit. Default: true

autoRejoin

Boolean Whether this should automatically rejoin channels it was kicked from. Default: false

autoConnect

Boolean Whether this should automatically connect after being created or not. Default: true

autoSplitMessage

Boolean Whether this should automatically split outgoing messages. Default: true NOTE: This will split the messages conservatively. Message lengths will be around 400-ish.

messageDelay

Integer How long to throttle between outgoing messages. Default: 1000

stripColors

Boolean Strips colors from incoming messages before processing. Default: true

stripStyles

Boolean Strips styles from incoming messages before processing, like bold and underline. Default: true

reconnectDelay

Integer Time in milliseconds to wait before trying to reconnect. Default: 5000

autoReconnect

Boolean Whether this should automatically attempt to reconnect on disconnecting from the server by error. If you explicitly call disconnect(), the client will not attempt to reconnect. This does NOT apply to the connect() retries. Default: true

autoReconnectTries

Integer The number of attempts to reconnect if autoReconnect is enabled. If this is -1, then the client will try infinitely many times. This does NOT apply to the connect() retries. Default: 3

ssl

Boolean/Object Whether to use ssl to connect to the server. If ssl is an object, then it is used as the options for ssl connections (See tls.connect in 'tls' node module). Default: false

selfSigned

Boolean Whether to accept self signed ssl certificates or not. Default: false

certificateExpired

Boolean Whether to accept expired certificates or not. Default: false

timeout

Integer Number of milliseconds to wait before timing out. Default: 120000

triggerEventForOwnMessages

Boolean Whether to trigger the msg, action, or notice events when client.msg(), client.action(), or client.notice() are called. If autoSplitMessage is enabled, it will trigger a separate event for every line. Default: false

Methods

connect([tries], [cb])

Connects to the server. Returns a Promise that resolves with the nick on successful connect, and rejects with an Error on connection error.

disconnect([reason], [cb])

Disconnects from the server. Returns a Promise that is resolved on successful disconnect.

forceQuit([reason])

Immediately disconnects from the server without waiting for the server to acknowledge the QUIT request.

raw(msg, delay = true)

Sends a raw message to the server. Automatically appends \r\n. If delay is false, the message will be sent immediately, skipping the message queue delay from the messageDelay option.

use(plugin)

Registers plugin with this client. (It just calls plugin(client)). Returns the client for chaining.

NOTE: Typically, you'll want your plugin to handle events before any other listeners on the client. EX: the core channel plugin needs to update nicknames on the nick event so other listeners will have updated data by the time they are called. To accomplish this, you must use the internal EventEmitter in the Client:

client._.internalEmitter.on('nick', function(/*args...*/){/*code*/});

Another important thing to note is that you cannot use this to refer to the Client when in a listener for internalEmitter.

isConnected()

Returns true if this client is connected to and has been accepted by the server.

isConnecting()

Returns true if a connection has been initiated by connect(), but the server hasn't accepted us yet.

verbose([enabled])

Getter/setter for the option verbose

verboseError([enabled])

Getter/setter for the option verboseError

messageDelay([enabled])

Getter/setter for the option messageDelay

autoSplitMessage([enabled])

Getter/setter for the option autoSplitMessage

autoRejoin([enabled])

Getter/setter for the option autoRejoin

triggerEventForOwnMessages([enabled])

Getter/setter for the option triggerEventForOwnMessages

isChannel(chan)

Checks if a string represents a channel, based on the CHANTYPES value from the server's iSupport 005 response. Typically this means it checks if the string starts with a '#'.

modeToPrefix(mode)

Returns the prefix the server has configured for the given mode character. For example, modeToPrefix('o') will return @ in virtually all servers.

invite(nick, chan)

Sends an invite to nick to join chan.

join(chan, [cb])

Joins a channel. chan can be a String or Array of channels. Returns a Promise that resolves when the channel (or all channels if you provided an Array) has been successfully joined.

part(chan, [reason], [cb])

Parts a channel. chan can be a String or Array of channels. Returns a Promise that resolves when the channel (or all channels if you provided an Array) has been successfully joined.

kick(chan, nick, [reason])

Kicks a user from a channel.

msg(target, msg)

Sends a message (PRIVMSG) to the target.

action(target, msg)

Sends an action (/me) to the target.

notice(target, msg)

Sends a notice to the target.

nick()

Returns the client's current nick.

nick(nick, [cb])

Changes the client's nick. Returns a Promise that resolves with {oldNick, newNick} on successful nick change, and rejects with the server's error reply.

mode(chan)

Returns an Array of modes for a channel.

mode(chan, modeStr)

Sets a given mode on a hostmask in a channel. modeStr is a String of modes and arguments to set for that channel.

ban(chan, hostmask)

Sets mode +b on a hostmask in a channel.

unban(chan, hostmask)

Sets mode -b on a hostmask in a channel.

op(chan, user)

Sets mode +o on a user in a channel. user can be an array of users.

deop(chan, user)

Sets mode -o on a user in a channel. user can be an array of users.

voice(chan, user)

Sets mode +v on a user in a channel. user can be an array of users.

devoice(chan, user)

Sets mode -v on a user in a channel. user can be an array of users.

topic(chan)

Sends a request to get the topic in chan. Listen for the topic event to get the answer.

topic(chan, topic)

Set the topic for chan to topic.