Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

IRC Notification Bot with Node.js

DZone's Guide to

IRC Notification Bot with Node.js

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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.

 

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Published at DZone with permission of Hemanth HM, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}