Skip to content

Instantly share code, notes, and snippets.

@sim642
Last active December 19, 2015 05:09
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 sim642/5902454 to your computer and use it in GitHub Desktop.
Save sim642/5902454 to your computer and use it in GitHub Desktop.
Source for simbot aka swagbot
var irc = require("irc");
var fs = require("fs");
var swag = {};
var cangive = {};
var cangive2 = {};
/*var regex = /^\s*([a-z_\-\[\]\\^{}|`][a-z0-9_\-\[\]\\^{}|`]*)[\s,:]*(\+\+|--)$/i*/
var regex = /^\s*([a-z_\-\[\]\\^{}|`][a-z0-9_\-\[\]\\^{}|`]*)[\s,:]*(\+\+)$/i
process.stdin.resume();
fs.readFile("swag.json", function(err, data) {
swag = JSON.parse(data);
});
process.on('SIGINT', function() {
fs.writeFileSync("swag.json", JSON.stringify(swag, null, 4));
process.exit(0);
});
setInterval(function() {
fs.writeFileSync("swag.json", JSON.stringify(swag, null, 4));
}, 60 * 1000);
var bot = new irc.Client("irc.awfulnet.org", "SwagBot", {
userName: "swagbot",
realName: "An epic swag bot",
/*port: 6697,
secure: true,
selfSigned: true,*/
channels: [/*"#bots",*/ "#teenagers"]
});
bot.addListener("registered", function(message) {
bot.say("NickServ", "identify <password>");
});
bot.addListener("message", function(nick, to, text, message) {
if (to.toLowerCase() == "swagbot")
return;
var s = text.split(" ");
var cmd = s[0].toLowerCase();
/*if (s[0] == "+swag") {
if (!(s[1] in swag)) {
swag[s[1]] = 0;
}
swag[s[1]] += parseInt(s[2]);
bot.say(to, s[1] + " now has " + swag[s[1]] + " swag!");
}*/
if (cmd == "swag?") {
var user = s[1].toLowerCase();
if (!(user in swag)) {
swag[user] = 0;
}
bot.say(to, s[1] + " has " + swag[user] + " swag.");
}
else if (cmd == "topswag?") {
var sortable = [];
for (var user in swag)
sortable.push([user, swag[user]]);
sortable.sort(function (a, b) { return b[1] - a[1]; });
bot.notice(nick, "Top swaggers:");
for (var i = 0; i < 5; i += 1)
bot.notice(nick, (i + 1).toString() + ". " + sortable[i][0] + " with " + sortable[i][1] + " swag");
}
/*else if (cmd == "bottomswag?") {
var sortable = [];
for (var user in swag)
sortable.push([user, swag[user]]);
sortable.sort(function (a, b) { return b[1] - a[1]; });
bot.notice(nick, "Bottom swaggers:");
for (var i = sortable.length - 5; i < sortable.length; i += 1)
bot.notice(nick, (i + 1).toString() + ". " + sortable[i][0] + " with " + sortable[i][1] + " swag");
}*/
else
{
var match = text.match(regex);
if (match) {
var user = match[1].toLowerCase();
var nick2 = match[1];
var pair = [message.host, user];
if (message.host in cangive2)
{
var timeout = cangive2[message.host];
bot.notice(nick, "Can't give swag for another " +
Math.ceil((timeout._idleStart.getTime() + timeout._idleTimeout - Date.now()) / 1000).toString() + " seconds.");
}
else if (pair in cangive)
{
var timeout = cangive[pair];
bot.notice(nick, "Can't give swag to " + nick2 + " for another " +
Math.ceil((timeout._idleStart.getTime() + timeout._idleTimeout - Date.now()) / 1000).toString() + " seconds.");
}
//if ((!(message.host in cangive) || cangive[message.host]) && nick != user) {
else if (nick.toLowerCase() != user) {
/*cangive[message.host] = false;
setTimeout(function() {
cangive[message.host] = true;
}, 15 * 1000);*/
cangive[pair] = setTimeout(function() {
delete cangive[pair];
}, 2 * 60 * 1000);
cangive2[message.host] = setTimeout(function() {
delete cangive2[message.host];
}, 30 * 1000);
if (!(user in swag)) {
swag[user] = 0;
}
if (match[2] == "++")
swag[user] += 1;
/*else
swag[user] -= 1;*/
bot.say(to, nick2 + " now has " + swag[user] + " swag!");
console.log("[" + to + "] " + nick + " " + match[2] + " > " + user + "(" + swag[user] + ")");
}
}
}
});
{
"uplategirl": 28,
"sim642": 17,
"notarealnick": 1,
"shepps": 1,
"sim": 2,
"nosuchnick": 1,
"madalyn": 39,
"notacreep": -9,
"applejuice": 2,
"wonka": 4,
"me": 5,
"bacon": 2,
"mag": 9,
"you": -1,
"sanduskyordie_": 4,
"roberto": 3,
"keve": 8,
"whiskeybiscuit": 22,
"sanduskyordie_----": -1,
"cdh473": 17,
"themanwithminus1swag": 0,
"something-": -1,
"themanwithplus1swag": -1,
"peoplewithswagaregay": 1,
"lausi": 3,
"simbot": 2,
"will__": 4,
"rose": 3,
"sim642|away": -1,
"cockstar2008": 2,
"sloth": 25,
"timebot": 4,
"spork": 2,
"fgojssgiu": -1,
"deathpowerwheelchair": 1,
"x": 4,
"golf1052": -2,
"panda": 31,
"infobot": 1,
"swag": 2,
"will": 3,
"tallguythefirst": 7,
"matt____": 4,
"nickster": 26,
"enrique": 18,
"nick": 1,
"myhips": 1,
"nisani": 2,
"hotkeys": -20,
"crazye": 2,
"fastar": 2,
"cdh": -22,
"dratergnikcuf2": 1,
"jakery": 1,
"nbot": 0,
"po": 3,
"xnil": 0,
"king": -1,
"qasaur": 4,
"kadence": 3,
"suffer_in_truth": 7,
"kevin": 2,
"--------------------------------------------": -1,
"undefined": 0,
"swagbot": 6,
"plategrill": 1,
"sluth": 1,
"rubbertoe": 1,
"offlinepersontest": 1,
"abc": 1,
"asd": 3,
"swaglord": 0,
"alexr_": -4,
"hawk": 2,
"cookietard": 5,
"c": 1,
"q-swag": 0,
"cornderg": 1,
"billy": 1,
"thisguy": 4,
"qswag": 0,
"soniex2": 0,
"alyx": 3,
"taquito": 3,
"charlotte": 2,
"ctrl": 1,
"cocks|sohorked": 1,
"evan": 3,
"hyper": 0,
"oz": 1,
"nutella": 5,
"dysoco": 5,
"class": 0,
"ur": 0,
".gaws": 0,
"has": 0,
"speck": 2,
"danilion": 2,
"hintss": 2,
"swagboy": 0,
"marie": 1,
"andy": 2,
"enri": 1,
"racketbot": 2,
"whiskeytriscuit": 1,
"^": 1,
"garr": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment