mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Add warning when locked title probably outdated
This commit is contained in:
parent
5714f51ac0
commit
3708d293dc
3 changed files with 48 additions and 0 deletions
|
@ -45,6 +45,7 @@ addDefaults(config, {
|
|||
discordFailedReportChannelWebhookURL: null,
|
||||
discordReportChannelWebhookURL: null,
|
||||
discordMaliciousReportWebhookURL: null,
|
||||
discordDeArrowLockedWebhookURL: null,
|
||||
minReputationToSubmitChapter: 0,
|
||||
minReputationToSubmitFiller: 0,
|
||||
getTopUsersCacheTimeMinutes: 240,
|
||||
|
|
|
@ -15,6 +15,9 @@ import { QueryCacher } from "../utils/queryCacher";
|
|||
import { acquireLock } from "../utils/redisLock";
|
||||
import { hasFeature } from "../utils/features";
|
||||
import { checkBanStatus } from "../utils/checkBan";
|
||||
import axios from "axios";
|
||||
import { getMaxResThumbnail } from "../utils/youtubeApi";
|
||||
import { getVideoDetails } from "../utils/getVideoDetails";
|
||||
|
||||
enum BrandingType {
|
||||
Title,
|
||||
|
@ -88,6 +91,8 @@ export async function postBranding(req: Request, res: Response) {
|
|||
// unlock all other titles
|
||||
await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]);
|
||||
}
|
||||
|
||||
sendWebhooks(videoID, UUID).catch((e) => Logger.error(e));
|
||||
}
|
||||
})(), (async () => {
|
||||
if (thumbnail) {
|
||||
|
@ -201,3 +206,44 @@ export async function verifyOldSubmissions(hashedUserID: HashedUserID, verificat
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID) {
|
||||
const lockedSubmission = await db.prepare("get", `SELECT "titleVotes"."votes", "titles"."title", "titles"."userID" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."videoID" = ? AND "titles"."UUID" != ? AND "titleVotes"."locked" = 1`, [videoID, UUID]);
|
||||
|
||||
if (lockedSubmission) {
|
||||
const currentSubmission = await db.prepare("get", `SELECT "titleVotes"."votes", "titles"."title" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."UUID" = ?`, [UUID]);
|
||||
|
||||
// Time to warn that there may be an issue
|
||||
if (currentSubmission.votes - lockedSubmission.votes > 2) {
|
||||
const usernameRow = await db.prepare("get", `SELECT "userName" FROM "userNames" WHERE "userID" = ?`, [lockedSubmission.userID]);
|
||||
|
||||
const data = await getVideoDetails(videoID);
|
||||
axios.post(config.discordDeArrowLockedWebhookURL, {
|
||||
"embeds": [{
|
||||
"title": data?.title,
|
||||
"url": `https://www.youtube.com/watch?v=${videoID}`,
|
||||
"description": `**${lockedSubmission.votes}** Votes vs **${currentSubmission.votes}**\
|
||||
\n\n**Locked title:** ${lockedSubmission.title}\
|
||||
\n**New title:** ${currentSubmission.title}\
|
||||
\n\n**Submitted by:** ${usernameRow?.userName ?? ""}\n${lockedSubmission.userID}`,
|
||||
"color": 10813440,
|
||||
"thumbnail": {
|
||||
"url": getMaxResThumbnail(videoID),
|
||||
},
|
||||
}],
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status >= 400) {
|
||||
Logger.error("Error sending reported submission Discord hook");
|
||||
Logger.error(JSON.stringify((res.data)));
|
||||
Logger.error("\n");
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
Logger.error("Failed to send reported submission Discord hook.");
|
||||
Logger.error(JSON.stringify(err));
|
||||
Logger.error("\n");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,6 +48,7 @@ export interface SBSConfig {
|
|||
discordFirstTimeSubmissionsWebhookURL?: string;
|
||||
discordCompletelyIncorrectReportWebhookURL?: string;
|
||||
discordMaliciousReportWebhookURL?: string;
|
||||
discordDeArrowLockedWebhookURL?: string,
|
||||
neuralBlockURL?: string;
|
||||
discordNeuralBlockRejectWebhookURL?: string;
|
||||
minReputationToSubmitChapter: number;
|
||||
|
|
Loading…
Reference in a new issue