Change automod check to call YT and NB API a single time per submission

This commit is contained in:
Andrew Lee
2020-09-11 17:08:41 -04:00
parent 137a6dc771
commit 6843e22a7b

View File

@@ -169,33 +169,58 @@ async function autoModerateSubmission(submission) {
if (data.pageInfo.totalResults === 0) { if (data.pageInfo.totalResults === 0) {
return "No video exists with id " + submission.videoID; return "No video exists with id " + submission.videoID;
} else { } else {
let segments = submission.segments;
let nbString = "";
for (let i = 0; i < segments.length; i++) {
let startTime = parseFloat(segments[i].segment[0]);
let endTime = parseFloat(segments[i].segment[1]);
let duration = data.items[0].contentDetails.duration; let duration = data.items[0].contentDetails.duration;
duration = isoDurations.toSeconds(isoDurations.parse(duration)); duration = isoDurations.toSeconds(isoDurations.parse(duration));
if (duration == 0) { if (duration == 0) {
// Allow submission if the duration is 0 (bug in youtube api) // Allow submission if the duration is 0 (bug in youtube api)
return false; return false;
} else if ((submission.endTime - submission.startTime) > (duration/100)*80) { } else if ((endTime - startTime) > (duration/100)*80) {
// Reject submission if over 80% of the video // Reject submission if over 80% of the video
return "One of your submitted segments is over 80% of the video."; return "One of your submitted segments is over 80% of the video.";
} else { } else {
if (segments[i].category === "sponsor") {
//Prepare timestamps to send to NB all at once
nbString = nbString + segments[i].segment[0] + "," + segments[i].segment[1] + ";";
}
}
}
// Check NeuralBlock // Check NeuralBlock
let neuralBlockURL = config.neuralBlockURL; let neuralBlockURL = config.neuralBlockURL;
if (!neuralBlockURL) return false; if (!neuralBlockURL) return false;
let response = await fetch(neuralBlockURL + "/api/checkSponsorSegments?vid=" + submission.videoID + let response = await fetch(neuralBlockURL + "/api/checkSponsorSegments?vid=" + submission.videoID +
"&segments=" + submission.startTime + "," + submission.endTime); "&segments=" + nbString.substring(0,nbString.length-1));
if (!response.ok) return false; if (!response.ok) return false;
let nbPredictions = await response.json(); let nbPredictions = await response.json();
if (nbPredictions.probabilities[0] >= 0.70){ nbDecision = false;
return false; let predictionIdx = 0; //Keep track because only sponsor categories were submitted
} else { for (let i = 0; i < segments.length; i++){
let UUID = getHash("v2-categories" + submission.videoID + submission.startTime + if (segments[i].category === "sponsor"){
submission.endTime + submission.category + submission.userID, 1); if (nbPredictions.probabilities[predictionIdx] < 0.70){
nbDecision = true; // At least one bad entry
startTime = parseFloat(segments[i].segment[0]);
endTime = parseFloat(segments[i].segment[1]);
let UUID = getHash("v2-categories" + submission.videoID + startTime +
endTime + segments[i].category + submission.userID, 1);
// Send to Discord // Send to Discord
sendWebhooksNB(submission.userID, submission.videoID, UUID, submission.startTime, submission.endTime, submission.category, nbPredictions.probabilities[0], data); // Note, if this is too spammy. Consider sending all the segments as one Webhook
return "NB disagreement."; sendWebhooksNB(submission.userID, submission.videoID, UUID, startTime, endTime, segments[i].category, nbPredictions.probabilities[predictionIdx], data);
} }
predictionIdx++;
}
}
if (nbDecision){
return "NB disagreement.";
} else {
return false;
} }
} }
} }
@@ -288,12 +313,16 @@ module.exports = async function postSkipSegments(req, res) {
res.sendStatus(409); res.sendStatus(409);
return; return;
} }
}
// Auto moderator check // Auto moderator check
if (!isVIP) { if (!isVIP) {
let autoModerateResult = await autoModerateSubmission({userID, videoID, startTime, endTime, category: segments[i].category}); let autoModerateResult = await autoModerateSubmission({userID, videoID, segments});//startTime, endTime, category: segments[i].category});
if (autoModerateResult == "NB disagreement."){ if (autoModerateResult == "NB disagreement."){
// If NB automod rejects, the submission will start with -2 votes // If NB automod rejects, the submission will start with -2 votes.
// Note, if one submission is bad all submissions will be affected.
// However, this behavior is consistent with other automod functions
// already in place.
//decreaseVotes = -2; //Disable for now //decreaseVotes = -2; //Disable for now
} else if (autoModerateResult) { } else if (autoModerateResult) {
//Normal automod behavior //Normal automod behavior
@@ -301,8 +330,6 @@ module.exports = async function postSkipSegments(req, res) {
return; return;
} }
} }
}
// Will be filled when submitting // Will be filled when submitting
let UUIDs = []; let UUIDs = [];