mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-15 07:57:05 +03:00
Removed unnecessary YT API call from NB Discord webhook
This commit is contained in:
@@ -98,69 +98,54 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendWebhooksNB(userID, videoID, UUID, startTime, endTime, category, probability) {
|
function sendWebhooksNB(userID, videoID, UUID, startTime, endTime, category, probability, ytData) {
|
||||||
if (config.youtubeAPIKey !== null) {
|
//let submissionInfoRow = db.prepare('get', "SELECT s.videoID, s.userID, s.startTime, s.endTime, s.category, u.userName, " +
|
||||||
//let submissionInfoRow = db.prepare('get', "SELECT s.videoID, s.userID, s.startTime, s.endTime, s.category, u.userName, " +
|
// "(select count(1) from sponsorTimes where userID = s.userID) count, " +
|
||||||
// "(select count(1) from sponsorTimes where userID = s.userID) count, " +
|
// "(select count(1) from sponsorTimes where userID = s.userID and votes <= -2) disregarded " +
|
||||||
// "(select count(1) from sponsorTimes where userID = s.userID and votes <= -2) disregarded " +
|
// "FROM sponsorTimes s left join userNames u on s.userID = u.userID where s.userId=?",
|
||||||
// "FROM sponsorTimes s left join userNames u on s.userID = u.userID where s.userId=?",
|
//[userID]);
|
||||||
//[userID]);
|
let submissionCount = db.prepare('get', "SELECT COUNT(*) count FROM sponsorTimes WHERE userID=?", [userID]);
|
||||||
let submissionCount = db.prepare('get', "SELECT COUNT(*) count FROM sponsorTimes WHERE userID=?", [userID]);
|
let disregardedCount = db.prepare('get', "SELECT COUNT(*) disregarded FROM sponsorTimes WHERE userID=? and votes <= -2", [userID]);
|
||||||
let disregardedCount = db.prepare('get', "SELECT COUNT(*) disregarded FROM sponsorTimes WHERE userID=? and votes <= -2", [userID]);
|
//let uName = db.prepare('get', "SELECT userName FROM userNames WHERE userID=?", [userID]);
|
||||||
//let uName = db.prepare('get', "SELECT userName FROM userNames WHERE userID=?", [userID]);
|
let submittedBy = userID;//"";
|
||||||
YouTubeAPI.videos.list({
|
// If there's no userName then just show the userID
|
||||||
part: "snippet",
|
// if (uName.userName == userID){
|
||||||
id: videoID
|
// submittedBy = userID;
|
||||||
}, function (err, data) {
|
// } else { // else show both
|
||||||
if (err || data.items.length === 0) {
|
// submittedBy = uName.userName + "\n " + userID;
|
||||||
err && logger.error(err);
|
// }
|
||||||
return;
|
|
||||||
}
|
|
||||||
//sendWebhookNotification(userID, videoID, UUID, submissionInfoRow.submissionCount, data, {submissionStart: startTime, submissionEnd: endTime}, segmentInfo);
|
|
||||||
let submittedBy = userID;//"";
|
|
||||||
// If there's no userName then just show the userID
|
|
||||||
// if (uName.userName == userID){
|
|
||||||
// submittedBy = userID;
|
|
||||||
// } else { // else show both
|
|
||||||
// submittedBy = uName.userName + "\n " + userID;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Send discord message
|
// Send discord message
|
||||||
if (config.discordNeuralBlockRejectWebhookURL === null) return;
|
if (config.discordNeuralBlockRejectWebhookURL === null) return;
|
||||||
request.post(config.discordNeuralBlockRejectWebhookURL, {
|
request.post(config.discordNeuralBlockRejectWebhookURL, {
|
||||||
json: {
|
json: {
|
||||||
"embeds": [{
|
"embeds": [{
|
||||||
"title": data.items[0].snippet.title,
|
"title": ytData.items[0].snippet.title,
|
||||||
"url": "https://www.youtube.com/watch?v=" + videoID + "&t=" + (startTime.toFixed(0) - 2),
|
"url": "https://www.youtube.com/watch?v=" + videoID + "&t=" + (startTime.toFixed(0) - 2),
|
||||||
"description": "**Submission ID:** " + UUID +
|
"description": "**Submission ID:** " + UUID +
|
||||||
"\n**Timestamp:** " + getFormattedTime(startTime) + " to " + getFormattedTime(endTime) +
|
"\n**Timestamp:** " + getFormattedTime(startTime) + " to " + getFormattedTime(endTime) +
|
||||||
"\n**Predicted Probability:** " + probability +
|
"\n**Predicted Probability:** " + probability +
|
||||||
"\n**Category:** " + category +
|
"\n**Category:** " + category +
|
||||||
"\n**Submitted by:** "+ submittedBy +
|
"\n**Submitted by:** "+ submittedBy +
|
||||||
"\n**Total User Submissions:** "+submissionCount.count +
|
"\n**Total User Submissions:** "+submissionCount.count +
|
||||||
"\n**Ignored User Submissions:** "+disregardedCount.disregarded,
|
"\n**Ignored User Submissions:** "+disregardedCount.disregarded,
|
||||||
"color": 10813440,
|
"color": 10813440,
|
||||||
"author": {
|
"thumbnail": {
|
||||||
"name": userID
|
"url": ytData.items[0].snippet.thumbnails.maxres ? ytData.items[0].snippet.thumbnails.maxres.url : "",
|
||||||
},
|
|
||||||
"thumbnail": {
|
|
||||||
"url": data.items[0].snippet.thumbnails.maxres ? data.items[0].snippet.thumbnails.maxres.url : "",
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
}, (err, res) => {
|
}]
|
||||||
if (err) {
|
}
|
||||||
logger.error("Failed to send NeuralBlock Discord hook.");
|
}, (err, res) => {
|
||||||
logger.error(JSON.stringify(err));
|
if (err) {
|
||||||
logger.error("\n");
|
logger.error("Failed to send NeuralBlock Discord hook.");
|
||||||
} else if (res && res.statusCode >= 400) {
|
logger.error(JSON.stringify(err));
|
||||||
logger.error("Error sending NeuralBlock Discord hook");
|
logger.error("\n");
|
||||||
logger.error(JSON.stringify(res));
|
} else if (res && res.statusCode >= 400) {
|
||||||
logger.error("\n");
|
logger.error("Error sending NeuralBlock Discord hook");
|
||||||
}
|
logger.error(JSON.stringify(res));
|
||||||
});
|
logger.error("\n");
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback: function(reject: "String containing reason the submission was rejected")
|
// callback: function(reject: "String containing reason the submission was rejected")
|
||||||
@@ -174,7 +159,7 @@ async function autoModerateSubmission(submission) {
|
|||||||
if (config.youtubeAPIKey !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
let {err, data} = await new Promise((resolve, reject) => {
|
let {err, data} = await new Promise((resolve, reject) => {
|
||||||
YouTubeAPI.videos.list({
|
YouTubeAPI.videos.list({
|
||||||
part: "contentDetails",
|
part: "contentDetails,snippet",
|
||||||
id: submission.videoID
|
id: submission.videoID
|
||||||
}, (err, data) => resolve({err, data}));
|
}, (err, data) => resolve({err, data}));
|
||||||
});
|
});
|
||||||
@@ -210,7 +195,7 @@ async function autoModerateSubmission(submission) {
|
|||||||
let UUID = getHash("v2-categories" + submission.videoID + submission.startTime +
|
let UUID = getHash("v2-categories" + submission.videoID + submission.startTime +
|
||||||
submission.endTime + submission.category + submission.userID, 1);
|
submission.endTime + submission.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]);
|
sendWebhooksNB(submission.userID, submission.videoID, UUID, submission.startTime, submission.endTime, submission.category, nbPredictions.probabilities[0], data);
|
||||||
return "NB disagreement.";
|
return "NB disagreement.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user