mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
User specific motd see counter
This commit is contained in:
parent
24dce3da2f
commit
0b1bfcbc31
2 changed files with 28 additions and 11 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue