diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index ce59172..36e23a0 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -19,9 +19,17 @@ const voteTypes = { incorrect: 1, }; +enum VoteWebhookType { + Normal, + Rejected +} + interface FinalResponse { + blockVote: boolean, finalStatus: number - finalMessage: string + finalMessage: string, + webhookType: VoteWebhookType, + webhookMessage: string } interface VoteData { @@ -52,7 +60,15 @@ async function sendWebhooks(voteData: VoteData) { if (submissionInfoRow !== undefined && userSubmissionCountRow != undefined) { let webhookURL: string = null; if (voteData.voteTypeEnum === voteTypes.normal) { - webhookURL = config.discordReportChannelWebhookURL; + switch (voteData.finalResponse.webhookType) { + case VoteWebhookType.Normal: + webhookURL = config.discordReportChannelWebhookURL; + break; + case VoteWebhookType.Rejected: + webhookURL = config.discordFailedReportChannelWebhookURL; + break; + } + } else if (voteData.voteTypeEnum === voteTypes.incorrect) { webhookURL = config.discordCompletelyIncorrectReportWebhookURL; } @@ -114,7 +130,9 @@ async function sendWebhooks(voteData: VoteData) { getFormattedTime(submissionInfoRow.startTime) + " to " + getFormattedTime(submissionInfoRow.endTime), "color": 10813440, "author": { - "name": voteData.finalResponse?.finalMessage ?? getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission), + "name": voteData.finalResponse?.webhookMessage ?? + voteData.finalResponse?.finalMessage ?? + getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission), }, "thumbnail": { "url": getMaxResThumbnail(data) || "", @@ -252,8 +270,11 @@ export async function voteOnSponsorTime(req: Request, res: Response) { // To force a non 200, change this early let finalResponse: FinalResponse = { + blockVote: false, finalStatus: 200, - finalMessage: null + finalMessage: null, + webhookType: VoteWebhookType.Normal, + webhookMessage: null } //x-forwarded-for if this server is behind a proxy @@ -276,8 +297,9 @@ export async function voteOnSponsorTime(req: Request, res: Response) { ' where "UUID" = ?', [UUID])); if (await isSegmentLocked() || await isVideoLocked()) { - finalResponse.finalStatus = 403; - finalResponse.finalMessage = "Vote rejected: A moderator has decided that this segment is correct" + finalResponse.blockVote = true; + finalResponse.webhookType = VoteWebhookType.Normal + finalResponse.webhookMessage = "Vote rejected: A moderator has decided that this segment is correct" } } @@ -384,6 +406,7 @@ export async function voteOnSponsorTime(req: Request, res: Response) { && (await db.prepare("get", `SELECT "userID" FROM "sponsorTimes" WHERE "userID" = ?`, [nonAnonUserID])) !== undefined && (await privateDB.prepare("get", `SELECT "userID" FROM "shadowBannedUsers" WHERE "userID" = ?`, [nonAnonUserID])) === undefined && (await privateDB.prepare("get", `SELECT "UUID" FROM "votes" WHERE "UUID" = ? AND "hashedIP" = ? AND "userID" != ?`, [UUID, hashedIP, userID])) === undefined) + && !finalResponse.blockVote && finalResponse.finalStatus === 200; if (ableToVote) { diff --git a/src/types/config.model.ts b/src/types/config.model.ts index f5614d9..dc16d0d 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -8,6 +8,7 @@ export interface SBSConfig { adminUserID: string; newLeafURLs?: string[]; discordReportChannelWebhookURL?: string; + discordFailedReportChannelWebhookURL?: string; discordFirstTimeSubmissionsWebhookURL?: string; discordCompletelyIncorrectReportWebhookURL?: string; neuralBlockURL?: string; diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index f649d12..b2cbc27 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -446,10 +446,10 @@ describe('voteOnSponsorTime', () => { + "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=0") .then(async res => { let row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]); - if (res.status === 403 && row.votes === 2) { + if (res.status === 200 && row.votes === 2) { done(); } else { - done("Status code was " + res.status + " instead of 403, row was " + JSON.stringify(row)); + done("Status code was " + res.status + " instead of 200, row was " + JSON.stringify(row)); } }) .catch(err => done(err)); @@ -474,10 +474,10 @@ describe('voteOnSponsorTime', () => { + "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&category=outro") .then(async res => { let row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]); - if (res.status === 403 && row.category === "sponsor") { + if (res.status === 200 && row.category === "sponsor") { done(); } else { - done("Status code was " + res.status + " instead of 403, row was " + JSON.stringify(row)); + done("Status code was " + res.status + " instead of 200, row was " + JSON.stringify(row)); } }) .catch(err => done(err));