<commit_before>//Nightclub by SilverTactic (Siiilver) and panpawn
'use strict';

if (!global.nightclubs) global.nightclubs = {};
let nightclubs = global.nightclubs;

function getColor() {
	let color = '#';
	for (let i = 0; i < 6; i++) {
		color += 'ABCDE'[Math.floor(Math.random() * 5)];
	}
	return color;
}

function colorify(message) {
	let total = '';
	for (let i = 0; i < message.length; i++) {
		if (message[i] === ' ') {
			total += ' ';
			continue;
		}
		total += '<span style = "color: ' + getColor() + '">' + message[i] + '</span>';
	}
	return total;
}

function formatHTML(message) {
	let escapes = ['&amp;', '&lt;', '&gt;', '&gt;', '&quot;', '&apos;', '&#x2f;'];
	if (!message) return '';
	let total = '';
	for (let i = 0; i < message.length; i++) {
		if (message[i] === '&') {
			let sub = message.substr(i);
			let part = sub.substr(0, sub.indexOf(';') + 1);
			if (escapes.indexOf(part) > -1) {
				i += part.length - 1;
				total += '<span style = "color: ' + getColor() + '">' + part + '</span>';
				continue;
			}
		}
		if (message[i] === '<') {
			let sub = message.substr(i).match(/<(span|b|a|i|code|s)[^]+<\/(span|b|a|i|code|s)>/);
			if (sub) {
				if (/<(a|b|i|s)>/.test(sub[0].substr(0, 3))) {
					total += sub[0].substr(0, 3) + colorify(sub[0].substr(3, sub[0].length - 7)) + sub[0].substr(sub[0].length - 4);
				} else {
					total += sub[0];
				}
				i += sub[0].length - 1;
				continue;
			}
		}
		total += '<span style = "color: ' + getColor() + '">' + message[i].escapeHTML() + '</span>';
	}
	return total;
}

function formatMessage(message) {
	message = message.replace(/\_\_([^ ](?:[^]*?[^ ])?)\_\_(?![^]*?<\/a)/g, '<i>$1</i>') //italics
		.replace(/\*\*([^ ](?:[^]*?[^ ])?)\*\*/g, '<b>$1</b>') //bold
		.replace(/\~\~([^ ](?:[^]*?[^ ])?)\~\~/g, '<s>$1</s>') //strikethrough
		.replace(/\`\`([^ ](?:[^]*?[^ ])?)\`\`/g, '<code>$1</code>') //code
		//urls
		.replace(/(https?\:\/\/[a-z0-9-.]+(\/([^\s]*[^\s?.,])?)?|[a-z0-9]([a-z0-9-\.]*[a-z0-9])?\.(com|org|net|edu|tk|us)((\/([^\s]*[^\s?.,])?)?|\b))/ig, '<a href="$1" target="_blank">$1</a>')<commit_msg>Fix a crash in nightclub<commit_after>//Nightclub by SilverTactic (Siiilver) and panpawn
'use strict';

if (!global.nightclubs) global.nightclubs = {};
let nightclubs = global.nightclubs;

function getColor() {
	let color = '#';
	for (let i = 0; i < 6; i++) {
		color += 'ABCDE'[Math.floor(Math.random() * 5)];
	}
	return color;
}

function colorify(message) {
	let total = '';
	for (let i = 0; i < message.length; i++) {
		if (message[i] === ' ') {
			total += ' ';
			continue;
		}
		total += '<span style = "color: ' + getColor() + '">' + message[i] + '</span>';
	}
	return total;
}

function formatHTML(message) {
	let escapes = ['&amp;', '&lt;', '&gt;', '&gt;', '&quot;', '&apos;', '&#x2f;'];
	if (!message) return '';
	let total = '';
	for (let i = 0; i < message.length; i++) {
		if (message[i] === '&') {
			let sub = message.substr(i);
			let part = sub.substr(0, sub.indexOf(';') + 1);
			if (escapes.indexOf(part) > -1) {
				i += part.length - 1;
				total += '<span style = "color: ' + getColor() + '">' + part + '</span>';
				continue;
			}
		}
		if (message[i] === '<') {
			let sub = message.substr(i).match(/<(span|b|a|i|code|s)[^]+<\/(span|b|a|i|code|s)>/);
			if (sub) {
				if (/<(a|b|i|s)>/.test(sub[0].substr(0, 3))) {
					total += sub[0].substr(0, 3) + colorify(sub[0].substr(3, sub[0].length - 7)) + sub[0].substr(sub[0].length - 4);
				} else {
					total += sub[0];
				}
				i += sub[0].length - 1;
				continue;
			}
		}
		total += '<span style = "color: ' + getColor() + '">' + Chat.escapeHTML(message[i])+ '</span>';
	}
	return total;
}

function formatMessage(message) {
	message = message.replace(/\_\_([^ ](?:[^]*?[^ ])?)\_\_(?![^]*?<\/a)/g, '<i>$1</i>') //italics
		.replace(/\*\*([^ ](?:[^]*?[^ ])?)\*\*/g, '<b>$1</b>') //bold
		.replace(/\~\~([^ ](?:[^]*?[^ ])?)\~\~/g, '<s>$1</s>') //strikethrough
		.replace(/\`\`([^ ](?:[^]*?[^ ])?)\`\`/g, '<code>$1</code>') //code
		//urls
		.replace(/(https?\:\/\/[a-z0-9-.]+(\/([^\s]*[^\s?.,])?)?|[a-z0-9]([a-z0-9-\.]*[a-z0-9])?\.(com|org|net|edu|tk|us)((\/([^\s]*[^\s?.,])?)?|\b))/ig, '<a href="$1" target="_blank">$1</a>')
{'fraction_non_alphanumeric': 0.3301526717557252, 'fraction_numerical': 0.019083969465648856, 'mean_word_length': 3.235353535353535, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7188435', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1817, 'n_words': 321}