Blocking users with too many active warnings from submitting votes and submissions

This commit is contained in:
Nanobyte
2020-09-16 22:40:11 +02:00
parent 3c79c0f7a8
commit 36f654f41c
7 changed files with 125 additions and 3 deletions

View File

@@ -235,6 +235,16 @@ async function voteOnSponsorTime(req, res) {
return;
}
}
const MILLISECONDS_IN_HOUR = 3600000;
const now = Date.now();
let warningsCount = db.prepare('get', "SELECT count(1) as count FROM warnings WHERE userID = ? AND issueTime > ?",
[nonAnonUserID, Math.floor(now - (config.hoursAfterWarningExpires * MILLISECONDS_IN_HOUR))]
).count;
if (warningsCount >= config.maxNumberOfActiveWarnings) {
return res.status(403).send('Vote blocked. Too many active warnings!');
}
let voteTypeEnum = (type == 0 || type == 1) ? voteTypes.normal : voteTypes.incorrect;