Last active
August 8, 2016 02:18
-
-
Save cr4m3r/2cd696015912fcc43887 to your computer and use it in GitHub Desktop.
Auto Congrats chats for players earning flair or reaching degrees
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
// ==UserScript== | |
// @name AutoGrats | |
// @namespace http://www.reddit.com/u/slothbear | |
// @description Auto congrats on an earned degree. | |
// @include http://tagpro-*.koalabeast.com:* | |
// @include http://tangent.jukejuice.com:* | |
// @include http://*.newcompte.fr:* | |
// @author slothbear / %bodyfat | |
// @version 2.5 | |
// @downloadURL https://gist.github.com/cr4m3r/2cd696015912fcc43887/raw/tagpro_autoGrats.user.js | |
// ==/UserScript== | |
tagpro.ready(function () { | |
// NEW DEGREE REACHED CONGRATULATIONS: | |
// These are the random phrases for when someone reaches a | |
// new degree. Put the word (in all caps) 'NUMBERS' if you want | |
// to say the new amount of degrees. Put the word (in all caps) | |
// 'PLAYERNAME' if you want to say the player's name who reached | |
// the degrees. Make sure the phrase is in quotation marks, and that | |
// it's followed by a comma, EXCEPT THE LAST PHRASE...NO COMMA AFTER. | |
// Just mess with the stuff between the ****** lines. | |
var degreePhrases = [ | |
//******************************************************** | |
//******************************************************** | |
"NUMBERS! Way to go PLAYERNAME!", | |
"Good job, PLAYERNAME", | |
"NUMBERS!", | |
"grats on the degrees PLAYERNAME", | |
"gj PLAYERNAME", | |
//***NO COMMA AFTER THE PHRASE BELOW*** | |
"grats PLAYERNAME" | |
//******************************************************** | |
//******************************************************** | |
]; | |
// NEW FLAIR EARNED CONGRATULATIONS: | |
// These are the random phrases for when someone earns a new | |
// flair. Put the word (in all caps) 'PLAYERNAME' if you | |
// want to say the player's name who reached the degrees. | |
// Make sure the phrase is in quotation marks, and that | |
// it's followed by a comma, EXCEPT THE LAST PHRASE...NO COMMA AFTER. | |
// Just mess with the stuff between the ****** lines. | |
var flairPhrases = [ | |
//******************************************************** | |
//******************************************************** | |
"Nice flair, PLAYERNAME!", | |
"gj PLAYERNAME", | |
"grats PLAYERNAME!", | |
"way to go PLAYERNAME", | |
//NO COMMA AFTER THE PHRASE BELOW*** | |
"yay PLAYERNAME!" | |
//******************************************************** | |
//******************************************************** | |
]; | |
//if (tagpro.group.socket) | |
// return; | |
tagpro.socket.on("end", function (e) { | |
console.log("STARTING AUTOGRATS"); | |
watchChat(); | |
}); | |
function respondDegrees(name, degrees) { | |
//pick random degreePhrase | |
var randomDegreePhrase = degreePhrases[Math.floor(Math.random() * degreePhrases.length)]; | |
//replace "NUMBERS" with degree amount, replace PLAYERNAME with name | |
randomDegreePhrase = insertDegreeAmount(degrees, randomDegreePhrase); | |
randomDegreePhrase = insertPlayerName(name, randomDegreePhrase); | |
//send the chat | |
tagpro.socket.emit("chat", { | |
message: randomDegreePhrase, | |
toAll: true | |
}); | |
} | |
function respondFlair(name) { | |
//pick random flairPhrase | |
var randomFlairPhrase = flairPhrases[Math.floor(Math.random() * flairPhrases.length)]; | |
//replace PLAYERNAME with name | |
randomFlairPhrase = insertPlayerName(name, randomFlairPhrase); | |
//send the chat | |
tagpro.socket.emit("chat", { | |
message: randomFlairPhrase, | |
toAll: true | |
}); | |
} | |
function insertDegreeAmount(degrees, randomPhrase) { | |
var n = randomPhrase.search("NUMBERS"); | |
if (n > -1) { | |
var output = randomPhrase.substring(0, n) + degrees + randomPhrase.substring(n + "NUMBERS".length); | |
return output; | |
} else { | |
return randomPhrase; | |
} | |
} | |
function insertPlayerName(name, randomPhrase) { | |
var n = randomPhrase.search("PLAYERNAME"); | |
if (n > -1) { | |
var output = randomPhrase.substring(0, n) + name + randomPhrase.substring(n + "PLAYERNAME".length); | |
return output; | |
} else { | |
return randomPhrase; | |
} | |
} | |
function getPlayerName() { | |
var playerName = tagpro.players[tagpro.playerId]["name"]; | |
return playerName; | |
} | |
function watchChat() { | |
var tooQuick = 0; | |
tagpro.socket.on("chat", function (origMessage) { | |
var msg = origMessage.message; | |
//Searches for degree reached message | |
var d = msg.search("has reached"); | |
if (d > -1) { | |
var dEnd = d + "has reached".length; | |
var degrees = msg.substring(dEnd, msg.length); | |
var dName = msg.substring(0, d - 1); | |
if (dName === getPlayerName()) { | |
return; | |
} else { | |
setTimeout(respondDegrees, (2500 + tooQuick), dName, degrees); | |
tooQuick += 1000; | |
} | |
} | |
//Searches for flair earned message | |
var f = msg.search("has earned"); | |
if (f > -1) { | |
var fName = msg.substring(0, f - 1); | |
if (fName === getPlayerName()) { | |
return; | |
} else { | |
setTimeout(respondFlair, (2500 + tooQuick), fName); | |
tooQuick += 1000; | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment