From 497a509d60ba405ec6a6e1fa7a7552f6d987043f Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 3 Aug 2021 13:18:38 -0400 Subject: [PATCH] Send longest warning reason --- src/routes/postSkipSegments.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index 188dbee..820ef54 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -284,7 +284,7 @@ async function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promi async function checkUserActiveWarning(userID: string): Promise { const MILLISECONDS_IN_HOUR = 3600000; const now = Date.now(); - const warnings = await db.prepare("all", + const warnings = (await db.prepare("all", `SELECT "reason" FROM warnings WHERE "userID" = ? AND "issueTime" > ? AND enabled = 1 @@ -295,7 +295,7 @@ async function checkUserActiveWarning(userID: string): Promise { Math.floor(now - (config.hoursAfterWarningExpires * MILLISECONDS_IN_HOUR)), config.maxNumberOfActiveWarnings ], - ) as {reason: string}[]; + ) as {reason: string}[]).sort((a, b) => (b?.reason?.length ?? 0) - (a?.reason?.length ?? 0)); if (warnings?.length >= config.maxNumberOfActiveWarnings) { const defaultMessage = "Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes"