Created
May 25, 2011 23:12
-
-
Save adamzr/992221 to your computer and use it in GitHub Desktop.
My first node.js IRC bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 + "!"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment