<commit_before>/*
 * Chat log viewer plugin by jd
 */
var fs = require('fs');
var sanitizeHtml = require('sanitize-html');

function sanitizeHTML(html) {
	return sanitizeHtml(html, {
		allowedTags: [ 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', 'nl', 'li', 'b', 'i', 'strong', 'em',
			'strike', 'code', 'hr', 'br', 'div', 'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'img', 'font',
			'center', 'button'],
		allowedAttributes: {
		  a: [ 'href', 'name', 'target' ],
		  img: [ 'src' ],
		  br: ['clear'],
		  div: ['class'],
		  font: ['color', 'size'],
		  button: ['name', 'value', 'class']
		},
	});
}

exports.commands = {
	viewlogs: function(target, room, user) {
		if (!target) return this.sendReply("Usage: /viewlogs [room], [year-month-day / 2014-12-08] - Provides you with a temporary link to view the target rooms chat logs.");
		var targetSplit = target.split(',');
		if (!targetSplit[1]) return this.sendReply("Usage: /viewlogs [room], [year-month-day / 2014-12-08] -Provides you with a temporary link to view the target rooms chat logs.");
		for (var u in targetSplit) targetSplit[u] = targetSplit[u].trim();
		var targetRoom = targetSplit[0];
		if (!user.can('lock') && !user.can('roommod', null, Rooms(targetRoom))) return this.sendReply("/viewlogs - Access denied.");
		if (toId(targetRoom) === 'staff' && !user.can('warn')) return this.sendReply("/viewlogs - Access denied.");
		if (toId(targetRoom) === 'administrators' && !user.can('hotpatch')) return this.sendReply("/viewlogs - Access denied.");
		if (toId(targetRoom) === 'upperstaff' && !user.can('pban')) return this.sendReply("/viewlogs - Access denied.");
		if (Rooms(targetRoom) && Rooms(targetRoom).isPrivate && !user.can('pban')) {
			if (Rooms(targetRoom) && Rooms(targetRoom).isPrivate && !user.can('roommod', null, Rooms(targetRoom))) return this.sendReply("/viewlogs - Access denied.");
		}
		var date = '';
		if (toId(targetSplit[1]) === 'today' || toId(targetSplit[1]) === 'yesterday') {
			date = new Date();
			if (toId(targetSplit[1]) === 'yesterday') date.setDate(date.getDate() - 1);
			targetSplit[1] = date.format('{dd}-{MM}-{yyyy}');
		}
		date = targetSplit[1];
		var splitDate = date.split('-');
		if (splitDate.length < 3) return this.sendReply("Usage: /viewlogs [room], [year-month-day / 2014-12-08] -Provides you with a temporary link to view the target rooms chat logs.");
		var self = this;

		fs.readFile('logs/chat/' + toId(targetRoom) + '/' + splitDate[0] + '-' + splitDate[1] + '/' + date + '.txt', 'utf8', function(err, data) {
			if (err) return self.sendReply("/viewlogs - Error: " + err);
			var filename = require('crypto').randomBytes(16).toString('hex') + '.html';
			var newDate = new Date();
			data = data.split('\n');
			var newFile = ['<html>',
			'<head><link rel="stylesheet" type="text/css" href="http://goldservers.info/style/client.css"><link rel="stylesheet" type="text/css" href="http://goldservers.info/js/style.css">' +
			'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>',
			'<div class="header"><img class="logo" src="http://i.imgur.com/fJwCDif.png" height="45" alt="Gold!"><center><font color=red>Room: ' + Tools.escapeHTML(targetRoom) +
			' Date: ' + Tools.escapeHTML(date) + '</font><br />' ,
			'<font color=red>Logs obtained ' + newDate.toUTCString() + ' by ' + Tools.escapeHTML(user.name) + '</font></center><div class="maintabbarbottom"></div></div>',
			'<div class="ps-room ps-room-light">','<div class="chat-log" style="bottom:0px;">','<div class="inner">'];

			for (var u in data) {
				var timestamp = data[u].substr(0, 9).trim();
				var line = data[u].substr(9, data[u].length);<commit_msg>Fix /viewlogs room, [yesterday/today] not worrking<commit_after>/*
 * Chat log viewer plugin by jd
 */
var fs = require('fs');
var sanitizeHtml = require('sanitize-html');

function sanitizeHTML(html) {
	return sanitizeHtml(html, {
		allowedTags: [ 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', 'nl', 'li', 'b', 'i', 'strong', 'em',
			'strike', 'code', 'hr', 'br', 'div', 'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'img', 'font',
			'center', 'button'],
		allowedAttributes: {
		  a: [ 'href', 'name', 'target' ],
		  img: [ 'src' ],
		  br: ['clear'],
		  div: ['class'],
		  font: ['color', 'size'],
		  button: ['name', 'value', 'class']
		},
	});
}

exports.commands = {
	viewlogs: function(target, room, user) {
		if (!target) return this.sendReply("Usage: /viewlogs [room], [year-month-day / 2014-12-08] - Provides you with a temporary link to view the target rooms chat logs.");
		var targetSplit = target.split(',');
		if (!targetSplit[1]) return this.sendReply("Usage: /viewlogs [room], [year-month-day / 2014-12-08] -Provides you with a temporary link to view the target rooms chat logs.");
		for (var u in targetSplit) targetSplit[u] = targetSplit[u].trim();
		var targetRoom = targetSplit[0];
		if (!user.can('lock') && !user.can('roommod', null, Rooms(targetRoom))) return this.sendReply("/viewlogs - Access denied.");
		if (toId(targetRoom) === 'staff' && !user.can('warn')) return this.sendReply("/viewlogs - Access denied.");
		if (toId(targetRoom) === 'administrators' && !user.can('hotpatch')) return this.sendReply("/viewlogs - Access denied.");
		if (toId(targetRoom) === 'upperstaff' && !user.can('pban')) return this.sendReply("/viewlogs - Access denied.");
		if (Rooms(targetRoom) && Rooms(targetRoom).isPrivate && !user.can('pban')) {
			if (Rooms(targetRoom) && Rooms(targetRoom).isPrivate && !user.can('roommod', null, Rooms(targetRoom))) return this.sendReply("/viewlogs - Access denied.");
		}
		var date = '';
		if (toId(targetSplit[1]) === 'today' || toId(targetSplit[1]) === 'yesterday') {
			date = new Date();
			if (toId(targetSplit[1]) === 'yesterday') date.setDate(date.getDate() - 1);
			targetSplit[1] = date.format('{yyyy}-{MM}-{dd}');
		}
		date = targetSplit[1];
		var splitDate = date.split('-');
		if (splitDate.length < 3) return this.sendReply("Usage: /viewlogs [room], [year-month-day / 2014-12-08] -Provides you with a temporary link to view the target rooms chat logs.");
		var self = this;

		fs.readFile('logs/chat/' + toId(targetRoom) + '/' + splitDate[0] + '-' + splitDate[1] + '/' + date + '.txt', 'utf8', function(err, data) {
			if (err) return self.sendReply("/viewlogs - Error: " + err);
			var filename = require('crypto').randomBytes(16).toString('hex') + '.html';
			var newDate = new Date();
			data = data.split('\n');
			var newFile = ['<html>',
			'<head><link rel="stylesheet" type="text/css" href="http://goldservers.info/style/client.css"><link rel="stylesheet" type="text/css" href="http://goldservers.info/js/style.css">' +
			'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head>',
			'<div class="header"><img class="logo" src="http://i.imgur.com/fJwCDif.png" height="45" alt="Gold!"><center><font color=red>Room: ' + Tools.escapeHTML(targetRoom) +
			' Date: ' + Tools.escapeHTML(date) + '</font><br />' ,
			'<font color=red>Logs obtained ' + newDate.toUTCString() + ' by ' + Tools.escapeHTML(user.name) + '</font></center><div class="maintabbarbottom"></div></div>',
			'<div class="ps-room ps-room-light">','<div class="chat-log" style="bottom:0px;">','<div class="inner">'];

			for (var u in data) {
				var timestamp = data[u].substr(0, 9).trim();
				var line = data[u].substr(9, data[u].length);
{'fraction_non_alphanumeric': 0.2248687928946306, 'fraction_numerical': 0.013187996232001077, 'mean_word_length': 4.538002980625931, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, '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': '4704909', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2554, 'n_words': 604}