IRC notification bot with node.js

This bot is a product of a simple need of notifying people when their friends login 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

Share this