User:Victor Bearwolf/temp

From Game Logs
Jump to: navigation, search

Discord to ur-dnd logs converter currently set up for On that September.
Just save it as "SEP_logfixer.wsf" and then run in Windows(r). Before that export Discord logs as text by DiscordCharExporter to "SEP_new.txt".
To configure for other games just rename players and characters. And filenames.

<job id="LogFixer">
<script name="JScript">

var strInputFile = "SEP_new.txt";
var strOutputFile = "SEP.txt";

// Read input file into memory
arrLine = new Array();
fs = new ActiveXObject("Scripting.FileSystemObject");
fileLog = fs.GetFile(strInputFile);
streamLog = fileLog.OpenAsTextStream(1, 0);
var intCount = 0;
while(!streamLog.AtEndOfStream) {
   arrLine[intCount] = streamLog.ReadLine();
   intCount++;
} 
streamLog.Close();

// Prepare output file
fs.CreateTextFile(strOutputFile);
fileNew = fs.GetFile(strOutputFile);
fileNew = fileNew.OpenAsTextStream(8, 0);
fileNew.write("[[Category:On That September]]\r\n");

// Prepare Find-n-Replace data (TODO: more regexps?)
var arrIn  = new Array("Petrovna#3347", "DiceParser#0764", "Victor Bearwolf#2285", "@Victor Bearwolf", "Heckfy[Ex]#1253", "@Heckfy[Ex]", "Bert#5362", "@Bert", "Zuzuzu#6001", "@Zuzuzu", "zigan#8073", "@zigan", " ,", "# ", "\\*", "*", "_", "* -", "```Markdown", "```");
var arrOut = new Array("<b>GM</b>:", "<b>bot</b>:", "<b>Джек</b>:", "<b>Джек</b>", "<b>Сэм</b>:", "<b>Сэм</b>", "<b>Джеймс</b>:", "<b>Джеймс</b>", "<b>Ринго</b>:", "<b>Ринго</b>", "<b>Фрэнк</b>:", "<b>Фрэнк</b>", ",", "", "\'\'", "\'\'", "\'\'", "\'\' -", "@", "@");

// Check arrays just in case
if(arrIn.length != arrOut.length) {
  WScript.Echo("ERROR! Input and output array lengths do not match.");
  WScript.Quit(); 
}

var intIndex = arrIn.length;
var strLog = arrLine[0];
var boolEm = false;
var intMatch = -1;

// Process log data
for(j = 0; j<arrLine.length; j++) {
  strLog = arrLine[j] + "\r\n";

  // Remove timestamp
  strLog = strLog.replace(/(\[\d{2}-[A-Z][a-z][a-z]-\d{2} \d{2}:\d{2} [AP]M\] )/, '');

  // Escape OOC
  strLog = strLog.replace(/(^[\*][ ])/, '* ');

  // Clear bot output
  //strLog = strLog.replace(/(^[`]*(Markdown)?)/, '');

  // Rename players as characters
  for(i = 0; i<intIndex; i++) {
    intMatch = strLog.indexOf(arrIn[i]);
    while(intMatch != -1) {
      var strLog = strLog.replace(arrIn[i], arrOut[i]);
      intMatch = strLog.indexOf(arrIn[i]);
    }
  }

  // Write result
  if(strLog != "@\r\n") {
    fileNew.write(strLog);
  }
}
fileNew.Close();
WScript.Echo("Done! Processed "+arrLine.length+" lines\r\nfrom "+strInputFile+" to "+strOutputFile);

</script>
</job>