Add canSubmitChapter and fix all userInfo functions running

This commit is contained in:
Ajay
2022-07-04 23:44:50 -04:00
parent 0f3df8db1b
commit f8c297ddfb
3 changed files with 17 additions and 10 deletions

View File

@@ -43,6 +43,7 @@ addDefaults(config, {
discordFailedReportChannelWebhookURL: null,
discordReportChannelWebhookURL: null,
discordMaliciousReportWebhookURL: null,
minReputationToSubmitChapter: 0,
getTopUsersCacheTimeMinutes: 240,
globalSalt: null,
mode: "",

View File

@@ -105,6 +105,10 @@ async function dbGetBanned(userID: HashedUserID): Promise<boolean> {
}
}
async function dbCanSubmitChapter(userID: HashedUserID): Promise<boolean> {
return (await isUserVIP(userID)) || (await getReputation(userID)) > config.minReputationToSubmitChapter;
}
type cases = Record<string, any>
const executeIfFunction = (f: any) =>
@@ -119,16 +123,17 @@ const functionSwitch = (cases: cases) => (defaultCase: string) => (key: string)
const dbGetValue = (userID: HashedUserID, property: string): Promise<string|SegmentUUID|number> => {
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);
};

View File

@@ -27,6 +27,7 @@ export interface SBSConfig {
discordMaliciousReportWebhookURL?: string;
neuralBlockURL?: string;
discordNeuralBlockRejectWebhookURL?: string;
minReputationToSubmitChapter: number;
userCounterURL?: string;
proxySubmission?: string;
behindProxy: string | boolean;