Created
August 2, 2015 01:19
-
-
Save 5Mixer/9f5fe0cb20d3683fffcd to your computer and use it in GitHub Desktop.
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 irc = require('irc'); | |
var Browser = require("zombie"); | |
var VoteMap = {}; | |
Map['User'] = 'Good'; | |
console.log("This script was made by Mixerman (BinaryBot). Feel free to use this script, although don't claim it is your own. Thanks."); | |
browser = new Browser() | |
domain = require('domain'), | |
d = domain.create(); | |
d.on('error', function(err) { | |
console.error(err); | |
}); | |
var currentTheme = "Key"; | |
var client = new irc.Client('irc.afternet.org', 'LDVOTE_Bot', { | |
channels: ["#LDVOTE"], | |
}); | |
getNewTheme(); | |
setInterval(getWinner,20000); | |
client.addListener('names#LDVOTE', function ( nicks) { | |
for(var k in nicks){ | |
VoteMap[k] = k; | |
} | |
}) | |
client.addListener('error', function(message) { | |
console.log('error: ', message); | |
}); | |
client.addListener('message', function (from, to, message) { | |
console.log(from + ' : ' + message); | |
if (message.toLowerCase().indexOf("get theme") > -1 || message.toLowerCase().indexOf("gt") > -1) { | |
theme(); | |
} | |
if (message.toLowerCase().indexOf("vote") > -1 || message.toLowerCase().indexOf("v") > -1) { | |
if (message.toLowerCase().indexOf("good") > -1 || message.toLowerCase().indexOf("vg") > -1){ | |
VoteMap[from] = "Good" | |
}else if (message.toLowerCase().indexOf("bad") > -1 || message.toLowerCase().indexOf("vb") > -1){ | |
VoteMap[from] = "Bad" | |
}else if (message.toLowerCase().indexOf("slaughter") > -1 || message.toLowerCase().indexOf("vs") > -1){ | |
VoteMap[from] = "Slaughter" | |
} | |
} | |
}); | |
function theme (){ | |
client.say('#LDVOTE', "THEME: "+currentTheme); | |
} | |
function getNewTheme (){ | |
browser.visit("http://ludumdare.com/theme/", function () { | |
currentTheme = browser.text('a[target=_blank]'); | |
console.log("THEME: "+browser.text('a[target=_blank]')); | |
theme(); | |
}); | |
} | |
function getWinner (){ | |
var badCount = 0; | |
var goodCount = 0; | |
var slaughterCount = 0; | |
for (k in VoteMap){ | |
if (VoteMap[k] == "Good"){ | |
goodCount++; | |
} | |
if (VoteMap[k] == "Bad"){ | |
badCount++; | |
} | |
if (VoteMap[k] == "Slaughter"){ | |
slaughterCount++; | |
} | |
} | |
if (badCount == 0 && goodCount==0 && slaughterCount==0){ | |
return; | |
} | |
client.say('#LDVOTE', badCount + " votes for it being a bad theme, "+goodCount + " votes for it being a good theme, "+slaughterCount + " votes for slaughtering theme"); | |
var highestVote = Math.max(badCount,goodCount,slaughterCount); | |
if (highestVote == goodCount){ | |
browser.clickLink("GOOD", function() { | |
//console.log("New page "+browser.url); | |
console.log("Voted theme as good"); | |
client.say('#LDVOTE', "Voting "+currentTheme+" as a good theme"); | |
getNewTheme(); | |
}); | |
}else if (highestVote == badCount){ | |
browser.clickLink("BAD", function() { | |
//console.log("New page "+browser.url); | |
console.log("Voted theme as bad"); | |
client.say('#LDVOTE', "Voting "+currentTheme+" as a bad theme"); | |
getNewTheme(); | |
}); | |
}else if (highestVote == slaughterCount){ | |
browser.clickLink("SLAUGHTER", function() { | |
//console.log("New page "+browser.url); | |
console.log("Slaughtered theme"); | |
client.say('#LDVOTE', "Slaughtering "+currentTheme+"!!"); | |
getNewTheme(); | |
}); | |
} | |
for(var k in VoteMap){ | |
VoteMap[k] = k; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was waiting for this! Thanks.