User specific motd see counter

This commit is contained in:
mrfry 2020-11-14 10:43:26 +01:00
parent 24dce3da2f
commit 0b1bfcbc31
2 changed files with 28 additions and 11 deletions

View file

@ -155,16 +155,27 @@ function GetApp() {
} }
function userSpecificMotdSeenBy(id) { function userSpecificMotdSeenBy(id) {
let write = false
if (!userSpecificMotd[id].seen) { if (!userSpecificMotd[id].seen) {
logger.Log( logger.Log(
`User #${id}'s user specific motd is now seen.`, `User #${id}'s user specific motd is now seen.`,
logger.GetColor('bluebg') 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] delete userSpecificMotd[id]
} else {
userSpecificMotd[id].seen = true
} }
write = true
}
if (write) {
utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile) utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile)
} }
} }
@ -172,20 +183,20 @@ function GetApp() {
function Load() { function Load() {
actions.backupData(data) actions.backupData(data)
utils.WatchFile(userSpecificMotdFile, (newData) => { utils.WatchFile(userSpecificMotdFile, () => {
logger.Log(`User Specific Motd changed: ${newData.replace(/\/n/g, '')}`) logger.Log(`User Specific Motd updated`, logger.GetColor('green'))
LoadUserSpecificMOTD() LoadUserSpecificMOTD()
}) })
utils.WatchFile(motdFile, (newData) => { utils.WatchFile(motdFile, () => {
logger.Log(`Motd changed: ${newData.replace(/\/n/g, '')}`) logger.Log(`Motd updated`, logger.GetColor('green'))
LoadMOTD() LoadMOTD()
}) })
utils.WatchFile(versionFile, (newData) => { utils.WatchFile(versionFile, (newData) => {
logger.Log(`Version changed: ${newData.replace(/\/n/g, '')}`) logger.Log(`Version changed: ${newData.replace(/\/n/g, '')}`)
LoadVersion() LoadVersion()
}) })
utils.WatchFile(testUsersFile, (newData) => { utils.WatchFile(testUsersFile, () => {
logger.Log(`Test Users file changed: ${newData.replace(/\/n/g, '')}`) logger.Log(`Test Users file changed`, logger.GetColor('green'))
LoadTestUsers() LoadTestUsers()
}) })
@ -851,7 +862,6 @@ function GetApp() {
.ProcessIncomingRequest( .ProcessIncomingRequest(
req.body.datatoadd || req.body, req.body.datatoadd || req.body,
data, data,
{ motd, version },
dryRun, dryRun,
user user
) )
@ -861,6 +871,13 @@ function GetApp() {
newQuestions: result, newQuestions: result,
}) })
}) })
.catch((err) => {
logger.Log(
'Couldnt process incoming request!',
logger.GetColor('redbg')
)
console.error(err)
})
}) })
app.get('/ask', function(req, res) { app.get('/ask', function(req, res) {

View file

@ -38,7 +38,7 @@ const minMatchToAmmountToAdd = 90
const writeAfter = 1 // write after # of adds FIXME: set reasonable save rate const writeAfter = 1 // write after # of adds FIXME: set reasonable save rate
var currWrites = 0 var currWrites = 0
function ProcessIncomingRequest(recievedData, qdb, infos, dryRun, user) { function ProcessIncomingRequest(recievedData, qdb, dryRun, user) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
logger.DebugLog('Processing incoming request', 'actions', 1) logger.DebugLog('Processing incoming request', 'actions', 1)
if (recievedData === undefined) { if (recievedData === undefined) {