<commit_before>/*jslint node: true*/
/* global $uc */

var _ = require('underscore');
var path = require('path');
var sprintf = require('util').format;

var pluginUserCenter = function () {
	global.$uc = this;
	this.plugDir = 'uc.d';
	this.loadPluginConfig  ();
};

pluginUserCenter.prototype = {
	name  : '用户中心!',
	ver   : '1.0',
	author: 'Jixun',
	desc  : '用户签到以及其他功能，依赖 db 模组。',

	load: function () {
		this.init (this.bot);
		this.registerEvents ();
		this.loadPluginModules ();
	},

	init: function (Bot) {
		this.mod = Bot.mod;
		this.ext = Bot.mod.db;
		this.db = this.ext.db;
		
		Bot.mod.log.info ('Init uc database ...');
		this.db.query (sprintf(this.ext.__(function () {/*
		create table if not exists `jB_user` (
			`qNum` VARCHAR(20) NOT NULL,
			`userNick` VARCHAR(20) NULL,
			`tLastSign` TIMESTAMP NULL,
			`dMoneyLeft` FLOAT NULL,
			`pems` text NULL,
			UNIQUE INDEX `qNum` (`qNum` ASC)
		)ENGINE = %s DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		*/}), this.ext.conf.engine));
	},

	// uc.d/sign.js for the complete version.
	can: function (u, n, def) {
		return def;
	},

	newUser: function (qqNum, cb) {
		var self = this;
		
		self.db.query('insert ignore into `jB_user` (`qNum`, `dMoneyLeft`) values (?, ?)', 
							[qqNum, self.bot.conf.user.default.dMoneyLeft]);
		
		cb (_.extend({
			qNum: qqNum,
			isNew: true,
			pems: {can: [], no: []}
		}, this.bot.conf.user.default));
	},
	getUser: function (uin, cb) {
		if (!cb) return null; // Invalid request.
		
		var self = this;
		var userNum = self.bot.friendHashTable.table[uin];
		if (userNum) {
			self.getUserByNum (userNum, cb);
			return ;
		}
		
		self.bot.log.warn ('User not found for uin:', uin);
		self.bot.uinToNum(uin, false, function (userNum) {
			self.getUserByNum (userNum, cb);
		});
	},
	getUserByNum: function (userNum, cb) {
		if (!cb) return null; // Invalid request.
		
		var self = this;
		
		var queueName = 'uc-get-user-' + userNum;
		<commit_msg>Reduce warning about uin not in cache<commit_after>/*jslint node: true*/
/* global $uc */

var _ = require('underscore');
var path = require('path');
var sprintf = require('util').format;

var pluginUserCenter = function () {
	global.$uc = this;
	this.plugDir = 'uc.d';
	this.loadPluginConfig  ();
};

pluginUserCenter.prototype = {
	name  : '用户中心!',
	ver   : '1.0',
	author: 'Jixun',
	desc  : '用户签到以及其他功能，依赖 db 模组。',

	load: function () {
		this.init (this.bot);
		this.registerEvents ();
		this.loadPluginModules ();
	},

	init: function (Bot) {
		this.mod = Bot.mod;
		this.ext = Bot.mod.db;
		this.db = this.ext.db;
		
		Bot.mod.log.info ('Init uc database ...');
		this.db.query (sprintf(this.ext.__(function () {/*
		create table if not exists `jB_user` (
			`qNum` VARCHAR(20) NOT NULL,
			`userNick` VARCHAR(20) NULL,
			`tLastSign` TIMESTAMP NULL,
			`dMoneyLeft` FLOAT NULL,
			`pems` text NULL,
			UNIQUE INDEX `qNum` (`qNum` ASC)
		)ENGINE = %s DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		*/}), this.ext.conf.engine));
	},

	// uc.d/sign.js for the complete version.
	can: function (u, n, def) {
		return def;
	},

	newUser: function (qqNum, cb) {
		var self = this;
		
		self.db.query('insert ignore into `jB_user` (`qNum`, `dMoneyLeft`) values (?, ?)', 
							[qqNum, self.bot.conf.user.default.dMoneyLeft]);
		
		cb (_.extend({
			qNum: qqNum,
			isNew: true,
			pems: {can: [], no: []}
		}, this.bot.conf.user.default));
	},
	getUser: function (uin, cb) {
		if (!cb) return null; // Invalid request.
		
		var self = this;
		var userNum = self.bot.friendHashTable.table[uin] || self.bot.uinCache.table[uin];
		if (userNum) {
			self.getUserByNum (userNum, cb);
			return ;
		}
		
		self.bot.log.warn ('User not found for uin:', uin);
		self.bot.uinToNum(uin, false, function (userNum) {
			self.getUserByNum (userNum, cb);
		});
	},
	getUserByNum: function (userNum, cb) {
		if (!cb) return null; // Invalid request.
		
		var self = this;
		
		var queueName = 'uc-get-user-' + userNum;
		
{'fraction_non_alphanumeric': 0.1755050505050505, 'fraction_numerical': 0.00404040404040404, 'mean_word_length': 3.2138297872340424, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2305945', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1535, 'n_words': 361}