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
|
||||
|
||||
if (!userSpecificMotd[id].seen) {
|
||||
logger.Log(
|
||||
`User #${id}'s user specific motd is now seen.`,
|
||||
|
@ -168,16 +170,18 @@ function GetApp() {
|
|||
}
|
||||
|
||||
if (userSpecificMotd[id].seeCounter) {
|
||||
userSpecificMotd[id].seeCounter -= 1
|
||||
if (userSpecificMotd[id].seeCounter === 1) {
|
||||
delete userSpecificMotd[id]
|
||||
if (userSpecificMotd[id].seeCounter <= 1) {
|
||||
shouldSee = false
|
||||
} else {
|
||||
userSpecificMotd[id].seeCounter -= 1
|
||||
write = true
|
||||
}
|
||||
write = true
|
||||
}
|
||||
|
||||
if (write) {
|
||||
utils.WriteFile(JSON.stringify(userSpecificMotd), userSpecificMotdFile)
|
||||
}
|
||||
return shouldSee
|
||||
}
|
||||
|
||||
function Load() {
|
||||
|
@ -986,9 +990,8 @@ function GetApp() {
|
|||
}
|
||||
if (req.query.motd) {
|
||||
result.motd = motd
|
||||
if (userSpecificMotd[user.id]) {
|
||||
if (userSpecificMotd[user.id] && userShouldGetUserSpecificMOTD(user.id)) {
|
||||
result.userSpecificMotd = userSpecificMotd[user.id].msg
|
||||
userSpecificMotdSeenBy(user.id)
|
||||
}
|
||||
}
|
||||
res.json(result)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue