Skip to content
ragv1 edited this page Jan 21, 2020 · 3 revisions

These are the available event triggers you can use with node-irc. node-irc is an extended version of EventEmitter made in such a way that it should be straightforward to use it for anyone.

Table of Contents

The data object

I have specified a standardized data object that should correspond with the messages passed between the IRC server and client. The object has four default slots, method (rarely used), receiver, sender and message. The contents of these slots vary from event to event, some might be empty. Below you will find a overview of what content would be find on each slot when the event is triggered. Some events, like "KICK" will let the slot message be an array, while on others it will be empty.

ircClient.on('ready', function () {});

Main shit. This is what defines what you should do right after the client has been connected successfully. Joining channels should be favored to be used here.

Object

None.

Example

var client = new ircClient(server, port, nick, fullname);
client.on('ready', function () {
  client.join('#Node.js');
});
client.connect();

ircClient.on('CHANMSG', function (data) {});

This event will be triggered if someone says something in a channel.

Object

Object data
data.receiver The channel the message was written in prefixed with hash (#)
data.sender The nick of the person who sent the message
data.message The message the person sent

Example

client.on('CHANMSG', function (data) {
  var message = data.sender + ' said: ' + data.message;
  client.say(data.receiver, message); 
});

ircClient.on('PRIVMSG', function (data) {});

This event will be triggered if someone says something to you in a private message.

Object

Object data
data.receiver The nick person who received the message (this should always be you)
data.sender The nick of the person who sent you the message
data.message The message the person sent

Example

client.on('PRIVMSG', function (data) {
  var message = 'Hi, ' + data.sender + ', nice of you to speak to a bot. I can only repeat what you said: ' + data.message;
  if(data.sender !== nick) client.say(data.sender, message);
});

ircClient.on('JOIN', function (data) {});

This event will be triggered if someone joins a channel

Object

Object data
data.receiver The channel the person joined, prefixed by a hash (#)
data.sender The nick of the person who joined

Example

client.on('JOIN', function (data) {
  var message = 'Welcome to ' + data.receiver + ', ' + data.sender;
  client.say(data.receiver, message);
});

ircClient.on('INVITE', function (data) {});

This event will be triggered if someone invite you to a channel.

Object

Object data
data.receiver The nick of the person who was invited (this should always be you)
data.sender The nick of the person who invited you
data.message The channel you were invited to, prefixed by a hash (#)

Example

client.on('INVITE', function (data) {
  var message = 'Thank you for your invite to ' + data.message + ', ' + data.sender;
  client.join(data.message);
  client.say(data.message, message);
});

ircClient.on('TOPIC', function (data) {});

This event will be triggered if someone changes the topic title of the channel

Object

Object data
data.receiver The channel the topic was changed on, prefixed by a hash (#)
data.sender The nick of the person who changed the topic
data.message The new topic message

Example

client.on('TOPIC', function (data) {
  var message = 'Hmm, seems like ' + data.sender + ' changed the topic of ' + data.receiver + ' to: ' + data.message;
  client.say(data.receiver, message);
});

ircClient.on('PART', function (data) {});

This event will be triggered if someone parts from the channel

Object

Object data
data.receiver The channel the person parted from, prefixed by a hash (#)
data.sender The nick of the person who parted

Example

client.on('PART', function (data) {
  var privMessage = 'Sorry to see you leave from ' + data.receiver + ', ' + data.sender + '. Hope to see you again soon!';
  var chanMessage = 'Hmm, seems like ' + data.sender + ' left us';
  client.say(data.receiver, chanMessage);
  client.say(data.sender, privMessage);
});

ircClient.on('KICK', function (data) {});

This event will be triggered if someone gets kicked from a channel.

Object

Object data
data.receiver The channel the person got kicked out of, prefixed by a hash (#)
data.sender The nick of the person who kicked out the other person
data.message[0] The nick of the person who got kicked out
data.message[1] The optional kick message, will default to the nick of the kicked user if not specified

Example

client.on('KICK', function (data) {
  var privMessage = 'Im sory but you seem to be some kind of an douche, ' + data.message[0] + 
                ', or else you wouldn\'t have been kicked by ' + data.sender + 
                ' on ' + data.receiver + ' because of ' + data.message[1];
  var chanMessage = 'Sorry guys, but ' + data.message[0] + ' had to go!';
  client.say(data.message[0], privMessage);
  client.say(data.receiver, chanMessage);
});

ircClient.on('QUIT', function (data) {});

This event will be triggered when someone quits the channel. Its worth noting that on most servers the quit message is picked up by a spam filter and won't be shown to the users.

Object

Object data
data.sender The nick of the person who quitted
data.message The quit message (usually deactivated on servers because of spam)

Example

client.on('QUIT', function (data) {
  var message = data.sender + ' has left the building!';
  client.say(chan, message);
});

ircClient.on('NICK', function (data) {});

This event will be triggered if someone change their nick

Object

Object data
data.receiver The new nick of the person
data.sender The old nick of the person

Example

client.on('NICK', function (data) {
  var message = data.sender + ' changed his nick to ' + data.receiver + '! We got a badass in here ;-)';
  client.say(chan, message);
});