mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
motd and version file watching and loading
This commit is contained in:
parent
a1e99c53ae
commit
7c7ed47455
2 changed files with 36 additions and 17 deletions
|
@ -25,20 +25,18 @@ module.exports = {
|
|||
|
||||
const dataFile = './public/data.json'
|
||||
const recDataFile = './stats/recdata'
|
||||
const versionFile = './public/version'
|
||||
const motdFile = './public/motd'
|
||||
const qaFile = './public/qa'
|
||||
|
||||
const logger = require('../utils/logger.js')
|
||||
const idStats = require('../utils/ids.js')
|
||||
idStats.Load() // TODO: dont always load when actions.js is used
|
||||
idStats.Load() // FIXME: dont always load when actions.js is used
|
||||
const utils = require('../utils/utils.js')
|
||||
const classes = require('./question-classes/classes.js')
|
||||
|
||||
const writeAfter = 1 // write after # of adds FIXME: set reasonable save rate
|
||||
var currWrites = 0
|
||||
|
||||
function ProcessIncomingRequest (recievedData, qdb) {
|
||||
function ProcessIncomingRequest (recievedData, qdb, infos) {
|
||||
if (recievedData === undefined) {
|
||||
logger.Log('\tRecieved data is undefined!', logger.GetColor('redbg'))
|
||||
return
|
||||
|
@ -63,12 +61,6 @@ function ProcessIncomingRequest (recievedData, qdb) {
|
|||
d.quiz.forEach((question) => {
|
||||
let q = new classes.Question(question.Q, question.A, question.data)
|
||||
let sames = qdb.Search(q, d.subj)
|
||||
if (sames.length === 0) {
|
||||
sames = qdb.Search(q, d.subj)
|
||||
if (sames.length !== 0) {
|
||||
logger.Log(`\t'${d.subj}' gave no result but '' did! (adding new questions)`, logger.GetColor('redbg'))
|
||||
}
|
||||
}
|
||||
// if it didnt find any question, or every found questions match is lower thatn 80
|
||||
let isNew = sames.length === 0 || sames.every(searchResItem => {
|
||||
return searchResItem.match < classes.minMatchAmmount
|
||||
|
@ -93,9 +85,8 @@ function ProcessIncomingRequest (recievedData, qdb) {
|
|||
if (currWrites >= writeAfter) {
|
||||
currWrites = 0
|
||||
try {
|
||||
// TODO: with utils.WatchFile
|
||||
qdb.version = utils.ReadFile(versionFile)
|
||||
qdb.motd = utils.ReadFile(motdFile)
|
||||
qdb.version = infos.version
|
||||
qdb.motd = infos.motd
|
||||
} catch (e) {
|
||||
logger.Log('MOTD/Version writing/reading error!')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue