diff --git a/src/config.ts b/src/config.ts index 654fab2..c290a6f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -48,6 +48,7 @@ addDefaults(config, { discordDeArrowLockedWebhookURL: null, discordDeArrowWarnedWebhookURL: null, discordNewUserWebhookURL: null, + discordRejectedNewUserWebhookURL: null, minReputationToSubmitChapter: 0, minReputationToSubmitFiller: 0, getTopUsersCacheTimeMinutes: 240, diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index b6d426d..4d7edfa 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -2,7 +2,7 @@ import { Request, Response } from "express"; import { config } from "../config"; import { db, privateDB } from "../databases/databases"; -import { BrandingSubmission, BrandingUUID, TimeThumbnailSubmission } from "../types/branding.model"; +import { BrandingSubmission, BrandingUUID, TimeThumbnailSubmission, TitleSubmission } from "../types/branding.model"; import { HashedIP, IPAddress, VideoID } from "../types/segments.model"; import { Feature, HashedUserID } from "../types/user.model"; import { getHashCache } from "../utils/getHashCache"; @@ -73,6 +73,7 @@ export async function postBranding(req: Request, res: Response) { }, endpoint: "dearrow-postBranding", })) { + sendNewUserWebhook(config.discordRejectedNewUserWebhookURL, hashedUserID, videoID, userAgent, req, videoDuration, title); Logger.warn(`Dearrow submission rejected by request validator: ${hashedUserID} ${videoID} ${videoDuration} ${userAgent} ${req.headers["user-agent"]} ${title.title} ${thumbnail.timestamp}`); res.status(200).send("OK"); return; @@ -84,34 +85,8 @@ export async function postBranding(req: Request, res: Response) { res.status(403).send(permission.reason); return; - } else if (permission.newUser && config.discordNewUserWebhookURL) { - axios.post(config.discordNewUserWebhookURL, { - "embeds": [{ - "title": hashedUserID, - "url": `https://www.youtube.com/watch?v=${videoID}`, - "description": `**User Agent**: ${userAgent}\ - \n**Sent User Agent**: ${req.body.userAgent}\ - \n**Real User Agent**: ${req.headers["user-agent"]}\ - \n**Video Duration**: ${videoDuration}\ - \n**Title**: ${title?.title}`, - "color": 1184701, - "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"); - }); + } else if (permission.newUser) { + sendNewUserWebhook(config.discordNewUserWebhookURL, hashedUserID, videoID, userAgent, req, videoDuration, title); } if (videoDuration && thumbnail && await checkForWrongVideoDuration(videoID, videoDuration)) { @@ -235,6 +210,38 @@ export async function postBranding(req: Request, res: Response) { } } +function sendNewUserWebhook(webhookUrl: string, hashedUserID: HashedUserID, videoID: VideoID, userAgent: any, req: Request, videoDuration: number, title: TitleSubmission) { + if (!webhookUrl) return; + + axios.post(webhookUrl, { + "embeds": [{ + "title": hashedUserID, + "url": `https://www.youtube.com/watch?v=${videoID}`, + "description": `**User Agent**: ${userAgent}\ + \n**Sent User Agent**: ${req.body.userAgent}\ + \n**Real User Agent**: ${req.headers["user-agent"]}\ + \n**Video Duration**: ${videoDuration}\ + \n**Title**: ${title?.title}`, + "color": 1184701, + "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"); + }); +} + /** * Finds an existing vote, if found, and it's for a different submission, it undoes it, and points to the new submission. * If no existing vote, it adds one. diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index deb3908..92c88a3 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -520,6 +520,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise { - 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"); - }); + } else if (permission.newUser) { + sendNewUserWebhook(config.discordNewUserWebhookURL, userID, videoID, userAgent, req, videoDurationParam); } // Will be filled when submitting @@ -685,6 +661,37 @@ export async function postSkipSegments(req: Request, res: Response): Promise { + 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"); + }); +} + // Takes an array of arrays: // ex) // [ diff --git a/src/types/config.model.ts b/src/types/config.model.ts index 7295b56..8c42ca9 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -86,6 +86,7 @@ export interface SBSConfig { discordNewUserWebhookURL?: string; neuralBlockURL?: string; discordNeuralBlockRejectWebhookURL?: string; + discordRejectedNewUserWebhookURL?: string; minReputationToSubmitChapter: number; minReputationToSubmitFiller: number; userCounterURL?: string;