<commit_before>/*
	Developer: Marzavec
	Use it as you'd like, but I'd appreciate a mention n_n
*/

triviaEngine = {
  isEngaged: false,
  currentSocket: null,
  userNick: null,
  userTrip: null,
  userID: 0,
	userPoints: 0,
	userProf: "",
	questionTimeout: 0,
	questionID: 0,
	questionPoints: 0,
	questionCat: "",
	questionAnswer: "",

	startNew: function(data, cat){
    this.isEngaged = true;
    this.currentSocket = data.socket;

		this.getUserData(data.nick, data.trip);

		cat = typeof cat === 'undefined' ? '1' : '`cat` = ' + mysql.escape(secureAlphaNumeric(cat));

		var sqlQuery = "SELECT `id`, `points`, `tta`, `cat`, `question`, `answer` FROM `questions` WHERE " + cat + " ORDER BY RAND() LIMIT 1";
		sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
			if(rows.length == 0){
				var sqlQuery = "SELECT `id`, `points`, `tta`, `cat`, `question`, `answer` FROM `questions` WHERE 1 ORDER BY RAND() LIMIT 1";
				sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
					if(rows.length == 0){
            this.currentSocket.say('There was a problem finding a question.');
            console.log('SQL Error: ' + err);
        		logEngine.add('SQL', err);
						return;
					}

					triviaEngine.initializeNewQuestion(rows[0]);
				});
				return;
			}

			triviaEngine.initializeNewQuestion(rows[0]);
		});
	},

	getUserData: function(userNick, userTrip){
    this.userNick = userNick;
    this.userTrip = userTrip;

		var sqlQuery = "SELECT `id`, `bridgeid`, `points`, `prof` FROM `points` WHERE `nick` = " + mysql.escape(userNick) + " AND `trip` = " + mysql.escape(userTrip) + " LIMIT 1";
		sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
			if(rows.length == 0){
				var sqlQuery = "INSERT INTO `points` (`id`, `bridgeid`, `trip`, `nick`, `points`, `prof`) VALUES (NULL, '0', " + mysql.escape(userTrip) + ", " + mysql.escape(userNick) + ", '0', '[]')";
				sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
					sqlEngine.sqlCon.query("SELECT LAST_INSERT_ID() AS `userID`", function(err, rows){
						triviaEngine.userID = rows[0].userID;
						triviaEngine.userPoints = 0;
						triviaEngine.userProf = [];
					});
				});
				return;
			}

			triviaEngine.userID = rows[0].id;
			if(rows[0].bridgeid != 0) triviaEngine.userID = rows[0].bridgeid;
			triviaEngine.userPoints = rows[0].points;
			triviaEngine.userProf = JSON.parse(rows[0].prof);
		});
	},

	initializeNewQuestion: function(data){
		this.questionID = data.id;
		this.questionPoints = data.points;
		this.questionCat = data.cat;
		this.questionAnswer = JSON.parse(data.answer);

		this.currentSocket.say("@" + this.userNick + "; the category is: " +
                           data.cat + " & for " +
                           colorize(String(data.points), 'green') +
                           " points, " + colorize(data.tta, 'red') +
                           " seconds to answer!\n" + data.question);

		this.questionTimeout = setTimeout(function(){
      triviaEngine.questionTimedOut();
    }, data.tta * 1000);
	},

	gaveAnswer: function(data){
		clearTimeout(this.questionTimeout);

		if(data == "pass"){
			this.questionPoints = Math.floor(this.questionPoints * 0.3);

			this.currentSocket.say("@" + this.userNick + ", no one likes a quitter. . . Lost " + colorize(String(this.questionPoints), 'green') + " points. Total: " + String(triviaEngine.userPoints - triviaEngine.questionPoints));<commit_msg>Just a color change.<commit_after>/*
	Developer: Marzavec
	Use it as you'd like, but I'd appreciate a mention n_n
*/

triviaEngine = {
  isEngaged: false,
  currentSocket: null,
  userNick: null,
  userTrip: null,
  userID: 0,
	userPoints: 0,
	userProf: "",
	questionTimeout: 0,
	questionID: 0,
	questionPoints: 0,
	questionCat: "",
	questionAnswer: "",

	startNew: function(data, cat){
    this.isEngaged = true;
    this.currentSocket = data.socket;

		this.getUserData(data.nick, data.trip);

		cat = typeof cat === 'undefined' ? '1' : '`cat` = ' + mysql.escape(secureAlphaNumeric(cat));

		var sqlQuery = "SELECT `id`, `points`, `tta`, `cat`, `question`, `answer` FROM `questions` WHERE " + cat + " ORDER BY RAND() LIMIT 1";
		sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
			if(rows.length == 0){
				var sqlQuery = "SELECT `id`, `points`, `tta`, `cat`, `question`, `answer` FROM `questions` WHERE 1 ORDER BY RAND() LIMIT 1";
				sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
					if(rows.length == 0){
            this.currentSocket.say('There was a problem finding a question.');
            console.log('SQL Error: ' + err);
        		logEngine.add('SQL', err);
						return;
					}

					triviaEngine.initializeNewQuestion(rows[0]);
				});
				return;
			}

			triviaEngine.initializeNewQuestion(rows[0]);
		});
	},

	getUserData: function(userNick, userTrip){
    this.userNick = userNick;
    this.userTrip = userTrip;

		var sqlQuery = "SELECT `id`, `bridgeid`, `points`, `prof` FROM `points` WHERE `nick` = " + mysql.escape(userNick) + " AND `trip` = " + mysql.escape(userTrip) + " LIMIT 1";
		sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
			if(rows.length == 0){
				var sqlQuery = "INSERT INTO `points` (`id`, `bridgeid`, `trip`, `nick`, `points`, `prof`) VALUES (NULL, '0', " + mysql.escape(userTrip) + ", " + mysql.escape(userNick) + ", '0', '[]')";
				sqlEngine.sqlCon.query(sqlQuery, function(err, rows){
					sqlEngine.sqlCon.query("SELECT LAST_INSERT_ID() AS `userID`", function(err, rows){
						triviaEngine.userID = rows[0].userID;
						triviaEngine.userPoints = 0;
						triviaEngine.userProf = [];
					});
				});
				return;
			}

			triviaEngine.userID = rows[0].id;
			if(rows[0].bridgeid != 0) triviaEngine.userID = rows[0].bridgeid;
			triviaEngine.userPoints = rows[0].points;
			triviaEngine.userProf = JSON.parse(rows[0].prof);
		});
	},

	initializeNewQuestion: function(data){
		this.questionID = data.id;
		this.questionPoints = data.points;
		this.questionCat = data.cat;
		this.questionAnswer = JSON.parse(data.answer);

		this.currentSocket.say("@" + this.userNick + "; the category is: " +
                           data.cat + " & for " +
                           colorize(String(data.points), 'green') +
                           " points, " + colorize(data.tta, 'red') +
                           " seconds to answer!\n" + data.question);

		this.questionTimeout = setTimeout(function(){
      triviaEngine.questionTimedOut();
    }, data.tta * 1000);
	},

	gaveAnswer: function(data){
		clearTimeout(this.questionTimeout);

		if(data == "pass"){
			this.questionPoints = Math.floor(this.questionPoints * 0.3);

			this.currentSocket.say("@" + this.userNick + ", no one likes a quitter. . . Lost " + colorize(String(this.questionPoints), 'yellow') + " points. Total: " + String(triviaEngine.userPoints - triviaEngine.questionPoints));
{'fraction_non_alphanumeric': 0.1651012621074259, 'fraction_numerical': 0.009098914000587027, 'mean_word_length': 3.3214965123652505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3479124', 'n_tokens_mistral': 2589, 'n_tokens_neox': 2267, 'n_words': 478}