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
3e2b76f75b
commit
8f09da8309
1 changed files with 10 additions and 7 deletions
|
@ -154,8 +154,10 @@ function GetApp() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function userSpecificMotdSeenBy(id) {
|
function userShouldGetUserSpecificMOTD(id) {
|
||||||
|
let shouldSee = true
|
||||||
let write = false
|
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.`,
|
||||||
|
@ -168,16 +170,18 @@ function GetApp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userSpecificMotd[id].seeCounter) {
|
if (userSpecificMotd[id].seeCounter) {
|
||||||
userSpecificMotd[id].seeCounter -= 1
|
if (userSpecificMotd[id].seeCounter <= 1) {
|
||||||
if (userSpecificMotd[id].seeCounter === 1) {
|
shouldSee = false
|
||||||
delete userSpecificMotd[id]
|
} else {
|
||||||
|
userSpecificMotd[id].seeCounter -= 1
|
||||||
|
write = true
|
||||||
}
|
}
|
||||||
write = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile)
|
utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile)
|
||||||
}
|
}
|
||||||
|
return shouldSee
|
||||||
}
|
}
|
||||||
|
|
||||||
function Load() {
|
function Load() {
|
||||||
|
@ -986,9 +990,8 @@ function GetApp() {
|
||||||
}
|
}
|
||||||
if (req.query.motd) {
|
if (req.query.motd) {
|
||||||
result.motd = motd
|
result.motd = motd
|
||||||
if (userSpecificMotd[user.id]) {
|
if (userSpecificMotd[user.id] && userShouldGetUserSpecificMOTD(user.id)) {
|
||||||
result.userSpecificMotd = userSpecificMotd[user.id].msg
|
result.userSpecificMotd = userSpecificMotd[user.id].msg
|
||||||
userSpecificMotdSeenBy(user.id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.json(result)
|
res.json(result)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue