<commit_before>/* Emoticons Plugin
 * This is a chat-plugin for an Emoticons system on PS
 * You will need a line in parser to actually  parse
 * this so that it works.  Also, you will need need to
 * add a few lines to the PM command.
 * Credits: panpawn, jd
 */

var fs = require('fs');
var serialize = require('node-serialize');
var emotes = {};
var Autolinker = require('autolinker');

if (typeof Gold === 'undefined') global.Gold = {};

Gold.emoticons = {
	maxChatEmotes: 4, //the default maximum number of emoticons in one chat message that gets parsed
	adminBypassMaxChatEmotes: true, //can administrators use as many emoticons as they wish?
	chatEmotes: {},
	processEmoticons: function(text) {
		var patterns = [],
		metachars = /[[\]{}()*+?.\\|^$\-,&#\s]/g,
		self = this;
		for (var i in this.chatEmotes) {
			if (this.chatEmotes.hasOwnProperty(i)) {
				patterns.push('(' + i.replace(metachars, "\\$&") + ')');
			}
		}
		return text.replace(new RegExp(patterns.join('|'), 'g'), function(match) {
			return typeof self.chatEmotes[match] != 'undefined' ?
				'<img src="' + self.chatEmotes[match] + '" title="' + match + '"/>' :
				match;
		});
	},
	checkEmoteModchat: function(user, room) {
		var rank = (user.group !== ' ' ? user.group : (room.auth ? room.auth[user.userid] : user.group));
		switch (room.emoteModChat) {
			case undefined:
			case false:
				return true;
				break;
			case 'ac':
			case 'autoconfirmed':
				return (user.autoconfirmed ? true : false);
				break;
			default:
				groups = Config.groupsranking;
				var i = groups.indexOf(rank); // rank # of user
				var u = groups.indexOf(room.emoteModChat); // rank # of emote modchat
				if (i >= u) return true;
		}
		return false;
	},
	userColor: function (color, text) {
		if (!text) text = color;
		return '<font color=' + Gold.hashColor(color) + '>' + Tools.escapeHTML(text) + '</font>';
	},
	processChatData: function(user, room, connection, message) {
		var match = false;
		var parsed_message = this.processEmoticons(message);
		for (var i in this.chatEmotes) {
			if (~message.indexOf(i)) {
				if ((parsed_message.match(/<img/g) || []).length <= this.maxChatEmotes || (this.adminBypassMaxChatEmotes && user.can('hotpatch'))) {
					match = true;
				} else {
					match = false;
				}
			}
		}
		switch (Users.ShadowBan.checkBanned(user) && match) {
			case true:
				origmsg = message;
				message = Tools.escapeHTML(message);
				message = this.processEmoticons(message);
				user.sendTo(room, '|html|' +
					' <small>' + user.getIdentity(room).substr(0,1) + '</small><strong class="username">' + this.userColor(user.name) + '</strong><b>' + this.userColor(user.name, ":") + '</b> &nbsp;' + message
				);
				room.update();
				Users.ShadowBan.addMessage(user, "To " + room, origmsg);
				break;
			case false:
				if (!this.checkEmoteModchat(user, room)) {
					kitty = message = this.processEmoticons(message);
					var message = Tools.escapeHTML(kitty);
					return (message);
					return;
				} else if (this.checkEmoteModchat(user, room)) {
					if (!match || message.charAt(0) === '!') return true;
					message = Tools.escapeHTML(message).replace(/&#x2f;/g, '/');
					message = this.processEmoticons(message);

					//PS formatting
					message = message.replace(/\_\_([^< ](?:[^<]*?[^< ])?)\_\_(?![^<]*?<\/a)/g, '<i>$1</i>'); // italics
					message = message.replace(/\*\*([^< ](?:[^<]*?[^< ])?)\*\*/g, '<b>$1</b>'); // bold
					message = message.replace(/\~\~([^< ](?:[^<]*?[^< ])?)\~\~/g, '<strike>$1</strike>'); // strikethrough
					message = Autolinker.link(message, {stripPrefix: false, phone: false, twitter: false});

					if (room.type === 'chat') {
						room.add('|uhtml|' + user.userid + '|<small>' + user.getIdentity(room).substr(0,1) + '</small><strong class="username">' + this.userColor(user.name) + '</strong><b>' + this.userColor(user.name, ":") + '</b> &nbsp;' + message);
						room.update();
						room.messageCount++;
					} else {
						room.addRaw(' <small>' + user.getIdentity(room).substr(0,1) + '</small><strong class="username">' + this.userColor(user.name) + '</strong><b>' + this.userColor(user.name, ":") + '</b> &nbsp;' + message);
						room.update();
						room.messageCount++;
					}
					return false;
				}
				break;
		}
	},
	processPMsParsing: function (message) {
		emoteRegex = [];
		for (var emote in this.chatEmotes) {
			emoteRegex.push(emote);
		}
		emoteRegex = new RegExp('(' + emoteRegex.join('|') + ')', 'g');
		self = this;
		if (emoteRegex.test(message)) {
			message = message.replace(emoteRegex, function (match) {
				return '<img src=' + self.chatEmotes[match] + ' title=' + match + '>';<commit_msg>Add nightclub support for emotes<commit_after>/* Emoticons Plugin
 * This is a chat-plugin for an Emoticons system on PS
 * You will need a line in parser to actually  parse
 * this so that it works.  Also, you will need need to
 * add a few lines to the PM command.
 * Credits: panpawn, jd
 */

var fs = require('fs');
var serialize = require('node-serialize');
var emotes = {};
var Autolinker = require('autolinker');

if (typeof Gold === 'undefined') global.Gold = {};

Gold.emoticons = {
	maxChatEmotes: 4, //the default maximum number of emoticons in one chat message that gets parsed
	adminBypassMaxChatEmotes: true, //can administrators use as many emoticons as they wish?
	chatEmotes: {},
	processEmoticons: function(text) {
		var patterns = [],
		metachars = /[[\]{}()*+?.\\|^$\-,&#\s]/g,
		self = this;
		for (var i in this.chatEmotes) {
			if (this.chatEmotes.hasOwnProperty(i)) {
				patterns.push('(' + i.replace(metachars, "\\$&") + ')');
			}
		}
		return text.replace(new RegExp(patterns.join('|'), 'g'), function(match) {
			return typeof self.chatEmotes[match] != 'undefined' ?
				'<img src="' + self.chatEmotes[match] + '" title="' + match + '"/>' :
				match;
		});
	},
	checkEmoteModchat: function(user, room) {
		var rank = (user.group !== ' ' ? user.group : (room.auth ? room.auth[user.userid] : user.group));
		switch (room.emoteModChat) {
			case undefined:
			case false:
				return true;
				break;
			case 'ac':
			case 'autoconfirmed':
				return (user.autoconfirmed ? true : false);
				break;
			default:
				groups = Config.groupsranking;
				var i = groups.indexOf(rank); // rank # of user
				var u = groups.indexOf(room.emoteModChat); // rank # of emote modchat
				if (i >= u) return true;
		}
		return false;
	},
	userColor: function (color, text) {
		if (!text) text = color;
		return '<font color=' + Gold.hashColor(color) + '>' + Tools.escapeHTML(text) + '</font>';
	},
	processChatData: function(user, room, connection, message) {
		var match = false;
		var parsed_message = this.processEmoticons(message);
		for (var i in this.chatEmotes) {
			if (~message.indexOf(i)) {
				if ((parsed_message.match(/<img/g) || []).length <= this.maxChatEmotes || (this.adminBypassMaxChatEmotes && user.can('hotpatch'))) {
					match = true;
				} else {
					match = false;
				}
			}
		}
		switch (Users.ShadowBan.checkBanned(user) && match) {
			case true:
				origmsg = message;
				message = Tools.escapeHTML(message);
				message = this.processEmoticons(message);
				user.sendTo(room, '|html|' +
					' <small>' + user.getIdentity(room).substr(0,1) + '</small><strong class="username">' + this.userColor(user.name) + '</strong><b>' + this.userColor(user.name, ":") + '</b> &nbsp;' + message
				);
				room.update();
				Users.ShadowBan.addMessage(user, "To " + room, origmsg);
				break;
			case false:
				if (!this.checkEmoteModchat(user, room)) {
					kitty = message = this.processEmoticons(message);
					var message = Tools.escapeHTML(kitty);
					return (message);
					return;
				} else if (this.checkEmoteModchat(user, room)) {
					if (!match || message.charAt(0) === '!') return true;
					message = Tools.escapeHTML(message).replace(/&#x2f;/g, '/');
					message = this.processEmoticons(message);

					//PS formatting
					message = message.replace(/\_\_([^< ](?:[^<]*?[^< ])?)\_\_(?![^<]*?<\/a)/g, '<i>$1</i>'); // italics
					message = message.replace(/\*\*([^< ](?:[^<]*?[^< ])?)\*\*/g, '<b>$1</b>'); // bold
					message = message.replace(/\~\~([^< ](?:[^<]*?[^< ])?)\~\~/g, '<strike>$1</strike>'); // strikethrough
					message = Autolinker.link(message, {stripPrefix: false, phone: false, twitter: false});

					let msg = '<small>' + user.getIdentity(room).substr(0,1) + '</small><strong class="username">' + this.userColor(user.name) + '</strong><b>' + this.userColor(user.name, ":") + '</b> &nbsp;' + message;
					if (nightclubs[room.id]) msg = '<div style = "color: white; background: black; font-size: 11pt; text-shadow: 0px 0px 10px, 0px 0px 10px, 0px 0px 10px; padding:1px; margin:-3px;">' + msg + '</div>';
					if (room.type === 'chat') {
						room.add('|uhtml|' + user.userid + '|' + msg);
						room.update();
						room.messageCount++;
					} else {
						room.addRaw(msg);
						room.update();
						room.messageCount++;
					}
					return false;
				}
				break;
		}
	},
	processPMsParsing: function (message) {
		emoteRegex = [];
		for (var emote in this.chatEmotes) {
			emoteRegex.push(emote);
		}
		emoteRegex = new RegExp('(' + emoteRegex.join('|') + ')', 'g');
		self = this;
		if (emoteRegex.test(message)) {
			message = message.replace(emoteRegex, function (match) {
				return '<img src=' + self.chatEmotes[match] + ' title=' + match + '>';
{'fraction_non_alphanumeric': 0.19893446989877464, 'fraction_numerical': 0.004049014384656367, 'mean_word_length': 3.4315391879131254, 'pattern_counts': {'":': 5, '<': 81, '<?xml version=': 0, '>': 57, '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': '6579957', 'n_tokens_mistral': 3799, 'n_tokens_neox': 3236, 'n_words': 740}