Send moderator rejected votes to discord anyway

This commit is contained in:
Ajay Ramachandran 2021-03-19 18:05:33 -04:00
parent cfdb0f4466
commit 1f01c004ae

View file

@ -33,6 +33,7 @@ interface VoteData {
category: string; category: string;
incrementAmount: number; incrementAmount: number;
oldIncrementAmount: number; oldIncrementAmount: number;
finalMessage: string;
} }
async function sendWebhooks(voteData: VoteData) { async function sendWebhooks(voteData: VoteData) {
@ -111,7 +112,7 @@ async function sendWebhooks(voteData: VoteData) {
getFormattedTime(submissionInfoRow.startTime) + " to " + getFormattedTime(submissionInfoRow.endTime), getFormattedTime(submissionInfoRow.startTime) + " to " + getFormattedTime(submissionInfoRow.endTime),
"color": 10813440, "color": 10813440,
"author": { "author": {
"name": getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission), "name": voteData.finalMessage ?? getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission),
}, },
"thumbnail": { "thumbnail": {
"url": data.items[0].snippet.thumbnails.maxres ? data.items[0].snippet.thumbnails.maxres.url : "", "url": data.items[0].snippet.thumbnails.maxres ? data.items[0].snippet.thumbnails.maxres.url : "",
@ -238,6 +239,10 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
const nonAnonUserID = getHash(paramUserID); const nonAnonUserID = getHash(paramUserID);
const userID = getHash(paramUserID + UUID); const userID = getHash(paramUserID + UUID);
// To force a non 200, change this early
let finalStatus = 200;
let finalMessage = null;
//x-forwarded-for if this server is behind a proxy //x-forwarded-for if this server is behind a proxy
const ip = getIP(req); const ip = getIP(req);
@ -258,7 +263,8 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
' where "UUID" = ?', [UUID])); ' where "UUID" = ?', [UUID]));
if (await isSegmentLocked() || await isVideoLocked()) { if (await isSegmentLocked() || await isVideoLocked()) {
res.status(403).send("Vote rejected: A moderator has decided that this segment is correct"); finalStatus = 403;
finalMessage = "Vote rejected: A moderator has decided that this segment is correct"
return; return;
} }
} }
@ -415,7 +421,7 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
} }
} }
res.sendStatus(200); res.status(finalStatus).send(finalMessage ?? undefined);
if (incrementAmount - oldIncrementAmount !== 0) { if (incrementAmount - oldIncrementAmount !== 0) {
sendWebhooks({ sendWebhooks({
@ -428,6 +434,7 @@ export async function voteOnSponsorTime(req: Request, res: Response) {
category, category,
incrementAmount, incrementAmount,
oldIncrementAmount, oldIncrementAmount,
finalMessage
}); });
} }
} catch (err) { } catch (err) {