Пример #1
0
addAdminCommand("accept", function(src, commandData, channel) {
	if(trivreview.editingMode === true){
		triviaq.unsafeAdd(trivreview.editingCategory, trivreview.editingQuestion, trivreview.editingAnswer);
		trivreview.editingMode = false;
		triviabot.sendAll("The question in edit was saved",channel);
		trivreview.checkq(trivreview.currentId);
		return;
	}
	var tr = trivreview.all();
	if (trivreview.questionAmount() !== 0) {
		if((time()-trivreview.declineTime)<=2){
			triviabot.sendMessage(src, "Please wait before accepting a question",channel);
			return;
		}
		var id = Object.keys(tr)[0];
		var q = trivreview.get(id);
		triviaq.unsafeAdd(q.category,q.question,q.answer);
		var all = triviaq.all(), qid;
		for (var b in all){
			var qu = triviaq.get(b);
			if(qu.question===q.question){
				qid = b;
			}
		}
		triviabot.sendAll(sys.name(src)+" accepted question: id, "+qid+" category: "+q.category+", question: "+q.question+", answer: "+q.answer,revchan);
		trivreview.declineTime = time();
		trivreview.remove(id);
		trivreview.checkq(id+1);
		return;
	}
	triviabot.sendMessage(src, "No more questions!",channel);
    // triviabot.sendMessage(src,"You accepted question ID #"+commandData+"!", channel);
},"Allows you to accept the current question in review");
Пример #2
0
addOwnerCommand("revertfrom", function(src, commandData, channel) {
	commandData = commandData.split(":");
	var fileTrivia = commandData[0], fileTrivReview = commandData[1];
	if (fileTrivia == undefined || fileTrivReview == undefined) {
		fileTrivia = "backupQuestions.json", fileTrivReview = "backupReview.json";
	}
	var content1 = sys.getFileContent(fileTrivia), content2 = sys.getFileContent(fileTrivReview);
	if (content1 == undefined || content1 == '' || content2 == undefined || content2 == '') {
		triviabot.sendMessage(src, 'The content of either file is undefined or blank.', channel);
		return;
	}
	if (fileTrivia.indexOf(".json") == -1 || fileTrivReview.indexOf(".json") == -1) { 
		triviabot.sendMessage(src, 'Please add .json to make sure you are specifying a valid file.', channel);
		return;
	}
	try {
		var parsed = JSON.parse(content1), parsed2 = JSON.parse(content2);
	} catch (e) {
		triviabot.sendMessage(src, "Couldn't revert: "+e, channel);
		return;
	}
	sys.writeToFile("triviaq.json", content1);
	triviaq.state = parsed;
	sys.writeToFile("trivreview.json", content2);
	trivreview.state = parsed2;
	triviabot.sendMessage(src, "Successfully reverted questions!", channel);
	return;
},"Revert questions.");
Пример #3
0
addAdminCommand("submitban", function(src, commandData, channel) {
	var name = commandData;
	if (sys.dbIp(name) == undefined) {
		triviabot.sendMessage(src, "He/She doesn't exist!");
		return;
	}
	var ableToBan = sys.dbAuth(name) < 1 && !tadmin.isTAdmin(name.toLowerCase());
	var ip = (sys.id(name) !== undefined) ? sys.ip(sys.id(name)) : sys.dbIp(name);
	if (trivData.submitBans[ip] !== undefined) {
		triviabot.sendMessage(src, commandData+" is already banned from submitting.", channel);
		return;
	}
	if (ableToBan) {
		trivData.submitBans[ip] = {
			'by' : sys.name(src),
			'name' : name
		};
		var channels = [sys.channelId("Indigo Plateau"), sys.channelId("Victory Road"), revchan]
		for (var x in channels) {
			if (sys.existChannel(sys.channel(channels[x]))) {
				triviabot.sendAll(sys.name(src)+" banned "+name+" from submitting questions.", channels[x]);
			}
		}
		saveData();
		return;
	} else {
		triviabot.sendMessage(src, "Sorry, you are unable to ban "+name+" from submitting.", channel);
		return;
	}
}, "Ban a user from submitting.");
Пример #4
0
addAdminCommand("showq", function(src, commandData, channel){
	var q = triviaq.get(commandData);
	if(q !== null){
		triviabot.sendMessage(src, "Question ID: "+ commandData +", Question: "+ q.question + ", Category: "+ q.category + ", Answer(s): " + q.answer, channel);
		return;
	}
	triviabot.sendMessage(src, "This question does not exist",channel);
},"Allows you to see an already submitted question");
Пример #5
0
addOwnerCommand("erasequestions", function(src, commandData, channel) {
	if (commandData == undefined || commandData !== 'confirm') {
		triviabot.sendMessage(src, 'Please confirm that you want to erase all questions by typing /erasequestions confirm.', channel);
		return;
	} else {
		sys.writeToFile("triviaq.json", "");
		triviaq.state = {freeId: 0, questions: {}};
		triviabot.sendMessage(src, "Questions erased!", channel);
	}
},"Erases all current questions");
Пример #6
0
addUserCommand("flashme", function(src,commandData,channel) {
	if (trivData.toFlash[sys.ip(src)] == undefined) {
		trivData.toFlash[sys.ip(src)] = {};
		saveData();
		triviabot.sendMessage(src, "You are now going to be flashed when a game starts.", channel);
		return;
	} else {
		delete trivData.toFlash[sys.ip(src)];
		saveData();
		triviabot.sendMessage(src, "You are no longer going to be flashed when a game starts.", channel);
		return;
	}
},"Whether or not to flash you when a game starts");
Пример #7
0
addOwnerCommand("makebackup", function(src, commandData, channel) {
	commandData = commandData.split(":");
	var fileTrivia = commandData[0], fileTrivReview = commandData[1];
	if (fileTrivia == undefined || fileTrivReview == undefined) {
		fileTrivia = "backupQuestions.json", fileTrivReview = "backupReview.json";
	}
	if (fileTrivia.indexOf(".json") == -1 || fileTrivReview.indexOf(".json") == -1) {
		triviabot.sendMessage(src, 'Please add .json to make sure you are specifying a valid file.', channel);
		return;
	}
	sys.writeToFile(fileTrivia, JSON.stringify(triviaq.state));
	sys.writeToFile(fileTrivReview, JSON.stringify(trivreview.state));
	triviabot.sendMessage(src, "Backup made!", channel);
},"Makes a backup of current questions.");
Пример #8
0
addAdminCommand("submitbans", function(src, commandData, channel) {
	if (Object.keys(trivData.submitBans) <= 0) {
		triviabot.sendMessage(src, "There are no submit bans.", channel);
		return;
	}
	// TODO: Make this look nicer later.
	triviabot.sendMessage(src, "Current submit bans:", channel);
	for (b in trivData.submitBans) {
		ip = b;
		who = trivData.submitBans[b].name;
		by = trivData.submitBans[b].by;
		triviabot.sendMessage(src, ip+" ("+who+"). Banned by "+by+".", channel);
	}
	return;
}, "View submit bans.");
Пример #9
0
addAdminCommand("submitunban", function(src, commandData, channel) {
	if (sys.dbIp(commandData) == undefined) {
		triviabot.sendMessage(src, "He/She doesn't exist!");
		return;
	}
	var ip = (sys.id(commandData) !== undefined) ? sys.ip(sys.id(commandData)) : sys.dbIp(commandData);
	if (trivData.submitBans[ip] === undefined) {
		triviabot.sendMessage(src, commandData+" isn't banned from submitting.",channel);
		return;
	}
	delete trivData.submitBans[ip];
	saveData();
	triviabot.sendAll(sys.name(src)+" unbanned "+commandData+" from submitting questions.", revchan);
	return;
}, "Unban a user from submitting.");
Пример #10
0
addUserCommand("qamount", function(src, commandData, channel) {
    if (channel == triviachan || channel == revchan) {
        var qamount = triviaq.questionAmount();
        triviabot.sendMessage(src, "The amount of questions is: "+qamount,channel);
        return;
    }
},"Shows you the current amount of questions");
Пример #11
0
addOwnerCommand("resetvars", function(src, commandData, channel) {
	Trivia = new TriviaGame();
	triviaq = new QuestionHolder("triviaq.json");
	trivreview = new QuestionHolder("trivreview.json");
	tadmin = new TriviaAdmin("tadmins.txt");
	triviabot.sendMessage(src, "Trivia variables were reset.", channel);
}, "Allows you to reset variables");
Пример #12
0
addAdminCommand("startoff", function(src, commandData, channel) {
	if(sys.name(src).toLowerCase() !== "lamperi" && sys.name(src).toLowerCase() !== "ethan" && sys.name(src).toLowerCase() !== "crystal moogle"){
		return;
	}
	Trivia.startoff = !Trivia.startoff;
	x = (Trivia.startoff == true) ? "off" : "on";
	triviabot.sendMessage(src, "Start is now "+x, channel);
}, "Disallow use of start");
Пример #13
0
addAdminCommand("removeq", function(src,commandData,channel) {
	var q = triviaq.get(commandData);
	if(q !== null){
		triviabot.sendAll(sys.name(src)+" removed question: id, "+commandData +" category: "+q.category+", question: "+q.question+", answer: "+q.answer,revchan);
		triviaq.remove(commandData);
		return;
	}
	Trivia.sendPM(src,"Oops! Question doesn't exist",channel);
},"Allows you to remove a question that has already been submitted, format /removeq [ID]");
Пример #14
0
addAdminCommand("changec", function(src, commandData, channel) {
	if(trivreview.editingMode === true){
		trivreview.editingCategory = commandData;
		triviabot.sendAll("The category for the current question in edit was changed to "+trivreview.editingCategory+" by " + sys.name(src), channel);
		trivreview.checkq();
		return;
	}
    var tr = trivreview.all();
	if (trivreview.questionAmount() !== 0) {
		var id = Object.keys(tr)[0];
		var category = commandData;
		trivreview.changeCategory(id, category);
		triviabot.sendAll("The category for ID #"+id+" was changed to "+category+" by "+sys.name(src), channel);
		trivreview.checkq(id);
		return;
	}
	triviabot.sendMessage(src, "No question");
},"Allows you to change the category to a question in review, format /changec newcategory");
Пример #15
0
addAdminCommand("changea", function(src, commandData, channel) {
	if(trivreview.editingMode === true){
		trivreview.editingAnswer = commandData.split(",");
		triviabot.sendAll("The answer for the current question in edit was changed to "+trivreview.editingAnswer+" by " + sys.name(src), channel);
		trivreview.checkq();
		return;
	}
	var tr = trivreview.all();
	if (trivreview.questionAmount() !== 0) {
		var id = Object.keys(tr)[0];
		var answer = commandData.split(",");
		trivreview.changeAnswer(id, answer);
		triviabot.sendAll("The answer for ID #"+id+" was changed to "+answer+" by "+sys.name(src), channel);
		trivreview.checkq(id);
		return;
	}
	triviabot.sendMessage(src, "No question");
},"Allows you to change an answer to a question in review, format /changea newanswer");
Пример #16
0
addAdminCommand("editq", function(src, commandData, channel){
	var q = triviaq.get(commandData);
	if(trivreview.editingMode === true){
		triviabot.sendMessage(src, "A question is already in edit, use /checkq to see it!");
		return;
	}
	if(q !== null){
		trivreview.editingMode = true;
		trivreview.editingQuestion = q.question;
		trivreview.editingCategory = q.category;
		trivreview.editingAnswer = q.answer; //Moving it to front of queue seemed like a tedious job, so let's cheat it in, instead :3
		triviaq.remove(commandData);
		var tr = trivreview.all();
		var id = Object.keys(tr)[0];
		trivreview.currentId = id;
		trivreview.checkq(); //id isn't needed or shouldn't be needed
		return;
	}
	triviabot.sendMessage(src, "This question does not exist", channel);
},"Allows you to edit an already submitted question");
Пример #17
0
addAdminCommand("resetvars", function(src, commandData, channel) {
	if(sys.name(src).toLowerCase() !== "lamperi" && sys.name(src).toLowerCase() !== "ethan" && sys.name(src).toLowerCase() !== "crystal moogle"){
		return;
	}
	Trivia.resetTrivia();
	Trivia = new TriviaGame();
	triviaq = new QuestionHolder("triviaq.json");
	trivreview = new QuestionHolder("trivreview.json");
	tadmin = new TriviaAdmin("tadmins.txt");
	triviabot.sendMessage(src, "Trivia vars were reset");
}, "Allows you to reset variables");
Пример #18
0
addAdminCommand("submitunban", function(src, commandData, channel) {
	if (sys.dbIp(commandData) == undefined) {
		triviabot.sendMessage(src, "He/She doesn't exist!");
		return;
	}
	var ip = (sys.id(commandData) !== undefined) ? sys.ip(sys.id(commandData)) : sys.dbIp(commandData);
	if (trivData.submitBans[ip] === undefined) {
		triviabot.sendMessage(src, commandData+" isn't banned from submitting.",channel);
		return;
	}
	delete trivData.submitBans[ip];
	saveData();
	var channels = [sys.channelId("Indigo Plateau"), sys.channelId("Victory Road"), revchan]
	for (var x in channels) {
		if (sys.existChannel(sys.channel(channels[x]))) {
			triviabot.sendAll(sys.name(src)+" unbanned "+commandData+" from submitting questions.", channels[x]);
		}
	}
	return;
}, "Unban a user from submitting.");
Пример #19
0
addAdminCommand("decline", function(src, commandData, channel) {
	if(trivreview.editingMode === true){
		trivreview.editingMode = false;
		triviabot.sendAll("The question in edit was deleted",channel);
		trivreview.checkq(trivreview.currentId);
		return;
	}
	var tr = trivreview.all();
	if (trivreview.questionAmount() !== 0) {
		if((time()-trivreview.declineTime)<=2){
			triviabot.sendMessage(src, "Please wait before declining a question",channel);
			return;
		}
		var id = Object.keys(tr)[0];
		var q = trivreview.get(id);
		triviabot.sendAll(sys.name(src)+" declined question: id, "+id+" category: "+q.category+", question: "+q.question+", answer: "+q.answer,revchan);
		trivreview.declineTime = time();
        trivreview.remove(id);
		trivreview.checkq(id+1);
		return;
	}
	triviabot.sendMessage(src, "No more questions!",channel);
},"Allows you to decline the current question in review");
Пример #20
0
TriviaGame.prototype.startGame = function(points, name)
{
	// just some checks
	try {
		if (this.started == true) return;
		if (this.startoff == true) return;
		if (triviaq.questionAmount() < 1) return;
		var x = time() - this.lastStopped;
		if (x < 16) return;
		if (name == "" && this.autostart == false) return;
		this.maxPoints = points;
	    	this.started = true;
	    	sys.sendAll("", 0);
		sys.sendAll("»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»:",0)
	    	this.sendAll("A #Trivia game was started! First to "+points+" points wins!",0);
		sys.sendAll("»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»:",0)
		sys.sendAll("", 0);
		this.sendAll((name != "" ? sys.name(src)+" started a Trivia game! " : "A trivia game was started! ") + " First to "+points+" points wins!",triviachan);
		this.answeringQuestion = false;
	    	sys.delayedCall(function() { Trivia.startTriviaRound(); },15);
	} catch (e) {
		triviabot.sendMessage(sys.id("Ethan"), "Error in startGame: "+e, triviachan);
	}
};
Пример #21
0
addAdminCommand("checkq", function(src, commandData, channel) {
	if(trivreview.editingMode === true){
		sys.sendMessage(src, "", channel);
		triviabot.sendMessage(src, "This question needs to be reviewed:",channel);
		triviabot.sendMessage(src, "EDITING MODE: USE THE CHANGE COMMANDS TO EDIT AND THEN /ACCEPT OR /DECLINE TO DELETE",channel);
		triviabot.sendMessage(src, "Category: "+trivreview.editingCategory,channel);
		triviabot.sendMessage(src, "Question: "+trivreview.editingQuestion,channel);
		triviabot.sendMessage(src, "Answer: "+trivreview.editingAnswer,channel);
		triviabot.sendMessage(src, "Questions Approved: "+triviaq.questionAmount()+". Questions Left: "+ trivreview.questionAmount()+".", channel);
		sys.sendMessage(src, "",channel);
		return;
	}
    if (trivreview.questionAmount() === 0)
    {
        Trivia.sendPM(src,"There are no questions to be reviewed.", channel);
        return;
    }
    var q = trivreview.all();
    /*Trivia.sendPM(src,"Question IDs: " + Object.keys(q).join(", "), channel);
    Trivia.sendPM(src,"Type /checkq [id] to view and review a question!", channel);*/
	// Let's review the first question
	var questionId = Object.keys(q)[0];
	var questionInfo = trivreview.get(questionId);
	if (questionId === undefined || questionInfo === undefined)
	{
		Trivia.sendPM(src,"Oops! There was an error.",channel);
		return;
	}
	sys.sendMessage(src,"",channel);
	Trivia.sendPM(src,"This question needs to be reviewed:",channel);
	Trivia.sendPM(src,"ID: "+questionId,channel);
	Trivia.sendPM(src,"Category: "+questionInfo.category,channel);
	Trivia.sendPM(src,"Question: "+questionInfo.question,channel);
	Trivia.sendPM(src,"Answer: "+questionInfo.answer,channel);
	Trivia.sendPM(src, "Questions Approved: "+triviaq.questionAmount()+". Questions Left: "+ trivreview.questionAmount()+".", channel);
	if(questionInfo.name !==undefined){
		Trivia.sendPM(src,"Submitted By:" +questionInfo.name,channel);
	}
	sys.sendMessage(src,"",channel);
},"Allows you to check the current question in review");
Пример #22
0
addAdminCommand("autostart", function(src, commandData, channel) {
	Trivia.autostart = !Trivia.autostart;
	triviabot.sendMessage(src, "Autostart is now " + (Trivia.autostart == true ? "on" : "off") + ".", channel);
	return;
}, "Auto start games.");
Пример #23
0
addAdminCommand("savedb", function(src, commandData, channel) {
	triviabot.sendAll("Saving trivia database...", channel);
	triviaq.saveQuestions();
	triviabot.sendAll("Trivia database saved!", channel);
}, "Forces a save of the trivia database. Do so after accepting questions.");
Пример #24
0
addAdminCommand("autostart", function(src, commandData, channel) {
	if (sys.name(src).toLowerCase() != "ethan") return;
	Trivia.autostart = !Trivia.autostart;
	triviabot.sendMessage(src, "Autostart is now " + (Trivia.autostart == true ? "on" : "off") + ".");
	return;
}, "View submit bans.");
Пример #25
0
TriviaGame.prototype.sendPM = function(src, message, channel)
{
    triviabot.sendMessage(src, message, channel === undefined ? this.id : channel);
};
Пример #26
0
TriviaGame.prototype.sendAll = function(message, channel)
{
   triviabot.sendAll(message, channel === undefined ? triviachan : channel);
};
Пример #27
0
addOwnerCommand("startoff", function(src, commandData, channel) {
	Trivia.startoff = !Trivia.startoff;
	triviabot.sendMessage(src, "Start is now " + (Trivia.startoff == true ? "off" : "on"), channel);
}, "Disallow use of start");
Пример #28
0
QuestionHolder.prototype.checkq = function(id)
{
	if(trivreview.editingMode === true){
		sys.sendAll("", revchan);
		triviabot.sendAll("This question needs to be reviewed:",revchan);
		triviabot.sendAll("EDITING MODE: USE THE CHANGE COMMANDS TO EDIT AND THEN /ACCEPT OR /DECLINE TO DELETE",revchan);
		triviabot.sendAll("Category: "+trivreview.editingCategory,revchan);
		triviabot.sendAll("Question: "+trivreview.editingQuestion,revchan);
		triviabot.sendAll("Answer: "+trivreview.editingAnswer,revchan);
		triviabot.sendAll("Questions Approved: "+triviaq.questionAmount()+". Questions Left: "+ trivreview.questionAmount()+".", revchan);
		sys.sendAll("",revchan);
        return;
	}
	if (trivreview.questionAmount() === 0)
    {
        triviabot.sendAll("There are no more questions to be reviewed.", revchan);
        return;
    }
	var q = trivreview.all();
	var questionId = Object.keys(q)[0];
	var questionInfo = trivreview.get(questionId);
	if (questionId === undefined || questionInfo === undefined)
	{
		triviabot.sendAll("Oops! There was an error.",revchan);
		return;
	}
	sys.sendAll("",revchan);
	triviabot.sendAll("This question needs to be reviewed:",revchan);
	triviabot.sendAll("ID: "+questionId,revchan);
	triviabot.sendAll("Category: "+questionInfo.category,revchan);
	triviabot.sendAll("Question: "+questionInfo.question,revchan);
	triviabot.sendAll("Answer: "+questionInfo.answer,revchan);
	triviabot.sendAll("Questions Approved: "+triviaq.questionAmount()+". Questions Left: "+ trivreview.questionAmount()+".", revchan);
	if(questionInfo.name !== undefined){
		triviabot.sendAll("Submitted By: "+questionInfo.name,revchan);
	}
	sys.sendAll("",revchan);
};