Skip to content

Instantly share code, notes, and snippets.

@cmcculloh
Forked from adamzr/mybot.js
Created October 18, 2012 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmcculloh/3915265 to your computer and use it in GitHub Desktop.
Save cmcculloh/3915265 to your computer and use it in GitHub Desktop.
My first node.js IRC bot
//
// My First IRC Bot
//
console.log("Bot Started...");
var irc = require('irc');
//For storing globals
var MYBOT = {};
//Channel to use
MYBOT.channelname = "#tedev";
MYBOT.nick = "MyBot";
//Open an irc connection
var client = new irc.Client('irc.example.com', MYBOT.nick, {
channels: [MYBOT.channelname],
debug: true
});
//Handle private messages
client.addListener('pm', function (from, message) {
console.log(from + ' => ME: ' + message);
client.say(MYBOT.channelname, "Hello, " + from);
});//End of pm listener
//Handle on connect event
client.addListener("connect", function () {
//Sending a message to the channel when the bot connects
client.say(MYBOT.channelname,"Hello everyone!");
});
//Handle on message in target channel event
client.addListener("message" + MYBOT.channelname, function (nick,text) {
console.log(nick + ' said: ' + text);
if(text.indexOf(MYBOT.nick) > -1){
client.say(MYBOT.channelname,"Hello " + nick + "!");
}
});
@cmcculloh
Copy link
Author

Corrected some syntax errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment