<commit_before>/*
 * Copyright (c) 2014, <NAME>, https://bitbucket.org/sgt-kabukiman/
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

var
	BasePlugin = require('./../Base.js'),
	Manager    = require('./EmoteManager.js'),
	numeral    = require('numeral'),
	util       = require('util');

function EmoteCounterPlugin() {
	BasePlugin.call(this);

	this.manager     = null;
	this.txtListener = null;
	this.cmdListener = null;
	this.table       = 'emote_counter';
	this.stats       = {};
}

util.inherits(EmoteCounterPlugin, BasePlugin);

EmoteCounterPlugin.prototype.setup = function(kabukibot, eventDispatcher) {
	BasePlugin.prototype.setup.call(this, kabukibot, eventDispatcher);

	eventDispatcher.onCommand(true, this.onGlobalCommand.bind(this));

	this.manager     = new Manager(kabukibot.getLog());
	this.txtListener = this.onText.bind(this);
	this.cmdListener = this.onCommand.bind(this);

	this.manager.fetchEmotes();
	this.manager.initUpdater(3*3600*1000); // update every 3 hours

	// sync emote counter with database every 30 minutes
	setInterval(this.syncAll.bind(this), 30*60*1000);

	if (this.bot.getConfig().database.driver === 'sqlite') {
		this.db.query('CREATE TABLE IF NOT EXISTS ' + this.table + ' (channel VARCHAR(200), emote VARCHAR(50), counter INTEGER UNSIGNED, PRIMARY KEY (channel, emote))');
	}
	else {
		this.db.query('CREATE TABLE IF NOT EXISTS ' + this.table + ' (channel VARCHAR(200), emote VARCHAR(50), counter INTEGER UNSIGNED, PRIMARY KEY (channel, emote)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
	}
};

EmoteCounterPlugin.prototype.getKey = function() {
	return 'emote_counter';
};

EmoteCounterPlugin.prototype.getACLTokens = function() {
	return ['use_emote_counter'];
};

EmoteCounterPlugin.prototype.load = function(channel, kabukibot, eventDispatcher) {
	var chan = channel.getName(), self = this;

	this.stats[chan] = {};<commit_msg>there has been at least one case where a sub emote was replaced by another one that just differs in capitalization...<commit_after>/*
 * Copyright (c) 2014, <NAME>, https://bitbucket.org/sgt-kabukiman/
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

var
	BasePlugin = require('./../Base.js'),
	Manager    = require('./EmoteManager.js'),
	numeral    = require('numeral'),
	util       = require('util');

function EmoteCounterPlugin() {
	BasePlugin.call(this);

	this.manager     = null;
	this.txtListener = null;
	this.cmdListener = null;
	this.table       = 'emote_counter';
	this.stats       = {};
}

util.inherits(EmoteCounterPlugin, BasePlugin);

EmoteCounterPlugin.prototype.setup = function(kabukibot, eventDispatcher) {
	BasePlugin.prototype.setup.call(this, kabukibot, eventDispatcher);

	eventDispatcher.onCommand(true, this.onGlobalCommand.bind(this));

	this.manager     = new Manager(kabukibot.getLog());
	this.txtListener = this.onText.bind(this);
	this.cmdListener = this.onCommand.bind(this);

	this.manager.fetchEmotes();
	this.manager.initUpdater(3*3600*1000); // update every 3 hours

	// sync emote counter with database every 30 minutes
	setInterval(this.syncAll.bind(this), 30*60*1000);

	if (this.bot.getConfig().database.driver === 'sqlite') {
		this.db.query('CREATE TABLE IF NOT EXISTS ' + this.table + ' (channel VARCHAR(200), emote TINYBLOB, counter INTEGER UNSIGNED, PRIMARY KEY (channel, emote(50)))');
	}
	else {
		this.db.query('CREATE TABLE IF NOT EXISTS ' + this.table + ' (channel VARCHAR(200), emote TINYBLOB, counter INTEGER UNSIGNED, PRIMARY KEY (channel, emote(50))) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
	}
};

EmoteCounterPlugin.prototype.getKey = function() {
	return 'emote_counter';
};

EmoteCounterPlugin.prototype.getACLTokens = function() {
	return ['use_emote_counter'];
};

EmoteCounterPlugin.prototype.load = function(channel, kabukibot, eventDispatcher) {
	var chan = channel.getName(), self = this;

	this.stats[chan] = {};
{'fraction_non_alphanumeric': 0.13739914570479356, 'fraction_numerical': 0.0170859041290935, 'mean_word_length': 4.62, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3377337', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1349, 'n_words': 320}