Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const fs = require('fs');
- function toId(s) {
- return "" + (s && typeof s === "string" ? s : "").toLowerCase().replace(/[^a-z0-9]+/g, "");
- }
- function convertLine(line) {
- if (!line) return "";
- // first we save and remove the timestamp and the roomname
- let prefix = line.match(/\[.+?\] \(.+?\) /i)[0];
- line = line.replace(prefix, '');
- // apply the drastic replaces to mod actions first - these are the most important
- if (/^.{1,19}(?:\W+)? was (muted|unmuted|warned|banned|unbanned|locked|globally banned|unlocked|globally unbanned)(?: from .+?)? by .{1,19}(?:\W+)?(?: for (?:7|60) minutes)?\./i.test(line)) {
- line = line
- .replace(/^(.{1,19}?)(?:\W+)? was muted (by .{1,19}?)(?:\W+)? for 7 minutes\.( \(.+\)$)?/i, 'MUTE: [$1] $2$3')
- .replace(/^(.{1,19}?)(?:\W+)? was muted (by .{1,19}?)(?:\W+)? for 60 minutes\.( \(.+\)$)?/i, 'HOURMUTE: [$1] $2$3')
- .replace(/^(.{1,19}?)(?:\W+)? was unmuted (by .+)(?:\W+)?\.$/i, 'UNMUTE: [$1] $2')
- .replace(/^(.{1,19}?)(?:\W+)? was warned (by .{1,19}?)(?:\W+)?(?:\.$|\.( \(.+\)$))/i, 'WARN: [$1] $2$3')
- .replace(/^(.{1,19}?)(?:\W+)? was banned from .+? (by .{1,19}?)(?:\W+)?\.( \(.+\))?( \(.+\))$/i, 'ROOMBAN: [$1]$4 $2$3')
- .replace(/^(.{1,19}?)(?:\W+)? was unbanned from .+? (by .{1,19}?)(?:\W+)?\.$/i, 'ROOMUNBAN: [$1] $2')
- .replace(/^(.{1,19}?)(?:\W+)? was locked from talking (by .{1,19}?)(?:\W+)?\.( \(.+\))?( \(.+\))$/i, 'LOCK: [$1]$4 $2$3')
- .replace(/^(.{1,19}?)(?:\W+)? was globally banned (by .{1,19}?)(?:\W+)?\.( \(.+\))?( \(.+\))$/i, 'BAN: [$1]$4 $2$3')
- .replace(/^(.{1,19}?)(?:\W+)? was globally unbanned (by .{1,19}?)(?:\W+)?\.$/i, 'UNBAN: [$1] $2')
- .replace(/^(.{1,19}?)(?:\W+)? was unlocked from (by .{1,19}?)(?:\W+)?\.$/i, 'UNLOCK: [$1] $2')
- // finally convert most things to userids!
- .replace(/\[.+\](?= (?:\(.+?\) )?by )/i, match => `[${toId(match)}]`)
- .replace(/by .{1,19}(?=$| \(.+?\)$)/i, match => `by ${toId(match.slice(2))}`);
- return prefix + line;
- }
- // generic grammatical patterns that can be automatically picked up
- line = line.replace(/^.{1,19}(?:\W+)?(?= would be)/g, match => `[${toId(match)}]`) // identify subject - conditional (would be muted, would be banned, etc)
- .replace(/by .{1,19}(?:(?![\.\)]+)\W+)?(?=\.(?:\))?(?:\(.+\))?$| but)/g, match => `by [${toId(match.slice(2))}]`) // identify the object of each line and convert to userid.
- .replace(/^\(?.{1,19}(?:\W+)?(?= [hw]as (?:.+?ed|set|reset)\b)/g, match => (match.startsWith('(') ? '(' : '') + `[${toId(match)}]`) // identify the subject of each line
- // specific cases
- .replace(/^.{1,19}(?:\W+)?(?= (?:globally )? declared)/i, match => `[${toId(match)}]`) // (global declares)
- .replace(/^\(?.{1,19}(?:\W+)?(?= (?!(has|was)\b)(?:created|changed the|set modchat to|started (a|the)|notes))/i, match => (match.startsWith('(') ? '(' : '') + `[${toId(match)}]`);
- return prefix + line;
- }
- function convertLogs(file) {
- const filename = 'logs/modlog/' + file;
- const data = fs.readFileSync(filename).toString().split('\n')
- .map(line => convertLine(line));
- fs.writeFile(filename, data.join('\n'), () => {});
- }
- function convertGlobalModlog() {
- const file = 'logs/modlog/modlog_global.txt';
- let data = fs.readFileSync(file).toString().split('\n');
- data = data.map(line => line.replace(/by .{1,19}(?:\W+)?(?=: |$)/, match => `by ${toId(match.slice(2))}`));
- fs.writeFile(file, data.join('\n'), () => {});
- }
- console.time('modlog conversion');
- // convert non global modlog files first!
- fs.readdir('logs/modlog', (err, dir) => {
- for (let file of dir) {
- if (file === 'modlog_global.txt' || file === 'README.md') continue;
- convertLogs(file);
- }
- });
- convertGlobalModlog();
- console.timeEnd('modlog conversion');
Advertisement
Add Comment
Please, Sign In to add comment