-
Notifications
You must be signed in to change notification settings - Fork 9
Events
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.
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.
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.
None.
var client = new ircClient(server, port, nick, fullname);
client.on('ready', function () {
client.join('#Node.js');
});
client.connect();
This event will be triggered if someone says something in a channel.
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 |
client.on('CHANMSG', function (data) {
var message = data.sender + ' said: ' + data.message;
client.say(data.receiver, message);
});
This event will be triggered if someone says something to you in a private message.
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 |
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);
});
This event will be triggered if someone joins a channel
Object | data |
---|---|
data.receiver | The channel the person joined, prefixed by a hash (#) |
data.sender | The nick of the person who joined |
client.on('JOIN', function (data) {
var message = 'Welcome to ' + data.receiver + ', ' + data.sender;
client.say(data.receiver, message);
});
This event will be triggered if someone invite you to a channel.
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 (#) |
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);
});
This event will be triggered if someone changes the topic title of the channel
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 |
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);
});
This event will be triggered if someone parts from the channel
Object | data |
---|---|
data.receiver | The channel the person parted from, prefixed by a hash (#) |
data.sender | The nick of the person who parted |
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);
});
This event will be triggered if someone gets kicked from a channel.
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 |
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);
});
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 | data |
---|---|
data.sender | The nick of the person who quitted |
data.message | The quit message (usually deactivated on servers because of spam) |
client.on('QUIT', function (data) {
var message = data.sender + ' has left the building!';
client.say(chan, message);
});
This event will be triggered if someone change their nick
Object | data |
---|---|
data.receiver | The new nick of the person |
data.sender | The old nick of the person |
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);
});