Created
January 28, 2015 02:29
-
-
Save milesrout/c285aa3fd0ccd551a50c to your computer and use it in GitHub Desktop.
mroutbot. Written in node.js
This file contains hidden or 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
var irc = require('irc'); | |
var readline = require('readline'); | |
var util = require('util'); | |
var config = { | |
channels: ['#project-trillek'], | |
server: 'irc.freenode.net', | |
botName: 'mroutbot' | |
}; | |
var bot = new irc.Client(config.server, config.botName, { | |
channels: config.channels | |
}); | |
bot.on('raw', function (message) { | |
if (message.command != 'PRIVMSG') { | |
console.log(message.command.toUpperCase() + ': ' + message.args.join(' ')); | |
} | |
}); | |
bot.on('motd', function (motd) { | |
//bot.join('#project-trillek'); | |
}); | |
bot.on('message', function (nick, to, text, message) { | |
console.log(util.format('%s: <%s> %s', to, nick, text)); | |
switch (message.match(/^&([a-z]+) /)[1]) { | |
case 'quit': | |
quit(); | |
break; | |
case 'reputation': | |
var name = message.match(/^&[a-z]+ ([a-z0-9A-Z_]+)/)[1]; | |
console.log('getting reputation for', name); | |
} | |
}); | |
bot.on('names', function () { | |
// remove join message while testing | |
//bot.say('#project-trillek', 'bot will no longer make noises in channel when it joins.'); | |
rl.prompt(); | |
}); | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
rl.setPrompt('mroutbot> '); | |
rl.on('line', function (line) { | |
switch (true) { | |
case /^say /.test(line): | |
bot.say('#project-trillek', line.match(/^say (.*)/)[1]); | |
break; | |
case /^quit$/.test(line): | |
quit(); | |
break; | |
} | |
rl.prompt(); | |
}); | |
function quit() { | |
rl.close(); | |
bot.disconnect(); | |
process.exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment