Performance Zone is brought to you in partnership with:

A GNU/Linux g33k CLI+Web loving computer polyglot. Hemanth is a DZone MVB and is not an employee of DZone and has posted 16 posts at DZone. You can read more from them at their website. View Full User Profile

IRC Notification Bot with Node.js

09.25.2012
| 3715 views |
  • submit to reddit

This bot is a product of a simple need: notifying people when their friends log in to a particular channel:

The need :

  • Simple IRC bot, that would notify its master.

  • Easy to configure.

  • Easy maintainability.

The answer was to do it with node.js!

To get up and running :

  • Indeed you must have node.

  • npm install irc

  • Check out the code from the repo and edit config.js as per need.

  • Finally start the bot node notify.js and the pm notifications ;)

The code :

The config file : [ Power of JS objects FTW! ]

var config = {};
 
config.chans   = "#yeoman, #html5"; 
config.server  = "irc.freenode.net";
config.botName = "notify-bot";
config.friends = "firend1, firend2, firends3";
config.master  = "hemanth";
module.exports = config;

The bot:

#!/usr/bin/env node
var irc = require('irc');
var config = require('./config');
 
var chans   = config.chans.split("/, */");
var server  = config.server;
var botName = config.botName;
var friends = config.friends.split(/, */);
var master  = config.master;
 
var bot = new irc.Client(server,botName, {
  channels: chans
});
 
bot.addListener('join', function (channel, who) {
  console.log(who);
  console.log(friends.indexOf(who));
  console.log(friends);
  if(friends.indexOf(who) >=0){
    bot.say(master,who + " joined "+channel); 
  } 
});

Hope this helps, as it's helping me. Your suggestions are welcome -- do check out l33ty.

 

Published at DZone with permission of Hemanth Madhavarao, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)