Skip to content

Commit

Permalink
Add new webhook for was warned
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Oct 18, 2024
1 parent 566eabd commit e9c0c44
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ addDefaults(config, {
discordReportChannelWebhookURL: null,
discordMaliciousReportWebhookURL: null,
discordDeArrowLockedWebhookURL: null,
discordDeArrowWarnedWebhookURL: null,
minReputationToSubmitChapter: 0,
minReputationToSubmitFiller: 0,
getTopUsersCacheTimeMinutes: 240,
Expand Down
36 changes: 32 additions & 4 deletions src/routes/postBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface ExistingVote {
}

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);

if (!videoID || !userID || userID.length < 30 || !service
Expand Down Expand Up @@ -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;
if (existingUUID != undefined && isBanned) return; // ignore votes on existing details from banned users
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;
return;
}
Expand Down Expand Up @@ -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]);
}

sendWebhooks(videoID, UUID, voteType).catch((e) => Logger.error(e));
sendWebhooks(videoID, UUID, voteType, wasWarned).catch((e) => Logger.error(e));
}
})(), (async () => {
if (thumbnail) {
Expand Down Expand Up @@ -307,7 +307,7 @@ async function canSubmitOriginal(hashedUserID: HashedUserID, isVip: boolean): Pr
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(
"get",
`SELECT
Expand All @@ -319,6 +319,34 @@ async function sendWebhooks(videoID: VideoID, UUID: BrandingUUID, voteType: Bran
WHERE "titles"."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
if (voteType === BrandingVoteType.Upvote) {
const lockedSubmission = await db.prepare(
Expand Down
1 change: 1 addition & 0 deletions src/types/branding.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface BrandingSubmission {
autoLock: boolean | undefined;
downvote: boolean | undefined;
videoDuration: number | undefined;
wasWarned: boolean | undefined;
}

export interface BrandingSegmentDBResult {
Expand Down
1 change: 1 addition & 0 deletions src/types/config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface SBSConfig {
discordCompletelyIncorrectReportWebhookURL?: string;
discordMaliciousReportWebhookURL?: string;
discordDeArrowLockedWebhookURL?: string,
discordDeArrowWarnedWebhookURL?: string,
neuralBlockURL?: string;
discordNeuralBlockRejectWebhookURL?: string;
minReputationToSubmitChapter: number;
Expand Down

0 comments on commit e9c0c44

Please sign in to comment.