Created
September 8, 2014 10:02
-
-
Save rubensworks/c8d02ed92198894ae5e6 to your computer and use it in GitHub Desktop.
SeriousBot
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
var config = { | |
channels: ["#seriouslee"], | |
server: "irc.esper.net", | |
botName: "SeriousBot" | |
}; | |
var MAX_RANDOM_TIMEOUT = 20000000; | |
var randomMessages = [ | |
"PRRRRRRRT!", | |
"MHMMMMHHMMM!", | |
"EEEEUEUUUHH!", | |
"In je poep!", | |
"Dat is niet verplicht, maar slechts een aanbeveling.", | |
"Nog even wat YouTube filmpkes kijken...", | |
"Moeie een koekske ein dikke lul?", | |
"Ik heb kaka gedaan.", | |
"dotdotdotdotdotdotdotdotdot..." | |
]; | |
var joinMessages = [ | |
"ELLO {0}!", | |
"{0}, we zijn blij dat je erbij bent.", | |
"{0} ... dude ... welcome back...", | |
"AAAAARGHHH, het is een {0}!", | |
"Aah, die {0}poepoehoofd.", | |
"En die {0} leeft ook nog" | |
]; | |
var history = {}; | |
String.prototype.format = function() { | |
var formatted = this; | |
for( var arg in arguments ) { | |
formatted = formatted.replace("{" + arg + "}", arguments[arg]); | |
} | |
return formatted; | |
}; | |
function escapeRegExp(string) { | |
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); | |
} | |
String.prototype.replaceAll = function(find, replace) { | |
return this.replace(new RegExp(escapeRegExp(find), 'g'), replace); | |
} | |
var irc = require("irc"); | |
var bot = new irc.Client(config.server, config.botName, { | |
channels: config.channels | |
}); | |
// Listen for joins | |
bot.addListener("join", function(channel, who) { | |
if(who != config.botName) { | |
var i = Math.floor(Math.random() * joinMessages.length); | |
var message = joinMessages[i].format(who); | |
bot.say(channel, message); | |
} else { | |
newTimeout(channel); | |
} | |
}); | |
// Listen for any message, PM said user when he posts | |
/*bot.addListener("message", function(from, to, text, message) { | |
bot.say(from, "Me stupid, no answer."); | |
});*/ | |
// Listen for any message, say to him/her in the room | |
bot.addListener("message", function(from, to, text, message) { | |
if(text.indexOf(config.botName) >= 0) { | |
bot.say(config.channels[0], "WHAT DID YOU SAY?!?"); | |
} else if(text == "random") { | |
randomMessage(config.channels[0]); | |
} else if(/s\/.*\/.*\//.test(text)) { | |
if(!history.hasOwnProperty(from)) { | |
bot.say(config.channels[0], "Dude, please say something before asking to replace something ... dumbass"); | |
} else { | |
var parts = text.split(/[\/]/); | |
var original = history[from]; | |
var newMsg = original.replaceAll(parts[1], parts[2]); | |
//bot.say(config.channels[0], "Hold on, we have a substitute request!"); | |
bot.say(config.channels[0], from + ": " + newMsg); | |
} | |
} | |
history[from] = text; | |
}); | |
// Random message | |
newTimeout = function(channel) { | |
setTimeout(function() { | |
newTimeout(channel); | |
randomMessage(channel); | |
}, Math.floor(Math.random() * MAX_RANDOM_TIMEOUT)); | |
}; | |
randomMessage = function(channel) { | |
var i = Math.floor(Math.random() * randomMessages.length); | |
bot.say(channel, randomMessages[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment