Added trustworthy check function and made it possible to get unshadowbanned.

This commit is contained in:
Ajay Ramachandran 2019-09-16 16:51:55 -04:00
parent ef5c6fddec
commit fa58e786d2

View file

@ -177,21 +177,9 @@ app.get('/api/postVideoSponsorTimes', async function (req, res) {
let shadowBanned = shadowBanResult.row.userCount;
//check to see if this user how many submissions this user has submitted
let totalSubmissionsResult = await new Promise((resolve, reject) => {
db.prepare("SELECT count(*) as totalSubmissions FROM sponsorTimes WHERE userID = ?").get(userID, (err, row) => resolve({err, row}));
});
if (totalSubmissionsResult.row.totalSubmissions > 15) {
//check if they have a high downvote ratio
let downvotedSubmissionsResult = await new Promise((resolve, reject) => {
db.prepare("SELECT count(*) as downvotedSubmissions FROM sponsorTimes WHERE userID = ? AND votes < 0").get(userID, (err, row) => resolve({err, row}));
});
if (downvotedSubmissionsResult.row.downvotedSubmissions / totalSubmissionsResult.row.totalSubmissions > 0.6) {
//hide this submission as this user is untrustworthy
shadowBanned = 1;
}
if (!(await isUserTrustworthy(userID))) {
//hide this submission as this user is untrustworthy
shadowBanned = 1;
}
let startingVotes = 0;
@ -287,7 +275,7 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
});
//check if the increment amount should be multiplied (downvotes have more power if there have been many views)
db.prepare("SELECT votes, views FROM sponsorTimes WHERE UUID = ?").get(UUID, function(err, row) {
db.prepare("SELECT votes, views FROM sponsorTimes WHERE UUID = ?").get(UUID, async function(err, row) {
if (vipResult.row.userCount != 0 && incrementAmount < 0) {
//this user is a vip and a downvote
//their vote should be -25 or -80%
@ -310,6 +298,30 @@ app.get('/api/voteOnSponsorTime', function (req, res) {
//oldIncrementAmount will be zero is row is null
db.prepare("UPDATE sponsorTimes SET votes = votes + ? WHERE UUID = ?").run(incrementAmount - oldIncrementAmount, UUID);
//for each positive vote, see if a hidden submission can be shown again
if (incrementAmount > 0) {
//find the UUID that submitted the submission that was voted on
let userIDSubmittedResult = await new Promise((resolve, reject) => {
db.prepare("SELECT userID FROM sponsorTimes WHERE UUID = ?").get(UUID, (err, row) => resolve({err, row}));
});
let submissionUserID = userIDSubmittedResult.row.userID;
//check if any submissions are hidden
let hiddenSubmissionsResult = await new Promise((resolve, reject) => {
db.prepare("SELECT count(*) as hiddenSubmissions FROM sponsorTimes WHERE userID = ? AND shadowHidden > 0").get(submissionUserID, (err, row) => resolve({err, row}));
});
if (hiddenSubmissionsResult.row.hiddenSubmissions > 0) {
//see if some of this users submissions should be visible again
if (await isUserTrustworthy(submissionUserID)) {
//they are trustworthy again, show 2 of their submissions again, if there are two to show
db.prepare("UPDATE sponsorTimes SET shadowHidden = 0 WHERE ROWID IN (SELECT ROWID FROM sponsorTimes WHERE userID = ? AND shadowHidden = 1 LIMIT 2)").run(submissionUserID)
}
}
}
//added to db
res.sendStatus(200);
});
@ -619,6 +631,27 @@ app.get('/database.db', function (req, res) {
res.sendFile("./databases/sponsorTimes.db", { root: __dirname });
});
//returns true if the user is considered trustworthy
//this happens after a user has made 5 submissions and has less than 60% downvoted submissions
async function isUserTrustworthy(userID) {
//check to see if this user how many submissions this user has submitted
let totalSubmissionsResult = await new Promise((resolve, reject) => {
db.prepare("SELECT count(*) as totalSubmissions, sum(votes) as voteSum FROM sponsorTimes WHERE userID = ?").get(userID, (err, row) => resolve({err, row}));
});
if (totalSubmissionsResult.row.totalSubmissions > 5) {
//check if they have a high downvote ratio
let downvotedSubmissionsResult = await new Promise((resolve, reject) => {
db.prepare("SELECT count(*) as downvotedSubmissions FROM sponsorTimes WHERE userID = ? AND votes < 0").get(userID, (err, row) => resolve({err, row}));
});
return (downvotedSubmissionsResult.row.downvotedSubmissions / totalSubmissionsResult.row.totalSubmissions) < 0.6 ||
(totalSubmissionsResult.row.voteSum > downvotedSubmissionsResult.row.downvotedSubmissions);
}
return true;
}
//This function will find sponsor times that are contained inside of eachother, called similar sponsor times
//Only one similar time will be returned, randomly generated based on the sqrt of votes.
//This allows new less voted items to still sometimes appear to give them a chance at getting votes.