Over a million developers have joined DZone.
Platinum Partner

IRC Notification Bot with Node.js

· Web Dev Zone

The Web Dev Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

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) {
  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.


The Web Dev Zone is brought to you in partnership with Mendix.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


Published at DZone with permission of Hemanth Madhavarao , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}