Silently reject votes

This commit is contained in:
Ajay Ramachandran
2021-06-08 20:20:05 -04:00
parent 1c8c76831e
commit 4225d9b3b3
3 changed files with 34 additions and 10 deletions

View File

@@ -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) {