<commit_before>/*
Emoticon plugin
This plugin allows you to use emoticons in both chat rooms (as long as they are enabled in the room) and private messages.

Adding this plugin to your server is fairly simple.
1) Add this file to your chat-plugins folder.
2) Open the rooms.js file in your favourite text editor and replace this.add('|c|' + user.getIdentity(this.id) + '|' + message); with:
    var emoticons = parseEmoticons(user.getIdentity(this.roomid), message);
    if (emoticons && !room.disableEmoticons) {
        this.addRaw(emoticons);
    } else {
        this.add('|c|' + user.getIdentity(this.id) + '|' + message);
    }

3) Open the commands.js file and find "var message = '|pm|' + user.getIdentity() + '|' + targetUser.getIdentity() + '|' + target;"
    Once you find that line place the following above it:
    var emoticons = parseEmoticons(user.getIdentity(room.id), target);
    if (emoticons) {
        target = "/html " + emoticons;
    }
*/
 
var fs = require('fs');
var emoticons = {'feelsbd': 'http://i.imgur.com/TZvJ1lI.png'};
var emoteRegex = new RegExp('feelsbd', 'g');
 
function loadEmoticons () {
    try {
        emoticons = JSON.parse(fs.readFileSync('config/emoticons.json', 'utf8'));
        emoteRegex = [];
        for (var emote in emoticons) {
            emoteRegex.push(escapeRegExp(emote));
        }
        emoteRegex = new RegExp('(' + emoteRegex.join('|') + ')', 'g');
    } catch (e) {}
}
loadEmoticons();
 
function saveEmoticons () {
    fs.writeFileSync('config/emoticons.json', JSON.stringify(emoticons));
    emoteRegex = [];
    for (var emote in emoticons) {
        emoteRegex.push(emote);
    }
    emoteRegex = new RegExp('(' + emoteRegex.join('|') + ')', 'g');
}
 
function parseEmoticons (user, message) {
    var html = user.charAt(0) + '<button class="astext" name="parseCommand" value="/user ' + toId(user) + '">' + '<b><font color="' + hashColor(toId(user)) + '">' + Tools.escapeHTML(user.substr(1)) + ':</font></b></button> ';
	if (emoteRegex.test(message)) {
			message = Tools.escapeHTML(message).replace(emoteRegex, function (match) {
			return '<img src=' + emoticons[match] + '>';
		});
		return html + message;
	}
	return false;
}<commit_msg>Change how the button looks.<commit_after>/*
Emoticon plugin
This plugin allows you to use emoticons in both chat rooms (as long as they are enabled in the room) and private messages.

Adding this plugin to your server is fairly simple.
1) Add this file to your chat-plugins folder.
2) Open the rooms.js file in your favourite text editor and replace this.add('|c|' + user.getIdentity(this.id) + '|' + message); with:
    var emoticons = parseEmoticons(user.getIdentity(this.roomid), message);
    if (emoticons && !room.disableEmoticons) {
        this.addRaw(emoticons);
    } else {
        this.add('|c|' + user.getIdentity(this.id) + '|' + message);
    }

3) Open the commands.js file and find "var message = '|pm|' + user.getIdentity() + '|' + targetUser.getIdentity() + '|' + target;"
    Once you find that line place the following above it:
    var emoticons = parseEmoticons(user.getIdentity(room.id), target);
    if (emoticons) {
        target = "/html " + emoticons;
    }
*/
 
var fs = require('fs');
var emoticons = {'feelsbd': 'http://i.imgur.com/TZvJ1lI.png'};
var emoteRegex = new RegExp('feelsbd', 'g');
 
function loadEmoticons () {
    try {
        emoticons = JSON.parse(fs.readFileSync('config/emoticons.json', 'utf8'));
        emoteRegex = [];
        for (var emote in emoticons) {
            emoteRegex.push(escapeRegExp(emote));
        }
        emoteRegex = new RegExp('(' + emoteRegex.join('|') + ')', 'g');
    } catch (e) {}
}
loadEmoticons();
 
function saveEmoticons () {
    fs.writeFileSync('config/emoticons.json', JSON.stringify(emoticons));
    emoteRegex = [];
    for (var emote in emoticons) {
        emoteRegex.push(emote);
    }
    emoteRegex = new RegExp('(' + emoteRegex.join('|') + ')', 'g');
}
 
function parseEmoticons (user, message) {
    var html = user.charAt(0) + '<button class="emote-chat" name="parseCommand" value="/user ' + toId(user) + '">' + '<b><font color="' + hashColor(toId(user)) + '">' + Tools.escapeHTML(user.substr(1)) + ':</font></b></button> ';
	if (emoteRegex.test(message)) {
			message = Tools.escapeHTML(message).replace(emoteRegex, function (match) {
			return '<img src=' + emoticons[match] + '>';
		});
		return html + message;
	}
	return false;
}
{'fraction_non_alphanumeric': 0.16692913385826771, 'fraction_numerical': 0.0031496062992125984, 'mean_word_length': 3.532110091743119, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2727306', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1493, 'n_words': 372}