From 0b1bfcbc31e596af741335e5b6c5c5fcae08b16d Mon Sep 17 00:00:00 2001 From: mrfry Date: Sat, 14 Nov 2020 10:43:26 +0100 Subject: [PATCH] User specific motd see counter --- src/modules/api/api.js | 37 +++++++++++++++++++++++++++---------- src/utils/actions.js | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/modules/api/api.js b/src/modules/api/api.js index b4ee1f1..7f0283d 100644 --- a/src/modules/api/api.js +++ b/src/modules/api/api.js @@ -155,16 +155,27 @@ function GetApp() { } function userSpecificMotdSeenBy(id) { + let write = false if (!userSpecificMotd[id].seen) { logger.Log( `User #${id}'s user specific motd is now seen.`, logger.GetColor('bluebg') ) - if (userSpecificMotd[id].seeOnce) { + logger.Log(userSpecificMotd[id].msg) + + userSpecificMotd[id].seen = true + write = true + } + + if (userSpecificMotd[id].seeCounter) { + userSpecificMotd[id].seeCounter -= 1 + if (userSpecificMotd[id].seeCounter === 1) { delete userSpecificMotd[id] - } else { - userSpecificMotd[id].seen = true } + write = true + } + + if (write) { utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile) } } @@ -172,20 +183,20 @@ function GetApp() { function Load() { actions.backupData(data) - utils.WatchFile(userSpecificMotdFile, (newData) => { - logger.Log(`User Specific Motd changed: ${newData.replace(/\/n/g, '')}`) + utils.WatchFile(userSpecificMotdFile, () => { + logger.Log(`User Specific Motd updated`, logger.GetColor('green')) LoadUserSpecificMOTD() }) - utils.WatchFile(motdFile, (newData) => { - logger.Log(`Motd changed: ${newData.replace(/\/n/g, '')}`) + utils.WatchFile(motdFile, () => { + logger.Log(`Motd updated`, logger.GetColor('green')) LoadMOTD() }) utils.WatchFile(versionFile, (newData) => { logger.Log(`Version changed: ${newData.replace(/\/n/g, '')}`) LoadVersion() }) - utils.WatchFile(testUsersFile, (newData) => { - logger.Log(`Test Users file changed: ${newData.replace(/\/n/g, '')}`) + utils.WatchFile(testUsersFile, () => { + logger.Log(`Test Users file changed`, logger.GetColor('green')) LoadTestUsers() }) @@ -851,7 +862,6 @@ function GetApp() { .ProcessIncomingRequest( req.body.datatoadd || req.body, data, - { motd, version }, dryRun, user ) @@ -861,6 +871,13 @@ function GetApp() { newQuestions: result, }) }) + .catch((err) => { + logger.Log( + 'Couldnt process incoming request!', + logger.GetColor('redbg') + ) + console.error(err) + }) }) app.get('/ask', function(req, res) { diff --git a/src/utils/actions.js b/src/utils/actions.js index d93e45b..ccd38b3 100755 --- a/src/utils/actions.js +++ b/src/utils/actions.js @@ -38,7 +38,7 @@ const minMatchToAmmountToAdd = 90 const writeAfter = 1 // write after # of adds FIXME: set reasonable save rate var currWrites = 0 -function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) { +function ProcessIncomingRequest(recievedData, qdb, dryRun, user) { return new Promise((resolve, reject) => { logger.DebugLog('Processing incoming request', 'actions', 1) if (recievedData === undefined) {