Actions.js refactoring

This commit is contained in:
YourFriendlyNeighborhoodDealer 2019-08-14 10:32:41 +02:00
parent 0d8c1c154a
commit 8a92e5651f

View file

@ -23,402 +23,370 @@ module.exports = {
NLoad: NLoad, NLoad: NLoad,
LoadJSON: LoadJSON, LoadJSON: LoadJSON,
ProcessQA: ProcessQA ProcessQA: ProcessQA
}; }
var staticFile = "public/data/static"; const staticFile = '../public/data/static'
var manFile = "public/man.html"; const dataFile = '../public/data.json'
var dataFile = "public/data.json"; const recDataFile = '../stats/recdata'
const recDataFile = "stats/recdata"; const versionFile = '../public/version'
const versionFile = "public/version"; const motdFile = '../public/motd'
const motdFile = "public/motd"; const qaFile = '../public/qa'
const qaFile = "public/qa";
var logger = require('./logger.js'); var logger = require('../utils/logger.js')
var utils = require('./utils.js'); var utils = require('../utils/utils.js')
class Question { class Question {
constructor(q, a, i) { constructor (q, a, i) {
this.Q = q; this.Q = q
this.A = a; this.A = a
this.I = i; this.I = i
} }
toString() { toString () {
var r = "?" + this.Q + "\n!" + this.A; var r = '?' + this.Q + '\n!' + this.A
if (this.I) if (this.I) { r += '\n>' + this.I }
r += "\n>" + this.I; return r
return r;
} }
HasQuestion() { HasQuestion () {
return this.Q != undefined; return this.Q !== undefined
} }
HasAnswer() { HasAnswer () {
return this.A != undefined; return this.A !== undefined
} }
HasImage() { HasImage () {
return this.I != undefined; return this.I !== undefined
} }
IsComplete() { IsComplete () {
return this.HasQuestion() && this.HasAnswer(); return this.HasQuestion() && this.HasAnswer()
} }
Compare(q2, i) { Compare (q2, i) {
if (typeof q2 == 'string') { if (typeof q2 === 'string') {
var qmatchpercent = Question.CompareString(this.Q, q2); var qmatchpercent = Question.CompareString(this.Q, q2)
if (i == undefined || i.length == 0) if (i == undefined || i.length == 0) { return qmatchpercent } else {
return qmatchpercent;
else {
if (this.HasImage()) { if (this.HasImage()) {
const imatchpercent = this.HasImage() ? Question.CompareString(this.I.join(" "), i.join(" ")) : const imatchpercent = this.HasImage() ? Question.CompareString(this.I.join(' '), i.join(' '))
0; : 0
return (qmatchpercent + imatchpercent) / 2; return (qmatchpercent + imatchpercent) / 2
} else { } else {
qmatchpercent -= 30; qmatchpercent -= 30
if (qmatchpercent < 0) if (qmatchpercent < 0) { return 0 } else { return qmatchpercent }
return 0;
else
return qmatchpercent;
} }
} }
} else { } else {
const qmatchpercent = Question.CompareString(this.Q, q2.Q); const qmatchpercent = Question.CompareString(this.Q, q2.Q)
const amatchpercent = Question.CompareString(this.A, q2.A); const amatchpercent = Question.CompareString(this.A, q2.A)
if (this.I != undefined) { if (this.I !== undefined) {
const imatchpercent = this.I == undefined ? Question.CompareString(this.I.join(" "), q2.I.join( const imatchpercent = this.I === undefined ? Question.CompareString(this.I.join(' '), q2.I.join(
" ")) : 0; ' ')) : 0
return (qmatchpercent + amatchpercent + imatchpercent) / 3; return (qmatchpercent + amatchpercent + imatchpercent) / 3
} else { } else {
return (qmatchpercent + amatchpercent) / 2; return (qmatchpercent + amatchpercent) / 2
} }
} }
} }
static CompareString(s1, s2) {
//if (s1 == undefined || s2 == undefined) // static CompareString (s1, s2) {
// return 0; // // if (s1 == undefined || s2 == undefined)
s1 = SimplifyStringForComparison(s1).split(" "); // // return 0;
s2 = SimplifyStringForComparison(s2).split(" "); // s1 = SimplifyStringForComparison(s1).split(' ')
var match = 0; // s2 = SimplifyStringForComparison(s2).split(' ')
for (var i = 0; i < s1.length; i++) // var match = 0
if (s2.includes(s1[i])) // for (var i = 0; i < s1.length; i++) {
match++; // if (s2.includes(s1[i])) { match++ }
var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent // }
var lengthDifference = Math.abs(s2.length - s1.length); // var percent = Math.round(((match / s1.length) * 100).toFixed(2)) // matched words percent
percent -= lengthDifference * 3; // var lengthDifference = Math.abs(s2.length - s1.length)
if (percent < 0) // percent -= lengthDifference * 3
percent = 0; // if (percent < 0) { percent = 0 }
return percent; // return percent
} // }
} }
class Subject { class Subject {
constructor(n) { constructor (n) {
this.Name = n; this.Name = n
this.Questions = []; this.Questions = []
} }
get length() { get length () {
return this.Questions.length; return this.Questions.length
} }
AddQuestion(q) { AddQuestion (q) {
this.Questions.push(q); this.Questions.push(q)
} }
Search(q, img) { Search (q, img) {
var r = []; const minMatchAmmount = 90
for (var i = 0; i < this.length; i++) { var r = []
let percent = this.Questions[i].Compare(q, img); for (let i = 0; i < this.length; i++) {
if (percent > minMatchAmmount) let percent = this.Questions[i].Compare(q, img)
if (percent > minMatchAmmount) {
r.push({ r.push({
q: this.Questions[i], q: this.Questions[i],
match: percent match: percent
}); })
}
} }
for (var i = 0; i < r.length; i++) for (let i = 0; i < r.length; i++) {
for (var j = i; j < r.length; j++) for (var j = i; j < r.length; j++) {
if (r[i].match < r[j].match) { if (r[i].match < r[j].match) {
var tmp = r[i]; var tmp = r[i]
r[i] = r[j]; r[i] = r[j]
r[j] = tmp; r[j] = tmp
}
}
} }
return r; return r
} }
toString() { toString () {
var r = []; var r = []
for (var i = 0; i < this.Questions.length; i++) for (var i = 0; i < this.Questions.length; i++) { r.push(this.Questions[i].toString()) }
r.push(this.Questions[i].toString()); return '+' + this.Name + '\n' + r.join('\n')
return "+" + this.Name + "\n" + r.join("\n");
} }
} }
class QuestionDB { class QuestionDB {
constructor() { constructor () {
this.Subjects = []; this.Subjects = []
} }
get length() { get length () {
return this.Subjects.length; return this.Subjects.length
} }
get activeIndexes() { // get activeIndexes () {
var r = []; // var r = []
for (var i = 0; i < this.length; i++) { // for (var i = 0; i < this.length; i++) {
if (GM_getValue("Is" + i + "Active")) { // if (GM_getValue('Is' + i + 'Active')) {
r.push(i); // r.push(i)
// }
// }
// return r
// }
// GetIfActive (ind) {
// return GM_getValue('Is' + ind + 'Active')
// }
// ChangeActive (i, value) {
// GM_setValue('Is' + i + 'Active', !!value)
// }
AddQuestion (subj, q) {
var i = 0
while (i < this.Subjects.length && this.Subjects[i].Name !== subj) { i++ }
if (i < this.Subjects.length) { this.Subjects[i].AddQuestion(q) } else {
const n = new Subject(subj)
n.AddQuestion(q)
this.Subjects.push(n)
} }
} }
return r; Search (q, img) {
var r = []
for (let i = 0; i < this.length; i++) {
if (this.GetIfActive(i)) { r = r.concat(this.Subjects[i].Search(q, img)) }
} }
GetIfActive(ind) {
return GM_getValue("Is" + ind + "Active");
}
ChangeActive(i, value) {
GM_setValue("Is" + i + "Active", !!value);
}
AddQuestion(subj, q) {
var i = 0;
while (i < this.Subjects.length && this.Subjects[i].Name != subj)
i++;
if (i < this.Subjects.length)
this.Subjects[i].AddQuestion(q);
else {
const n = new Subject(subj);
n.AddQuestion(q);
this.Subjects.push(n);
}
}
Search(q, img) {
var r = [];
for (var i = 0; i < this.length; i++)
if (this.GetIfActive(i))
r = r.concat(this.Subjects[i].Search(q, img));
for (var i = 0; i < r.length; i++) for (let i = 0; i < r.length; i++) {
for (var j = i; j < r.length; j++) for (var j = i; j < r.length; j++) {
if (r[i].match < r[j].match) { if (r[i].match < r[j].match) {
var tmp = r[i]; var tmp = r[i]
r[i] = r[j]; r[i] = r[j]
r[j] = tmp; r[j] = tmp
}
}
} }
return r; return r
} }
AddSubject(subj) { AddSubject (subj) {
var i = 0; var i = 0
while (i < this.length && subj.Name != this.Subjects[i].Name) while (i < this.length && subj.Name !== this.Subjects[i].Name) { i++ }
i++;
if (i < this.length) { if (i < this.length) {
this.Subjects.concat(subj.Questions); this.Subjects.concat(subj.Questions)
} else { } else {
this.Subjects.push(subj); this.Subjects.push(subj)
} }
} }
toString() { toString () {
var r = []; var r = []
for (var i = 0; i < this.Subjects.length; i++) for (var i = 0; i < this.Subjects.length; i++) { r.push(this.Subjects[i].toString()) }
r.push(this.Subjects[i].toString()); return r.join('\n\n')
return r.join("\n\n");
} }
} }
function Process (d, file) {
function Process(d, file) {
try { try {
logger.Log("File: " + file); logger.Log('File: ' + file)
if (d.data.split("\n").length > 1) { if (d.data.split('\n').length > 1) {
var oldFile = utils.ReadFile(file); var oldFile = utils.ReadFile(file)
var newFile = oldFile + "\n"; var newFile = oldFile + '\n'
if (d.data[0] == '+') if (d.data[0] === '+') { newFile += d.data } else { newFile += '+' + d.data }
newFile += d.data;
else
newFile += "+" + d.data;
var newRes = CheckData(newFile); var newRes = CheckData(newFile)
var oldRes = CheckData(oldFile); var oldRes = CheckData(oldFile)
if (oldRes.count > 0) if (oldRes.count > 0) { logger.Log('\t\told public result: ' + oldRes.count, logger.GetColor('blue')) } else { logger.Log('\t\told public NLOD error, ' + oldRes.log, logger.GetColor('redbg'), true) }
logger.Log("\t\told public result: " + oldRes.count, logger.GetColor("blue"));
else
logger.Log("\t\told public NLOD error, " + oldRes.log, logger.GetColor("redbg"), true);
if (newRes.count > 0) if (newRes.count > 0) { logger.Log('\t\tnew file result: ' + newRes.count, logger.GetColor('blue')) } else { logger.Log('\t\tnew file NLOD error, ' + newRes.log, logger.GetColor('redbg'), true) }
logger.Log("\t\tnew file result: " + newRes.count, logger.GetColor("blue"));
else
logger.Log("\t\tnew file NLOD error, " + newRes.log, logger.GetColor("redbg"), true);
utils.WriteFile(newFile, file);
logger.Log("\t\tNew data written to: " + file);
return newRes.count - oldRes.count;
} else
logger.Log("\t\tNo new data");
utils.WriteFile(newFile, file)
logger.Log('\t\tNew data written to: ' + file)
return newRes.count - oldRes.count
} else { logger.Log('\t\tNo new data') }
} catch (e) { } catch (e) {
Beep(); logger.Log('\tError at processing data! File: ' + file, logger.GetColor('redbg'))
logger.Log("\tError at processing data! File: " + file, logger.GetColor("redbg")); logger.Log(e.toString(), logger.GetColor('redbg'))
logger.Log(e.toString(), logger.GetColor("redbg"));
} }
return -1; return -1
} }
function ProcessIncomingRequest(data) { function ProcessIncomingRequest (data) {
if (data === undefined) {
if (data == undefined) { logger.Log('\tRecieved data is undefined!', logger.GetColor('redbg'))
logger.Log("\tRecieved data is undefined!", logger.GetColor("redbg")); return
return;
} }
try { try {
let towrite = logger.GetDateString() + "\n"; let towrite = logger.GetDateString() + '\n'
towrite += "------------------------------------------------------------------------------\n"; towrite += '------------------------------------------------------------------------------\n'
towrite += data towrite += data
towrite += "\n------------------------------------------------------------------------------\n"; towrite += '\n------------------------------------------------------------------------------\n'
utils.AppendToFile(towrite, recDataFile); utils.AppendToFile(towrite, recDataFile)
} catch (e) { } catch (e) {
logger.log("Error writing recieved data."); logger.log('Error writing recieved data.')
} }
try { try {
var d = JSON.parse(data); var d = JSON.parse(data)
var dfile = utils.ReadFile(dataFile); var dfile = utils.ReadFile(dataFile)
var data = LoadJSON(dfile); data = LoadJSON(dfile)
var allQuestions = []; var allQuestions = []
for ( var i = 0; i < d.allData.length; i++){ for (let i = 0; i < d.allData.length; i++) {
allQuestions.push(new Question(d.allData[i].Q, d.allData[i].A, d.allData[i].I)); allQuestions.push(new Question(d.allData[i].Q, d.allData[i].A, d.allData[i].I))
} }
var questions = []; var questions = []
for ( var i = 0; i < d.data.length; i++){ for (let i = 0; i < d.data.length; i++) {
let q = new Question(d.data[i].Q, d.data[i].A, d.data[i].I); let q = new Question(d.data[i].Q, d.data[i].A, d.data[i].I)
questions.push(q); questions.push(q)
data.AddQuestion(d.subj, q); data.AddQuestion(d.subj, q)
} }
logger.Log("\t" + d.subj); logger.Log('\t' + d.subj)
var msg = "All / new count: " + allQuestions.length + " / " + questions.length; var msg = 'All / new count: ' + allQuestions.length + ' / ' + questions.length
if (d.version != undefined) if (d.version !== undefined) { msg += '. Version: ' + d.version }
msg += ". Version: " + d.version; var color = logger.GetColor('green')
var color = logger.GetColor("green");
try { try {
data.version = utils.ReadFile(versionFile); data.version = utils.ReadFile(versionFile)
data.motd = utils.ReadFile(motdFile); data.motd = utils.ReadFile(motdFile)
} catch (e) { } catch (e) {
Log("MOTD/Version writing/reading error!"); logger.Log('MOTD/Version writing/reading error!')
} }
if (data != undefined && d.data.length > 0){ if (data !== undefined && d.data.length > 0) {
utils.WriteBackup(); utils.WriteBackup()
utils.WriteFile(JSON.stringify(data), dataFile); utils.WriteFile(JSON.stringify(data), dataFile)
msg += " - Data file written!"; msg += ' - Data file written!'
var color = logger.GetColor("blue"); color = logger.GetColor('blue')
} }
logger.Log("\t" + msg, color); logger.Log('\t' + msg, color)
} catch (e) { } catch (e) {
logger.Log("Couldnt parse JSON data, trying old format...", logger.GetColor("redbg")); logger.Log('Couldnt parse JSON data, trying old format...', logger.GetColor('redbg'))
var d = SetupData(data); d = SetupData(data)
var qcount = -1; var qcount = -1
try { try {
var splitted = d.alldata.split("\n"); var splitted = d.alldata.split('\n')
var count = 0; var count = 0
for (var i = 0; i < splitted.length; i++) for (var i = 0; i < splitted.length; i++) {
if (splitted[i][0] == '?') if (splitted[i][0] === '?') { count++ }
count ++; }
qcount = count; qcount = count
} catch (e) {console.log("Error :c"); console.log(e);} } catch (e) { console.log('Error :c'); console.log(e) }
logger.Log("\tProcessing data: " + d.subj + " (" + d.type + "), count: " + qcount, logger.GetColor("green")); logger.Log('\tProcessing data: ' + d.subj + ' (' + d.type + '), count: ' + qcount, logger.GetColor('green'))
if (d.subj == undefined){ if (d.subj === undefined) {
logger.Log(JSON.stringify(d), logger.GetColor("red")); logger.Log(JSON.stringify(d), logger.GetColor('red'))
return; return
} }
var newItems = 0; var newStatItems = Process(d, staticFile)
var newStatItems = Process(d, staticFile); PrintNewCount(d, newStatItems, staticFile)
PrintNewCount(d, newStatItems, staticFile);
} }
} }
function PrintNewCount(d, newItems, file) { function PrintNewCount (d, newItems, file) {
if (newItems > 0) { if (newItems > 0) {
var count = 0; var count = 0
var splitted = d.alldata.split("\n"); var splitted = d.alldata.split('\n')
for (var i = 0; i < splitted.length; i++) for (var i = 0; i < splitted.length; i++) {
if (splitted[i].startsWith("?")) if (splitted[i].startsWith('?')) { count++ }
count++; }
logger.Log("\t" + file + " All / New: " + count + " / " + newItems, logger.GetColor("cyan")); logger.Log('\t' + file + ' All / New: ' + count + ' / ' + newItems, logger.GetColor('cyan'))
} }
} }
function SetupData(data) { function SetupData (data) {
var pdata = data.split("<#>"); var pdata = data.split('<#>')
if (pdata.length <= 0){ if (pdata.length <= 0) {
logger.Log("Data length is zero !", logger.GetColor("redbg")); logger.Log('Data length is zero !', logger.GetColor('redbg'))
throw "No data recieved!"; throw 'No data recieved!'
} }
var d = {}; // parsed data var d = {} // parsed data
for (var i = 0; i < pdata.length; i++) { for (var i = 0; i < pdata.length; i++) {
var td = pdata[i].split("<=>"); var td = pdata[i].split('<=>')
if (td.length == 2) if (td.length === 2) { d[td[0]] = td[1] } else {
d[td[0]] = td[1]; logger.Log('Invalid parameter!', logger.GetColor('redbg'))
else { throw 'Invalid parameter recieved!'
logger.Log("Invalid parameter!", logger.GetColor("redbg"));
throw "Invalid parameter recieved!";
} }
} }
return d; return d
} }
function CheckData(data) { function CheckData (data) {
try { try {
var presult = NLoad(data); var presult = NLoad(data)
return presult; return presult
} catch (e) { } catch (e) {
logger.Log("Load error, " + e.toString(), logger.GetColor("redbg"), true); logger.Log('Load error, ' + e.toString(), logger.GetColor('redbg'), true)
return { return {
count: -1, count: -1,
log: [e.toString()] log: [e.toString()]
}; }
} }
} }
function NLoad(resource) { function NLoad (resource) {
var resultLog = []; var resultLog = []
var count = -1; var allCount = 0
var allCount = 0; if (resource === undefined) { throw 'A megadott adat undefined!' }
if (resource == undefined) resource = resource.split('\n') // splitting by enters
throw "A megadott adat undefined!"; if (resource.length === 1) { throw 'A megadott adat nem sorokból áll!' }
resource = resource.split("\n"); // splitting by enters var data = [] // initializing data declared at the begining
if (resource.length == 1)
throw "A megadott adat nem sorokból áll!";
var data = []; // initializing data declared at the begining
function AddNewSubj(name) // adds a new subject to the data function AddNewSubj (name) {
{
data.push({ data.push({
"questions": [] 'questions': []
}); // ads aa new object, with an empty array in it }) // ads aa new object, with an empty array in it
GetCurrSubj().name = name; // sets the name for it GetCurrSubj().name = name // sets the name for it
GetCurrSubj().count = 0; // setting count to default GetCurrSubj().count = 0 // setting count to default
// setting if its active only if its undefined, otherwise previous user setting shouldt be overwritten // setting if its active only if its undefined, otherwise previous user setting shouldt be overwritten
} }
function AddItem() // adds an item to the last subjects questions function AddItem () // adds an item to the last subjects questions
{ {
GetCurrSubj().count++; GetCurrSubj().count++
allCount++; // incrementing all count allCount++ // incrementing all count
GetCurrSubj().questions.push({}); // adding a new empty object to the last item in the data GetCurrSubj().questions.push({}) // adding a new empty object to the last item in the data
} }
function GetLastItem() // returns the last item of the last item of data function GetLastItem () // returns the last item of the last item of data
{ {
var q = GetCurrSubj().questions.length; // questions length var q = GetCurrSubj().questions.length // questions length
return GetCurrSubj().questions[q - 1]; return GetCurrSubj().questions[q - 1]
} }
function GetCurrSubj() { function GetCurrSubj () {
return data[data.length - 1]; return data[data.length - 1]
} }
// ? : question // ? : question
@ -431,103 +399,98 @@ function NLoad(resource) {
{ {
if (resource[j][0] == '+') // if there is a name identifier if (resource[j][0] == '+') // if there is a name identifier
{ {
break; // breaks, couse there will be a name break // breaks, couse there will be a name
} }
if (resource[j][0] == '?' || resource[j][0] == '!' || resource[j][0] == '>') // if it begins with another identifier: if (resource[j][0] == '?' || resource[j][0] == '!' || resource[j][0] == '>') // if it begins with another identifier:
{ {
AddNewSubj("NONAME"); // there is no name (for the first question at least), so setting it noname. AddNewSubj('NONAME') // there is no name (for the first question at least), so setting it noname.
break; break
} }
// else it does nothing, continues to check // else it does nothing, continues to check
} }
var jumped = 0; // the amount of lines it processed var jumped = 0 // the amount of lines it processed
for (var i = 0; i < resource.length; i += jumped) // gouing through the resource for (var i = 0; i < resource.length; i += jumped) // gouing through the resource
{ {
jumped = 0; // resetting it to 0 jumped = 0 // resetting it to 0
var currRawDataQ = resource[i]; // current question var currRawDataQ = resource[i] // current question
var currRawDataA = resource[i + 1]; // current answer var currRawDataA = resource[i + 1] // current answer
var currRawDataI = resource[i + 2]; // current image var currRawDataI = resource[i + 2] // current image
if (currRawDataQ != undefined && currRawDataQ[0] == '?' && currRawDataA != undefined && if (currRawDataQ != undefined && currRawDataQ[0] == '?' && currRawDataA != undefined &&
currRawDataA[0] == '!') // if the current line is ? and the next is ! its a data currRawDataA[0] == '!') // if the current line is ? and the next is ! its a data
{ {
AddItem(); AddItem()
GetLastItem().q = currRawDataQ.substr(1); GetLastItem().q = currRawDataQ.substr(1)
GetLastItem().a = currRawDataA.substr(1); GetLastItem().a = currRawDataA.substr(1)
jumped += 2; jumped += 2
if (currRawDataI != undefined && currRawDataI[0] == '>') { if (currRawDataI != undefined && currRawDataI[0] == '>') {
GetLastItem().i = currRawDataI.substr(1); GetLastItem().i = currRawDataI.substr(1)
jumped++; jumped++
} }
} else if (currRawDataQ[0] == '+') // if its a new subject } else if (currRawDataQ[0] == '+') // if its a new subject
{ {
AddNewSubj(currRawDataQ.substr(1)); AddNewSubj(currRawDataQ.substr(1))
jumped++; jumped++
} else { } else {
// this should be invalid question order // this should be invalid question order
resultLog.push("Warning @ line " + i + ":" + currRawDataQ + " " + currRawDataA + " " + resultLog.push('Warning @ line ' + i + ':' + currRawDataQ + ' ' + currRawDataA + ' ' +
currRawDataI); currRawDataI)
jumped++; jumped++
} }
} // end of parsing all data } // end of parsing all data
return { return {
count: allCount, count: allCount,
log: resultLog log: resultLog
}; }
} }
// loading stuff // loading stuff
function LoadJSON(resource) { function LoadJSON (resource) {
var count = -1; var count = -1
try { try {
var d = JSON.parse(resource); var d = JSON.parse(resource)
var r = new QuestionDB(); var r = new QuestionDB()
var rt = []; var rt = []
var allCount = -1; var allCount = -1
for (var i = 0; i < d.Subjects.length; i++) { for (var i = 0; i < d.Subjects.length; i++) {
let s = new Subject(d.Subjects[i].Name); let s = new Subject(d.Subjects[i].Name)
var j = 0; var j = 0
for (j = 0; j < d.Subjects[i].Questions.length; j++) { for (j = 0; j < d.Subjects[i].Questions.length; j++) {
var currQ = d.Subjects[i].Questions[j]; var currQ = d.Subjects[i].Questions[j]
s.AddQuestion(new Question(currQ.Q, currQ.A, currQ.I)); s.AddQuestion(new Question(currQ.Q, currQ.A, currQ.I))
} }
rt.push({ rt.push({
name: d.Subjects[i].Name, name: d.Subjects[i].Name,
count: j count: j
}); })
allCount += j; allCount += j
r.AddSubject(s); r.AddSubject(s)
} }
return r; return r
} catch (e) { } catch (e) {
logger.Log("Error loading sutff", logger.GetColor("redbg"), true); logger.Log('Error loading sutff', logger.GetColor('redbg'), true)
} }
} }
function ProcessQA() { function ProcessQA () {
if (!utils.FileExists(qaFile)) if (!utils.FileExists(qaFile)) { utils.WriteFile('', qaFile) }
utils.WriteFile("", qaFile);
let a = utils.ReadFile(qaFile).split("\n"); let a = utils.ReadFile(qaFile).split('\n')
let r = []; let r = []
let ind = 0; let ind = 0
for (let i = 0; i < a.length; i++) { for (let i = 0; i < a.length; i++) {
if ( a[i] == "#") if (a[i] == '#') { ind++ } else {
ind ++; if (r[ind] == undefined) { r[ind] = {} }
else {
if (r[ind] == undefined)
r[ind] = {};
if (r[ind].q == undefined) { if (r[ind].q == undefined) {
r[ind].q = a[i]; r[ind].q = a[i]
} else { } else {
if (r[ind].a == undefined) if (r[ind].a == undefined) { r[ind].a = [] }
r[ind].a = [];
r[ind].a.push(a[i]); r[ind].a.push(a[i])
} }
} }
} }
return r; return r
} }