From f8c297ddfbb51113babf3a9c6d67267581b09786 Mon Sep 17 00:00:00 2001 From: Ajay Date: Mon, 4 Jul 2022 23:44:50 -0400 Subject: [PATCH] Add canSubmitChapter and fix all userInfo functions running --- src/config.ts | 1 + src/routes/getUserInfo.ts | 25 +++++++++++++++---------- src/types/config.model.ts | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/config.ts b/src/config.ts index 1a62374..ee9e26f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -43,6 +43,7 @@ addDefaults(config, { discordFailedReportChannelWebhookURL: null, discordReportChannelWebhookURL: null, discordMaliciousReportWebhookURL: null, + minReputationToSubmitChapter: 0, getTopUsersCacheTimeMinutes: 240, globalSalt: null, mode: "", diff --git a/src/routes/getUserInfo.ts b/src/routes/getUserInfo.ts index 37aa678..dbede73 100644 --- a/src/routes/getUserInfo.ts +++ b/src/routes/getUserInfo.ts @@ -105,6 +105,10 @@ async function dbGetBanned(userID: HashedUserID): Promise { } } +async function dbCanSubmitChapter(userID: HashedUserID): Promise { + return (await isUserVIP(userID)) || (await getReputation(userID)) > config.minReputationToSubmitChapter; +} + type cases = Record const executeIfFunction = (f: any) => @@ -119,16 +123,17 @@ const functionSwitch = (cases: cases) => (defaultCase: string) => (key: string) const dbGetValue = (userID: HashedUserID, property: string): Promise => { return functionSwitch({ userID, - userName: dbGetUsername(userID), - ignoredSegmentCount: dbGetIgnoredSegmentCount(userID), - viewCount: dbGetViewsForUser(userID), - ignoredViewCount: dbGetIgnoredViewsForUser(userID), - warnings: dbGetWarningsForUser(userID), - warningReason: dbGetActiveWarningReasonForUser(userID), - banned: dbGetBanned(userID), - reputation: getReputation(userID), - vip: isUserVIP(userID), - lastSegmentID: dbGetLastSegmentForUser(userID), + userName: () => dbGetUsername(userID), + ignoredSegmentCount: () => dbGetIgnoredSegmentCount(userID), + viewCount: () => dbGetViewsForUser(userID), + ignoredViewCount: () => dbGetIgnoredViewsForUser(userID), + warnings: () => dbGetWarningsForUser(userID), + warningReason: () => dbGetActiveWarningReasonForUser(userID), + banned: () => dbGetBanned(userID), + reputation: () => getReputation(userID), + vip: () => isUserVIP(userID), + lastSegmentID: () => dbGetLastSegmentForUser(userID), + canSubmitChapter: () => dbCanSubmitChapter(userID) })("")(property); }; diff --git a/src/types/config.model.ts b/src/types/config.model.ts index a9f2532..9030e69 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -27,6 +27,7 @@ export interface SBSConfig { discordMaliciousReportWebhookURL?: string; neuralBlockURL?: string; discordNeuralBlockRejectWebhookURL?: string; + minReputationToSubmitChapter: number; userCounterURL?: string; proxySubmission?: string; behindProxy: string | boolean;