mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 13:07:02 +03:00
Add new webhook for was warned
This commit is contained in:
@@ -45,6 +45,7 @@ addDefaults(config, {
|
|||||||
discordReportChannelWebhookURL: null,
|
discordReportChannelWebhookURL: null,
|
||||||
discordMaliciousReportWebhookURL: null,
|
discordMaliciousReportWebhookURL: null,
|
||||||
discordDeArrowLockedWebhookURL: null,
|
discordDeArrowLockedWebhookURL: null,
|
||||||
|
discordDeArrowWarnedWebhookURL: null,
|
||||||
minReputationToSubmitChapter: 0,
|
minReputationToSubmitChapter: 0,
|
||||||
minReputationToSubmitFiller: 0,
|
minReputationToSubmitFiller: 0,
|
||||||
getTopUsersCacheTimeMinutes: 240,
|
getTopUsersCacheTimeMinutes: 240,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ interface ExistingVote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function postBranding(req: Request, res: Response) {
|
export async function postBranding(req: Request, res: Response) {
|
||||||
const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration } = req.body as BrandingSubmission;
|
const { videoID, userID, title, thumbnail, autoLock, downvote, videoDuration, wasWarned } = req.body as BrandingSubmission;
|
||||||
const service = getService(req.body.service);
|
const service = getService(req.body.service);
|
||||||
|
|
||||||
if (!videoID || !userID || userID.length < 30 || !service
|
if (!videoID || !userID || userID.length < 30 || !service
|
||||||
@@ -86,7 +86,7 @@ export async function postBranding(req: Request, res: Response) {
|
|||||||
const existingIsLocked = !!existingUUID && (await db.prepare("get", `SELECT "locked" from "titleVotes" where "UUID" = ?`, [existingUUID]))?.locked;
|
const existingIsLocked = !!existingUUID && (await db.prepare("get", `SELECT "locked" from "titleVotes" where "UUID" = ?`, [existingUUID]))?.locked;
|
||||||
if (existingUUID != undefined && isBanned) return; // ignore votes on existing details from banned users
|
if (existingUUID != undefined && isBanned) return; // ignore votes on existing details from banned users
|
||||||
if (downvote && existingIsLocked && !isVip) {
|
if (downvote && existingIsLocked && !isVip) {
|
||||||
sendWebhooks(videoID, existingUUID, voteType).catch((e) => Logger.error(e));
|
sendWebhooks(videoID, existingUUID, voteType, wasWarned).catch((e) => Logger.error(e));
|
||||||
errorCode = 403;
|
errorCode = 403;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ export async function postBranding(req: Request, res: Response) {
|
|||||||
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]);
|
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, voteType).catch((e) => Logger.error(e));
|
sendWebhooks(videoID, UUID, voteType, wasWarned).catch((e) => Logger.error(e));
|
||||||
}
|
}
|
||||||
})(), (async () => {
|
})(), (async () => {
|
||||||
if (thumbnail) {
|
if (thumbnail) {
|
||||||
@@ -307,7 +307,7 @@ async function canSubmitOriginal(hashedUserID: HashedUserID, isVip: boolean): Pr
|
|||||||
return isVip || (upvotedThumbs > 1 && customThumbs > 1 && originalThumbs / customThumbs < 0.4);
|
return isVip || (upvotedThumbs > 1 && customThumbs > 1 && originalThumbs / customThumbs < 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID, voteType: BrandingVoteType) {
|
async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID, voteType: BrandingVoteType, wasWarned: boolean) {
|
||||||
const currentSubmission = await db.prepare(
|
const currentSubmission = await db.prepare(
|
||||||
"get",
|
"get",
|
||||||
`SELECT
|
`SELECT
|
||||||
@@ -319,6 +319,34 @@ async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID, voteType: Bran
|
|||||||
WHERE "titles"."UUID" = ?`,
|
WHERE "titles"."UUID" = ?`,
|
||||||
[UUID]);
|
[UUID]);
|
||||||
|
|
||||||
|
if (wasWarned) {
|
||||||
|
const data = await getVideoDetails(videoID);
|
||||||
|
axios.post(config.discordDeArrowWarnedWebhookURL, {
|
||||||
|
"embeds": [{
|
||||||
|
"title": data?.title,
|
||||||
|
"url": `https://www.youtube.com/watch?v=${videoID}`,
|
||||||
|
"description": `**Submitted title:** ${currentSubmission.title}\
|
||||||
|
\n\n**Submitted by:** ${currentSubmission.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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Unlocked title getting more upvotes than the locked one
|
// Unlocked title getting more upvotes than the locked one
|
||||||
if (voteType === BrandingVoteType.Upvote) {
|
if (voteType === BrandingVoteType.Upvote) {
|
||||||
const lockedSubmission = await db.prepare(
|
const lockedSubmission = await db.prepare(
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export interface BrandingSubmission {
|
|||||||
autoLock: boolean | undefined;
|
autoLock: boolean | undefined;
|
||||||
downvote: boolean | undefined;
|
downvote: boolean | undefined;
|
||||||
videoDuration: number | undefined;
|
videoDuration: number | undefined;
|
||||||
|
wasWarned: boolean | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BrandingSegmentDBResult {
|
export interface BrandingSegmentDBResult {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export interface SBSConfig {
|
|||||||
discordCompletelyIncorrectReportWebhookURL?: string;
|
discordCompletelyIncorrectReportWebhookURL?: string;
|
||||||
discordMaliciousReportWebhookURL?: string;
|
discordMaliciousReportWebhookURL?: string;
|
||||||
discordDeArrowLockedWebhookURL?: string,
|
discordDeArrowLockedWebhookURL?: string,
|
||||||
|
discordDeArrowWarnedWebhookURL?: string,
|
||||||
neuralBlockURL?: string;
|
neuralBlockURL?: string;
|
||||||
discordNeuralBlockRejectWebhookURL?: string;
|
discordNeuralBlockRejectWebhookURL?: string;
|
||||||
minReputationToSubmitChapter: number;
|
minReputationToSubmitChapter: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user